{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forms-03",
  "description": "A form in steps that checks each step before moving on and reviews everything on the last one.",
  "registryDependencies": [
    "button",
    "field",
    "input",
    "https://www.dashboardblocks.com/r/radix/option-select.json",
    "switch",
    "textarea",
    "https://www.dashboardblocks.com/r/radix/forms.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forms/forms-03.tsx",
      "content": "'use client'\n\nimport {\n  type FormErrors,\n  type FormStep,\n  FormSteps,\n  useSimpleForm,\n} from '@/registry/components/dashboardblocks/forms'\nimport { OptionSelect } from '@/registry/components/dashboardblocks/option-select'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { type FormEvent, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport {\n  Field,\n  FieldContent,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldLabel,\n  FieldTitle,\n} from '@/components/ui/field'\nimport { Input } from '@/components/ui/input'\nimport { Switch } from '@/components/ui/switch'\nimport { Textarea } from '@/components/ui/textarea'\n\ntype NewProject = {\n  description: string\n  environment: string\n  isPublic: boolean\n  name: string\n  region: string\n}\n\ninterface Option {\n  label: string\n  value: string\n}\n\ninterface Forms3Props {\n  environments: Option[]\n  onCreate?: (values: NewProject) => Promise<FormErrors<NewProject> | void>\n  regions: Option[]\n  title: string\n}\n\nconst exampleProps: Forms3Props = {\n  environments: [\n    { label: 'Production', value: 'production' },\n    { label: 'Staging', value: 'staging' },\n    { label: 'Development', value: 'development' },\n  ],\n  regions: [\n    { label: 'Frankfurt (eu-central-1)', value: 'eu-central-1' },\n    { label: 'Virginia (us-east-1)', value: 'us-east-1' },\n    { label: 'Oregon (us-west-2)', value: 'us-west-2' },\n    { label: 'Singapore (ap-southeast-1)', value: 'ap-southeast-1' },\n  ],\n  title: 'New project',\n}\n\nconst STEPS: (FormStep & { fields: (keyof NewProject)[]; summary: string })[] = [\n  {\n    description: 'Name and purpose',\n    fields: ['name', 'description'],\n    summary: 'Name the project and say what it’s for.',\n    title: 'Details',\n  },\n  {\n    description: 'Where it runs',\n    fields: ['region', 'environment', 'isPublic'],\n    summary: 'Choose where it runs and who can see its dashboard.',\n    title: 'Setup',\n  },\n  {\n    description: 'Check and create',\n    fields: [],\n    summary: 'Check everything, then create the project.',\n    title: 'Review',\n  },\n]\n\nasync function createProject() {\n  await new Promise((resolve) => setTimeout(resolve, 800))\n}\n\nfunction validate(values: NewProject): FormErrors<NewProject> {\n  return {\n    description:\n      values.description.length > 200 ? 'Keep it to 200 characters or fewer.' : undefined,\n    name: !values.name.trim()\n      ? 'Enter a project name.'\n      : values.name.trim().length < 3\n        ? 'Use at least 3 characters.'\n        : undefined,\n  }\n}\n\nfunction labelOf(options: Option[], value: string) {\n  return options.find((option) => option.value === value)?.label ?? value\n}\n\nconst Forms3 = (props: Forms3Props) => {\n  const { environments, onCreate = createProject, regions, title } = props\n  const [step, setStep] = useState(0)\n  const [created, setCreated] = useState<string | null>(null)\n  const emptyValues: NewProject = {\n    description: '',\n    environment: environments[0]?.value ?? '',\n    isPublic: false,\n    name: '',\n    region: regions[0]?.value ?? '',\n  }\n  const form = useSimpleForm({ defaultValues: emptyValues, onSubmit: onCreate, validate })\n  const { values } = form\n  const last = step === STEPS.length - 1\n\n  function next() {\n    if (form.validateFields(STEPS[step].fields)) setStep(step + 1)\n  }\n\n  async function onSubmit(event: FormEvent<HTMLFormElement>) {\n    if (!last) {\n      event.preventDefault()\n      next()\n      return\n    }\n    await form.submit(event, { onSaved: () => setCreated(values.name) })\n  }\n\n  function startOver() {\n    form.reset(emptyValues)\n    setStep(0)\n    setCreated(null)\n  }\n\n  if (created) {\n    return (\n      <section className='@container flex flex-col gap-3'>\n        <div role='status' className='flex flex-col gap-0.5'>\n          <h2 className='flex items-center gap-2 font-semibold tracking-tight'>\n            <IconPlaceholder\n              lucide='CircleCheckIcon'\n              tabler='IconCircleCheckFilled'\n              hugeicons='CheckmarkCircle01Icon'\n              phosphor='CheckCircleIcon'\n              remixicon='RiCheckboxCircleFill'\n              aria-hidden\n              className='size-4 shrink-0 text-emerald-700 dark:text-emerald-400'\n            />\n            {created} is ready\n          </h2>\n          <p className='text-muted-foreground text-sm'>\n            Created in {labelOf(regions, values.region)}, for{' '}\n            {labelOf(environments, values.environment).toLowerCase()}, with a{' '}\n            {values.isPublic ? 'public' : 'private'} dashboard.\n          </p>\n        </div>\n        <div className='border-t pt-4'>\n          <Button variant='outline' size='sm' onClick={startOver}>\n            <IconPlaceholder\n              lucide='PlusIcon'\n              tabler='IconPlus'\n              hugeicons='PlusSignIcon'\n              phosphor='PlusIcon'\n              remixicon='RiAddLine'\n              data-icon='inline-start'\n            />\n            Create another project\n          </Button>\n        </div>\n      </section>\n    )\n  }\n\n  return (\n    <section className='@container flex flex-col gap-4'>\n      <header className='flex flex-col gap-0.5'>\n        <h2 className='font-semibold tracking-tight'>{title}</h2>\n        <p className='text-muted-foreground text-sm'>\n          Step {step + 1} of {STEPS.length}. {STEPS[step].summary}\n        </p>\n      </header>\n      <FormSteps current={step} steps={STEPS} />\n      <form\n        method='post'\n        noValidate\n        onSubmit={(event) => void onSubmit(event)}\n        className='flex flex-col gap-4'\n      >\n        {step === 0 && (\n          <FieldGroup>\n            <Field data-invalid={form.errors.name ? true : undefined}>\n              <FieldLabel htmlFor={form.getId('name')}>Project name</FieldLabel>\n              <Input autoComplete='off' {...form.field('name')} />\n              <FieldError {...form.error('name')} />\n            </Field>\n            <Field data-invalid={form.errors.description ? true : undefined}>\n              <FieldLabel htmlFor={form.getId('description')}>Description</FieldLabel>\n              <Textarea rows={3} {...form.field('description')} />\n              <FieldDescription>\n                Optional. Shown to everyone in the workspace.\n              </FieldDescription>\n              <FieldError {...form.error('description')} />\n            </Field>\n          </FieldGroup>\n        )}\n        {step === 1 && (\n          <FieldGroup>\n            <Field>\n              <FieldLabel htmlFor={form.getId('region')}>Region</FieldLabel>\n              <OptionSelect\n                className='w-full'\n                options={regions}\n                {...form.select('region')}\n              />\n              <FieldDescription>Pick the region closest to your users.</FieldDescription>\n            </Field>\n            <Field>\n              <FieldLabel htmlFor={form.getId('environment')}>Environment</FieldLabel>\n              <OptionSelect\n                className='w-full'\n                options={environments}\n                {...form.select('environment')}\n              />\n            </Field>\n            <Field orientation='horizontal'>\n              <FieldContent>\n                <FieldTitle id={`${form.getId('isPublic')}-label`}>\n                  Public dashboard\n                </FieldTitle>\n                <FieldDescription id={`${form.getId('isPublic')}-description`}>\n                  Anyone with the link can view it, without signing in.\n                </FieldDescription>\n              </FieldContent>\n              <Switch\n                aria-labelledby={`${form.getId('isPublic')}-label`}\n                aria-describedby={`${form.getId('isPublic')}-description`}\n                checked={values.isPublic}\n                onCheckedChange={(checked) => form.setValue('isPublic', checked)}\n              />\n            </Field>\n          </FieldGroup>\n        )}\n        {step === 2 && (\n          <dl className='divide-y border-y text-sm'>\n            {[\n              ['Name', values.name],\n              ['Description', values.description || 'None'],\n              ['Region', labelOf(regions, values.region)],\n              ['Environment', labelOf(environments, values.environment)],\n              ['Dashboard', values.isPublic ? 'Public' : 'Private'],\n            ].map(([term, detail]) => (\n              <div\n                key={term}\n                className='grid gap-1 py-2.5 @md:grid-cols-[10rem_minmax(0,1fr)] @md:gap-4'\n              >\n                <dt className='text-muted-foreground'>{term}</dt>\n                <dd className='min-w-0 break-words'>{detail}</dd>\n              </div>\n            ))}\n          </dl>\n        )}\n        <div className='flex items-center justify-between gap-2 border-t pt-4'>\n          <Button\n            type='button'\n            variant='outline'\n            disabled={step === 0 || form.isSubmitting}\n            onClick={() => setStep(step - 1)}\n          >\n            <IconPlaceholder\n              lucide='ArrowLeftIcon'\n              tabler='IconArrowLeft'\n              hugeicons='ArrowLeft01Icon'\n              phosphor='ArrowLeftIcon'\n              remixicon='RiArrowLeftLine'\n              data-icon='inline-start'\n            />\n            Back\n          </Button>\n          {last ? (\n            <Button key='create' type='submit' disabled={form.isSubmitting}>\n              {form.isSubmitting ? 'Creating' : 'Create project'}\n            </Button>\n          ) : (\n            <Button key='next' type='button' onClick={next}>\n              Next\n              <IconPlaceholder\n                lucide='ArrowRightIcon'\n                tabler='IconArrowRight'\n                hugeicons='ArrowRight01Icon'\n                phosphor='ArrowRightIcon'\n                remixicon='RiArrowRightLine'\n                data-icon='inline-end'\n              />\n            </Button>\n          )}\n        </div>\n      </form>\n    </section>\n  )\n}\n\nexport { Forms3, exampleProps as forms3ExampleProps, type Forms3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forms/forms-03.tsx"
    }
  ],
  "meta": {
    "shows": "A form in steps that checks each step before moving on and reviews everything on the last one.",
    "size": "half",
    "usedWith": [
      "onboarding-01",
      "checklist-02"
    ],
    "component": "Forms3",
    "props": "{ environments: { label: string; value: string }[]; onCreate?: (values: { description: string; environment: string; isPublic: boolean; name: string; region: string }) => Promise<void | { name?: string; region?: string; description?: string; environment?: string; isPublic?: string }>; regions: { label: string; value: string }[]; title: string }"
  },
  "type": "registry:component"
}
