Form
Building forms with React Hook Form and Yup.
Integration
Forms are tricky. They are one of the most common things you'll build in a web application, but also one of the most complex.
TerminalCopyyarn add react-hook-form @hookform/resolvers yup
Code EditorCopyimport { useForm, Controller } from 'react-hook-form' import { yupResolver } from '@hookform/resolvers/yup' import * as yup from 'yup' import { TextInput, Button } from '@erudilabs/alma' type Values = { full_name: string } const schema = yup.object({ full_name: yup.string().required('Field is required.'), }) const onSubmit = async (values: Values) => { const { full_name: fullName } = values alert(fullName) } export const TextInputFormExample = () => { const { control, handleSubmit, formState: { isSubmitting, isValid }, } = useForm<Values>({ resolver: yupResolver(schema), defaultValues: { full_name: '' }, mode: 'all', }) return ( <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col space-y-4"> <Controller name="full_name" control={control} render={({ field, formState: { errors } }) => { return ( <TextInput {...field} errorMessage={errors.full_name?.message} label="Full name" placeholder="Enter your full name" /> ) }} /> <Button type="submit" loading={isSubmitting} disabled={!isValid} block theme="primary" > Submit </Button> </form> ) }
Component Form
Here is several component form
AmountInput
Checkbox
Counter
Dropdown
MobileInput
NumberInput
Radio
TextInput
Textarea
Toogle
Code EditorCopyimport { AmountInput } from '@erudilabs/alma'
Code EditorCopyimport { Checkbox } from '@erudilabs/alma'
Code EditorCopyimport { Counter } from '@erudilabs/alma'
Code EditorCopyimport { Dropdown } from '@erudilabs/alma'
Code EditorCopyimport { MobileInput } from '@erudilabs/alma'
Code EditorCopyimport { NumberInput } from '@erudilabs/alma'
Code EditorCopyimport { Radio } from '@erudilabs/alma'
Code EditorCopyimport { TextInput } from '@erudilabs/alma'
Code EditorCopyimport { Textarea } from '@erudilabs/alma'
Code EditorCopyimport { Toogle } from '@erudilabs/alma'