// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React, { useState } from 'react'; import FormField from '.'; import Input from '../Input'; import Checkbox from '../Checkbox'; import Textarea from '../Textarea'; import Select from '../Select'; import RadioGroup from '../RadioGroup'; export default { title: 'UI Components/Form/FormField', component: FormField, }; const commonHiddenArgTypes = { checked: { table: { disable: true } }, field: { table: { disable: true } }, fieldProps: { table: { disable: true } }, onChange: { table: { disable: true } }, value: { table: { disable: true } }, options: { table: { disable: true } }, }; const options = [ { value: 'react', label: 'React', }, { value: 'angular', label: 'Angular', }, { value: 'vue', label: 'Vue', }, { value: 'none', label: 'None', }, ]; interface FormFieldProps { label: string; layout?: 'stack' | 'horizontal' | 'input-only'; error: boolean; infoText: string; errorText: string; placeholder?: string; } const TestInput: React.FC> = ( props ) => { const [name, setName] = useState(''); function handleChange(evt: any) { const value = evt.target.value; setName(value); } return ( ); }; export const BasicInputFormField = (args) => { return (
); }; BasicInputFormField.args = { layout: 'stack', label: 'First Name', placeholder: 'Enter your first name', infoText: 'This is some informational text', error: false, errorText: 'This is some error text', }; BasicInputFormField.argTypes = { layout: { control: 'radio', options: ['stack', 'horizontal', 'input-only'] }, label: { control: 'text' }, placeholder: { control: 'text' }, infoText: { control: 'text' }, error: { control: 'boolean' }, errorText: { control: 'text' }, ...commonHiddenArgTypes, }; const TestSelect: React.FC> = ( props ) => { const [value, setValue] = useState(''); const handleChange = (e: any) => setValue(e.target.value); return ( ); }; export const SelectFormField = (args) => { return (
); }; SelectFormField.args = { layout: 'stack', label: 'Select a framework', infoText: 'This is some informational text', error: false, errorText: 'This is some error text', }; SelectFormField.argTypes = { layout: { control: 'radio', options: ['stack', 'horizontal', 'input-only'] }, label: { control: 'text' }, infoText: { control: 'text' }, error: { control: 'boolean' }, errorText: { control: 'text' }, ...commonHiddenArgTypes, }; const TestTextarea: React.FC> = ( props ) => { const [value, setValue] = useState(''); const handleChange = (e: any) => { setValue(e.target.value); }; return ( ); }; export const TextareaFormField = (args) => { return (
); }; TextareaFormField.args = { layout: 'stack', label: 'Description', placeholder: 'Enter your description here', infoText: 'This is some informational text', error: false, errorText: 'This is some error text', }; TextareaFormField.argTypes = { layout: { control: 'radio', options: ['stack', 'horizontal', 'input-only'] }, label: { control: 'text' }, placeholder: { control: 'text' }, infoText: { control: 'text' }, error: { control: 'boolean' }, errorText: { control: 'text' }, ...commonHiddenArgTypes, }; const TestRadioGroup: React.FC> = ( props ) => { const [value, setValue] = useState(''); const handleChange = (evt: any) => { setValue(evt.target.value); }; return ( ); }; export const RadioGroupFormField = (args) => { return (
); }; RadioGroupFormField.args = { label: 'Select from the following:', infoText: 'This is some informational text', error: false, errorText: 'This is some error text', }; RadioGroupFormField.argTypes = { label: { control: 'text' }, infoText: { control: 'text' }, error: { control: 'boolean' }, errorText: { control: 'text' }, layout: { table: { disable: true } }, ...commonHiddenArgTypes, }; const TestCheckboxGroup: React.FC> = (props) => { const [state, setState] = React.useState({ react: false, angular: false, vue: false, }); function handleChange(evt: any) { const value = evt.target.checked; setState({ ...state, [evt.target.value]: value, }); } return ( <> ); }; export const CheckboxFormField = () => { return (
); }; CheckboxFormField.argTypes = { layout: { table: { disable: true } }, label: { table: { disable: true } }, infoText: { table: { disable: true } }, error: { table: { disable: true } }, errorText: { table: { disable: true } }, ...commonHiddenArgTypes, }; const TestMixedInputs: React.FC> = ( props ) => { const [state, setState] = useState({ firstName: '', lastName: '', acknowledge: false, select: '', textarea: '', tabs: 'spaces', }); function handleChange(evt: any) { const value = evt.target.type === 'checkbox' ? evt.target.checked : evt.target.value; setState({ ...state, [evt.target.type === 'radio' ? 'tabs' : evt.target.name]: value, }); } return ( <> ); }; export const MixedInputsFormField = (args) => { return (
); }; MixedInputsFormField.args = { layout: 'stack', error: false, }; MixedInputsFormField.argTypes = { layout: { control: 'radio', options: ['stack', 'horizontal', 'input-only'] }, error: { control: 'boolean' }, label: { table: { disable: true } }, infoText: { table: { disable: true } }, errorText: { table: { disable: true } }, ...commonHiddenArgTypes, };