dotUI
dotUI copied to clipboard
[feat] Add Forms Support
Feature description
Overview
I would love to add Forms support to this library with the clean declarative approach inspired by Ant Design with the use of react-hook-form and Zod as the validation library.
Benefits
What the developer has to do is structure the form and give the zod schema, the <Form.Item>
will handle all the validation internally, and onFinish
only calls when the form is validated.
Proposed Structure
const AddNewUser = () => {
const form = useForm({
resolver: zodResolver(
z.object({
firstName: z.string().max(20),
lastName: z.string().max(20).optional()
})
)
})
return (
<Form form={form} onFinish={data => console.log(data)}>
<div className='grid gap-x-10'>
<Form.Item label='First Name' name='firstName'>
<CustomTextField />
</Form.Item>
<Form.Item label='Last Name' name='lastName'>
<CustomTextField />
</Form.Item>
</div>
<Button type='submit'>Submit</Button>
</Form>
)
}
Affected component/components
All Input fields
Additional Context
No response
Before submitting
- [X] I've made research efforts and searched the documentation
- [X] I've searched for existing issues and PRs