{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ui-and-custom-fields-form",
  "title": "UI Layout & Custom Fields",
  "description": "Mixing inline UI components with completely custom registered fields.",
  "registryDependencies": [
    "@buzzform/ui",
    "card",
    "field",
    "input",
    "sonner"
  ],
  "files": [
    {
      "path": "registry/shadcn/examples/ui-and-custom-fields-form.tsx",
      "content": "\"use client\";\n\nimport { toast } from \"sonner\";\nimport { defineSchema, type InferType, useDataField } from \"@buildnbuzz/form-react\";\nimport {\n  Form,\n  FormContent,\n  FormFields,\n  FormSubmit,\n  FormActions,\n} from \"@/registry/shadcn/form\";\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\";\nimport {\n  Field,\n  FieldContent,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldLabel,\n} from \"@/components/ui/field\";\nimport { Input } from \"@/components/ui/input\";\n\n// 1. Define our custom field component.\n// It uses `useDataField` to easily hook into the headless form state.\nfunction ColorPickerField() {\n  const {\n    fieldApi,\n    isDisabled,\n    isReadOnly,\n    isRequired,\n    label,\n    description,\n    errors,\n    isInvalid,\n    descriptionId,\n    errorId,\n    handleChange,\n    handleBlur,\n  } = useDataField();\n\n  const value = (fieldApi.state.value as string) || \"#000000\";\n\n  return (\n    <FieldGroup data-field={fieldApi.name}>\n      <Field data-invalid={isInvalid} data-disabled={isDisabled}>\n        {label && (\n          <FieldLabel htmlFor={fieldApi.name} className=\"gap-1 items-baseline\">\n            {label}\n            {isRequired ? <span className=\"text-destructive\">*</span> : null}\n          </FieldLabel>\n        )}\n\n        <FieldContent>\n          <div className=\"flex gap-2\">\n            <Input\n              id={fieldApi.name}\n              name={fieldApi.name}\n              type=\"color\"\n              value={value}\n              onChange={(e) => handleChange(e.target.value)}\n              onBlur={handleBlur}\n              disabled={isDisabled}\n              readOnly={isReadOnly}\n              aria-invalid={isInvalid}\n              className=\"h-8 w-8 shrink-0 cursor-pointer border-0 p-0 rounded-md overflow-hidden shadow-none [&::-webkit-color-swatch-wrapper]:p-0 [&::-webkit-color-swatch]:border-none [&::-moz-color-swatch]:border-none\"            />\n            <Input\n              type=\"text\"\n              value={value}\n              onChange={(e) => handleChange(e.target.value)}\n              onBlur={handleBlur}\n              disabled={isDisabled}\n              readOnly={isReadOnly}\n              aria-invalid={isInvalid}\n              placeholder=\"#000000\"\n              className=\"flex-1 font-mono uppercase\"\n            />\n          </div>\n        </FieldContent>\n\n        {description && !isInvalid && (\n          <FieldDescription id={descriptionId}>{description}</FieldDescription>\n        )}\n\n        {isInvalid && <FieldError id={errorId} errors={errors} />}\n      </Field>\n    </FieldGroup>\n  );\n}\n\n// 2. Define the schema, mixing standard fields, layout \"ui\" fields,\n// and our custom \"color-picker\" field.\nconst customSchema = defineSchema({\n  fields: [\n    {\n      type: \"ui\",\n      content: (\n        <div className=\"rounded-lg bg-muted p-4 border mb-2\">\n          <h3 className=\"font-semibold\">Theme Builder</h3>\n          <p className=\"text-sm text-muted-foreground mt-1\">\n            Configure your application&apos;s appearance by selecting custom colors below.\n          </p>\n        </div>\n      ),\n    },\n    {\n      type: \"text\",\n      name: \"themeName\",\n      label: \"Theme Name\",\n      placeholder: \"e.g., Midnight Blue\",\n      required: true,\n    },\n    {\n      type: \"ui\",\n      content: <h4 className=\"font-medium text-sm mt-4 mb-2\">Brand Colors</h4>,\n    },\n    {\n      type: \"color-picker\",\n      name: \"primaryColor\",\n      label: \"Primary Color\",\n      description: \"Main color used for buttons and primary actions.\",\n      defaultValue: \"#0f172a\",\n      required: true,\n    },\n    {\n      type: \"color-picker\",\n      name: \"secondaryColor\",\n      label: \"Secondary Color\",\n      description: \"Color used for secondary elements and subtle backgrounds.\",\n      defaultValue: \"#f1f5f9\",\n    },\n    {\n      type: \"color-picker\",\n      name: \"accentColor\",\n      label: \"Accent Color\",\n      description: \"Color used for active states and highlights.\",\n      defaultValue: \"#3b82f6\",\n    },\n  ],\n});\n\nexport default function UiAndCustomFieldsExample() {\n  const handleSubmit = async ({ value }: { value: unknown }) => {\n    // value is inferred properly. Custom fields without explicitly defined type interfaces\n    // fall back to `unknown`. Layout fields don't show up here at all.\n    const data = value as InferType<typeof customSchema.fields>;\n\n    toast(\"Saved Custom Form\", {\n      description: (\n        <pre className=\"mt-2 max-h-48 overflow-auto rounded-md bg-muted text-muted-foreground p-3 text-xs\">\n          <code>{JSON.stringify(data, null, 2)}</code>\n        </pre>\n      ),\n    });\n  };\n\n  return (\n    <Card className=\"w-full max-w-md mx-auto\">\n      <CardHeader>\n        <CardTitle>UI Layout & Custom Fields</CardTitle>\n        <CardDescription>\n          Mixing inline UI components with completely custom registered fields.\n        </CardDescription>\n      </CardHeader>\n      <CardContent>\n        {/* We pass our custom fields inside the `registries.fields` prop to register them */}\n        <Form\n          schema={customSchema}\n          onSubmit={handleSubmit}\n          registries={{\n            fields: {\n              \"color-picker\": ColorPickerField,\n            },\n          }}\n        >\n          <FormContent>\n            <FormFields />\n            <FormActions>\n              <FormSubmit>Save Theme</FormSubmit>\n            </FormActions>\n          </FormContent>\n        </Form>\n      </CardContent>\n    </Card>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/buzzform/examples/ui-and-custom-fields-form.tsx"
    }
  ],
  "type": "registry:block"
}