import type { Meta, StoryObj } from '@storybook/react-vite'; import { zodResolver } from '@hookform/resolvers/zod'; import { useForm } from 'react-hook-form'; import { z } from 'zod/v4'; import { Story } from '../_internal/Story'; import { Form } from './Form'; const meta = { args: {}, component: Form, parameters: { layout: 'fullscreen', }, title: 'components/Form', } satisfies Meta; export default meta; type StoryDefinition = StoryObj; const roles = [ { label: 'Designer', value: 'designer' }, { label: 'Engineer', value: 'engineer' }, { label: 'Manager', value: 'manager' }, ] as const; const notificationChannels: { disabled?: boolean; label: string; value: string; }[] = [ { label: 'Email', value: 'email' }, { label: 'SMS', value: 'sms' }, { disabled: true, label: 'Push (coming soon)', value: 'push' }, ]; const signUpSchema = z.object({ email: z.email('Enter a valid email address.'), firstName: z.string().trim().min(1, 'Enter your first name.'), lastName: z.string().trim().min(1, 'Enter your last name.'), notificationChannel: z.enum(['email', 'sms']), password: z.string().min(8, 'Use at least 8 characters.'), productUpdates: z.boolean(), role: z.enum(['designer', 'engineer', 'manager']), terms: z.boolean().refine(Boolean, 'Accept the terms to continue.'), username: z.string().trim().min(1, 'Enter a username.'), }); type SignUpValues = z.infer; function SignUpForm() { const form = useForm({ defaultValues: { email: '', firstName: '', lastName: '', notificationChannel: 'email', password: '', productUpdates: true, role: 'designer', terms: false, username: '', }, resolver: zodResolver(signUpSchema), }); return (
form.clearErrors()}> {roles.map((role) => ( {role.label} ))} {notificationChannels.map((channel) => ( ))} Create account
); } export const SignUp: StoryDefinition = { render: () => ( ), };