Skip to content

Auto Form

InputMIT
View in Storybook

Schema-driven auto-generated form from a Zod schema — labels, helpers, and validation.

bun add @otfdashkit/ui

Preview

Auto Form
Loading Storybook preview…

Code

import * as z from 'zod'
import { AutoForm } from '@otfdashkit/ui'

const registrationSchema = z.object({
  name: z.string().min(2),
  email: z.email(),
  age: z.number().min(18).max(120),
  role: z.enum(['admin', 'editor', 'viewer']),
  newsletter: z.boolean().optional(),
  startDate: z.date().optional(),
})

export function Example() {
  return (
    <div className="max-w-sm">
      <AutoForm
        schema={registrationSchema}
        onSubmit={(data: unknown) => alert(JSON.stringify(data, null, 2))}
        defaultValues={{ role: 'viewer', newsletter: false }}
        submitLabel="Register"
      />
    </div>
  )
}

Free with the SDK. This component ships in @otfdashkit/ui under the MIT license.

Props

Props declared in the AutoForm source. Inherited HTML attributes are not listed.

PropTypeDefaultDescription
onSubmitrequired(data: Record<string, unknown>) => void
schemarequiredZodObject<Readonly<{ [k: string]: $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; }>, $strip>
defaultValuesRecord<string, unknown>
submitLabelstring'Submit'