컴포넌트
Form
react-hook-form + zod 연결.
import { zodResolver } from '@hookform/resolvers/zod'
import { useForm } from 'react-hook-form'
import { z } from 'zod'
import { Button } from '@zest/primitives/Button.js'
import { Form, FormField } from '@zest/primitives/Form.js'
import { Input } from '@zest/primitives/Input.js'
import { toast, Toaster } from '@zest/primitives/Toast.js'
const schema = z.object({ name: z.string().min(1, '이름을 적어 주세요'), email: z.string().email('이메일 형식이 아니에요') })
export default function Demo() {
const form = useForm<z.infer<typeof schema>>({ resolver: zodResolver(schema), defaultValues: { name: '', email: '' } })
return (
<>
<Form form={form} onSubmit={() => toast({ title: '저장했어요', tone: 'done' })} className="flex w-full max-w-[360px] flex-col gap-4">
<FormField name="name" label="이름" required render={(f) => <Input {...f} />} />
<FormField name="email" label="이메일" render={(f) => <Input type="email" {...f} />} />
<Button type="submit">저장</Button>
</Form>
<Toaster />
</>
)
}설치
shadcn CLI 로 소스를 프로젝트에 가져와요. 테마·유틸·의존 부품이 함께 설치돼요.
npx shadcn@latest add @zest/form패키지로 쓰려면 @zest-im/ui 에서 가져와요. 설치 안내
사용법
import { FormField } from '@/components/ui/form'위 미리보기의 「코드」 탭이 실제로 동작하는 예제예요.
API
| prop | 타입 | 설명 |
|---|---|---|
name | string | — |
label | string | — |
hint? | string | — |
required? | boolean | — |
render | (field: ControllerRenderProps<FieldValues, string>) => ReactElement<unknown, string | J… | — |
className? | string | — |
표에 없는 HTML·Radix 속성은 그대로 전달돼요.