{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forms-04",
  "description": "Single values edited in place, saved with Enter and cancelled with Escape.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/forms.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/forms/forms-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { InlineEditField, isEmail } from '@/registry/components/dashboardblocks/forms'\nimport { startTransition, useState } from 'react'\n\ninterface CustomerDetails {\n  company: string\n  email: string\n  name: string\n  phone: string\n  website: string\n}\n\ninterface Forms4Props extends BlockStateProps {\n  /** Leave out to show the empty state. */\n  defaultValues?: CustomerDetails\n  onSave?: (field: keyof CustomerDetails, value: string) => Promise<string | void>\n  title: string\n}\n\nconst exampleProps: Forms4Props = {\n  defaultValues: {\n    company: 'Northwind Traders',\n    email: 'jonas@northwind.io',\n    name: 'Jonas Weber',\n    phone: '',\n    website: 'https://northwind.io',\n  },\n  title: 'Customer details',\n}\n\nasync function saveField() {\n  await new Promise((resolve) => setTimeout(resolve, 600))\n}\n\nfunction Forms4Content(props: Forms4Props & { defaultValues: CustomerDetails }) {\n  const { defaultValues, onSave = saveField } = props\n  const [details, setDetails] = useState(defaultValues)\n\n  function save(field: keyof CustomerDetails) {\n    return async (value: string) => {\n      const error = await onSave(field, value)\n      if (error) return error\n      startTransition(() => setDetails((current) => ({ ...current, [field]: value })))\n    }\n  }\n\n  return (\n    <>\n      <div className='divide-y border-t'>\n        <InlineEditField\n          label='Name'\n          value={details.name}\n          onSave={save('name')}\n          validate={(value) => (value.trim() ? undefined : 'Enter a name.')}\n        />\n        <InlineEditField\n          label='Email'\n          type='email'\n          value={details.email}\n          onSave={save('email')}\n          validate={(value) =>\n            isEmail(value) ? undefined : 'Enter an email address like name@example.com.'\n          }\n        />\n        <InlineEditField\n          label='Phone'\n          type='tel'\n          value={details.phone}\n          onSave={save('phone')}\n        />\n        <InlineEditField\n          label='Company'\n          value={details.company}\n          onSave={save('company')}\n        />\n        <InlineEditField\n          label='Website'\n          type='url'\n          value={details.website}\n          onSave={save('website')}\n          validate={(value) =>\n            !value || /^https?:\\/\\/\\S+\\.\\S+$/.test(value)\n              ? undefined\n              : 'Enter a full address, starting with https://.'\n          }\n        />\n      </div>\n    </>\n  )\n}\n\nconst Forms4 = (props: Forms4Props) => {\n  const { defaultValues, 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'>\n            Each change saves as soon as you confirm it.\n          </p>\n        </header>\n        {ready ? (\n          <Forms4Content {...props} defaultValues={defaultValues} />\n        ) : (\n          <div className='border-t'>\n            <BlockStateRows rows={5} />\n          </div>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { Forms4, exampleProps as forms4ExampleProps, type Forms4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/forms/forms-04.tsx"
    }
  ],
  "meta": {
    "shows": "Single values edited in place, saved with Enter and cancelled with Escape.",
    "size": "half",
    "usedWith": [
      "record-detail-01",
      "forms-01"
    ],
    "component": "Forms4",
    "props": "{ defaultValues?: { company: string; email: string; name: string; phone: string; website: string }; onSave?: (field: \"name\" | \"email\" | \"company\" | \"phone\" | \"website\", value: string) => Promise<string | void>; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
