{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forms-01",
  "description": "A form with fields grouped into titled sections and a save bar that appears while there are unsaved changes.",
  "registryDependencies": [
    "field",
    "input",
    "https://www.dashboardblocks.com/r/radix/option-select.json",
    "switch",
    "textarea",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/forms.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forms/forms-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type FormErrors,\n  FormSection,\n  isEmail,\n  SaveBar,\n  useSimpleForm,\n} from '@/registry/components/dashboardblocks/forms'\nimport { OptionSelect } from '@/registry/components/dashboardblocks/option-select'\n\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 WorkspaceSettings = {\n  bio: string\n  email: string\n  name: string\n  slug: string\n  timezone: string\n  weeklyDigest: boolean\n  workspaceName: string\n}\n\ninterface Forms1Props extends BlockStateProps {\n  /** Leave out to show the empty state. */\n  defaultValues?: WorkspaceSettings\n  description: string\n  domain: string\n  onSubmit?: (values: WorkspaceSettings) => Promise<FormErrors<WorkspaceSettings> | void>\n  timezones: { label: string; value: string }[]\n  title: string\n}\n\nconst BIO_LIMIT = 160\n\nconst exampleProps: Forms1Props = {\n  defaultValues: {\n    bio: 'Runs growth at Acme. Ask me about funnels.',\n    email: 'amara@acme.com',\n    name: 'Amara Okafor',\n    slug: 'acme-store',\n    timezone: 'Europe/London',\n    weeklyDigest: true,\n    workspaceName: 'Acme Store',\n  },\n  description: 'Your profile, and the workspace you share with your team.',\n  domain: 'app.example.com',\n  timezones: [\n    { label: 'Pacific Time (Los Angeles)', value: 'America/Los_Angeles' },\n    { label: 'Eastern Time (New York)', value: 'America/New_York' },\n    { label: 'Greenwich Mean Time (London)', value: 'Europe/London' },\n    { label: 'Central European Time (Berlin)', value: 'Europe/Berlin' },\n    { label: 'Japan Standard Time (Tokyo)', value: 'Asia/Tokyo' },\n  ],\n  title: 'Settings',\n}\n\nasync function saveSettings(values: WorkspaceSettings) {\n  await new Promise((resolve) => setTimeout(resolve, 800))\n  if (values.slug === 'acme') return { slug: 'That URL is already taken.' }\n}\n\nfunction validate(values: WorkspaceSettings): FormErrors<WorkspaceSettings> {\n  return {\n    bio:\n      values.bio.length > BIO_LIMIT\n        ? `Keep it to ${BIO_LIMIT} characters or fewer.`\n        : undefined,\n    email: !values.email.trim()\n      ? 'Enter your email address.'\n      : !isEmail(values.email)\n        ? 'Enter an email address like name@example.com.'\n        : undefined,\n    name: values.name.trim() ? undefined : 'Enter your name.',\n    slug: !/^[a-z0-9-]{3,}$/.test(values.slug)\n      ? 'Use at least 3 lowercase letters, numbers or dashes.'\n      : undefined,\n    workspaceName: values.workspaceName.trim() ? undefined : 'Enter a workspace name.',\n  }\n}\n\nfunction Forms1Content(props: Forms1Props & { defaultValues: WorkspaceSettings }) {\n  const { defaultValues, domain, onSubmit = saveSettings, timezones } = props\n  const form = useSimpleForm({ defaultValues, onSubmit, validate })\n  const { values } = form\n  const changes = form.changedFields.length\n\n  return (\n    <>\n      <form method='post' noValidate onSubmit={(event) => void form.submit(event)}>\n        <div className='flex flex-col gap-6'>\n          <FormSection title='Profile' description='How you appear to your team.'>\n            <FieldGroup>\n              <Field data-invalid={form.errors.name ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('name')}>Name</FieldLabel>\n                <Input autoComplete='name' {...form.field('name')} />\n                <FieldError {...form.error('name')} />\n              </Field>\n              <Field data-invalid={form.errors.email ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('email')}>Email</FieldLabel>\n                <Input type='email' autoComplete='email' {...form.field('email')} />\n                <FieldError {...form.error('email')} />\n              </Field>\n              <Field data-invalid={form.errors.bio ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('bio')}>Bio</FieldLabel>\n                <Textarea rows={3} {...form.field('bio')} />\n                <FieldDescription>\n                  {values.bio.length} of {BIO_LIMIT} characters\n                </FieldDescription>\n                <FieldError {...form.error('bio')} />\n              </Field>\n            </FieldGroup>\n          </FormSection>\n          <FormSection\n            title='Workspace'\n            description='The name and address your team uses to find this workspace.'\n          >\n            <FieldGroup>\n              <Field data-invalid={form.errors.workspaceName ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('workspaceName')}>\n                  Workspace name\n                </FieldLabel>\n                <Input {...form.field('workspaceName')} />\n                <FieldError {...form.error('workspaceName')} />\n              </Field>\n              <Field data-invalid={form.errors.slug ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('slug')}>URL</FieldLabel>\n                <Input autoCapitalize='none' spellCheck={false} {...form.field('slug')} />\n                <FieldDescription>\n                  {domain}/{values.slug || 'your-workspace'}\n                </FieldDescription>\n                <FieldError {...form.error('slug')} />\n              </Field>\n            </FieldGroup>\n          </FormSection>\n          <FormSection\n            title='Preferences'\n            description='Your time zone, and the emails you get.'\n          >\n            <FieldGroup>\n              <Field>\n                <FieldLabel htmlFor={form.getId('timezone')}>Time zone</FieldLabel>\n                <OptionSelect\n                  className='w-full'\n                  options={timezones}\n                  {...form.select('timezone')}\n                />\n                <FieldDescription>\n                  Reports and digests use this time zone.\n                </FieldDescription>\n              </Field>\n              <Field orientation='horizontal'>\n                <FieldContent>\n                  <FieldTitle id={`${form.getId('weeklyDigest')}-label`}>\n                    Weekly digest\n                  </FieldTitle>\n                  <FieldDescription id={`${form.getId('weeklyDigest')}-description`}>\n                    A summary of your workspace every Monday morning.\n                  </FieldDescription>\n                </FieldContent>\n                <Switch\n                  aria-labelledby={`${form.getId('weeklyDigest')}-label`}\n                  aria-describedby={`${form.getId('weeklyDigest')}-description`}\n                  checked={values.weeklyDigest}\n                  onCheckedChange={(checked) => form.setValue('weeklyDigest', checked)}\n                />\n              </Field>\n            </FieldGroup>\n          </FormSection>\n        </div>\n        <SaveBar\n          className='mt-6'\n          isDirty={form.isDirty}\n          isSubmitting={form.isSubmitting}\n          message={`${changes} unsaved ${changes === 1 ? 'change' : 'changes'}`}\n          onDiscard={() => form.reset()}\n        />\n      </form>\n    </>\n  )\n}\n\nconst Forms1 = (props: Forms1Props) => {\n  const { defaultValues, description, errorMessage, status, title } = props\n  const ready = !status && defaultValues !== undefined\n\n  return (\n    <BlockStateProvider\n      errorMessage={errorMessage}\n      state={getBlockState(status, defaultValues)}\n    >\n      <section className='@container flex flex-col gap-3'>\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'>{description}</p>\n        </header>\n        {ready ? (\n          <Forms1Content {...props} defaultValues={defaultValues} />\n        ) : (\n          <div className='border-t'>\n            <BlockStateRows rows={6} />\n          </div>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { Forms1, exampleProps as forms1ExampleProps, type Forms1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forms/forms-01.tsx"
    }
  ],
  "meta": {
    "shows": "A form with fields grouped into titled sections and a save bar that appears while there are unsaved changes.",
    "size": "half",
    "usedWith": [
      "page-header-01",
      "forms-04"
    ],
    "component": "Forms1",
    "props": "{ defaultValues?: { bio: string; email: string; name: string; slug: string; timezone: string; weeklyDigest: boolean; workspaceName: string }; description: string; domain: string; onSubmit?: (values: { bio: string; email: string; name: string; slug: string; timezone: string; weeklyDigest: boolean; workspaceName: string }) => Promise<void | { name?: string; email?: string; bio?: string; slug?: string; timezone?: string; weeklyDigest?: string; workspaceName?: string }>; timezones: { label: string; value: string }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
