1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { useField } from 'formik'
- const TextInput = ({ label, ...props }) => {
- const [field, meta] = useField(props)
- return (
- <>
- <label htmlFor={props.id || props.name}>{label}</label>
- <input className='text-input' {...field} {...props} />
- {meta.touched && meta.error ? (
- <div className='error'>{meta.error}</div>
- ) : null}
- </>
- )
- }
- const Checkbox = ({ children, ...props }) => {
- const [field, meta] = useField({ ...props, type: 'checkbox' })
- return (
- <>
- <label className='checkbox'>
- <input {...field} {...props} type='checkbox' />
- {children}
- </label>
- {meta.touched && meta.error ? (
- <div className='error'>{meta.error}</div>
- ) : null}
- </>
- )
- }
- const Select = ({ label, ...props }) => {
- const [field, meta] = useField(props)
- return (
- <>
- <label htmlFor={props.id || props.name}>{label}</label>
- <select {...field} {...props} />
- {meta.touched && meta.error ? (
- <div className='error'>{meta.error}</div>
- ) : null}
- </>
- )
- }
- export { TextInput, Checkbox, Select }
|