{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "field",
  "title": "Field",
  "description": "A labeled form control: the label, an optional description, the control and its error, wired together with ids that match between the server and the browser.",
  "dependencies": [
    "@base-ui/react@^1.8.0"
  ],
  "registryDependencies": [
    "@ouro/lib-appearance-hints",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-field"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/field/field-parts.tsx",
      "content": "\"use client\";\n\nimport { Field as BaseField } from \"@base-ui/react/field\";\nimport { useMemo, type JSX, type Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { devThrow } from \"@/registry/ouro/lib/ouro/dev\";\nimport { FieldContext, useField, useFieldOwner, type FieldContextValue } from \"@/registry/ouro/lib/ouro/use-field\";\nimport {\n  controlClass,\n  descriptionClass,\n  errorClass,\n  fieldHint,\n  inlineLabelClass,\n  labelClass,\n  labelFrameClass,\n  requiredMarkClass,\n  rootClass,\n} from \"@/registry/ouro/components/ouro/field/field-styles\";\n\n/** The JSX a part belongs in, for the dev message when it is not there. */\nconst SHAPE =\n  '<FieldRoot name=\"email\"><FieldLabel>Email</FieldLabel><FieldDescription>…</FieldDescription><FieldControl /><FieldError /></FieldRoot>';\n\n/** The enclosing field's state; throws in development, with the JSX the part belongs in, outside one. */\nfunction useFieldPart(part: string): FieldContextValue {\n  const field = useField();\n  if (!field) {\n    devThrow(\n      part,\n      \"must be rendered inside <FieldRoot> or <Field>\",\n      process.env.NODE_ENV !== \"production\" ? SHAPE : /* istanbul ignore next @preserve -- production only */ \"\",\n    );\n  }\n  return field;\n}\n\n/**\n * The className check every part runs, with the field's hint.\n *\n * @claim \"The className check every part runs\" registry/ouro/components/ouro/field/field-parts.tsx verify:fileLine(registry/ouro/components/ouro/field/field-parts.tsx, /function\\suseLayoutClassName\\(part:\\sstring,/)\n */\nfunction useLayoutClassName(part: string, className: string | undefined): void {\n  useAppearanceClassNameCheck(\n    part,\n    className,\n    process.env.NODE_ENV !== \"production\" ? fieldHint : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n}\n\n/** Props for {@link FieldRoot}. `className` is for layout only (margins, width, grid placement). */\nexport type FieldRootProps = Omit<BaseField.Root.Props, \"className\"> & {\n  className?: string | undefined;\n  /** The control is required: it gets `required` and `aria-required`, and the label a marker. */\n  required?: boolean | undefined;\n};\n\n/**\n * Part: the state owner of a field built from parts. It connects the label, description\n * and error to the control, and passes `name`, `disabled` and `required` down. Use the\n * `Field` component instead unless its props cannot express your layout; every Ouro form\n * control is built on these parts. Parts link the description and error after hydration;\n * use `Field` when the server HTML must carry them, or pass `id`s and `aria-describedby`\n * yourself.\n *\n * @example\n * <FieldRoot name=\"email\" required>\n *   <FieldLabel>Email</FieldLabel>\n *   <FieldDescription>We never share it.</FieldDescription>\n *   <FieldControl type=\"email\" />\n *   <FieldError />\n * </FieldRoot>\n */\nexport function FieldRoot({ className, required, ...props }: FieldRootProps): JSX.Element {\n  useLayoutClassName(\"FieldRoot\", className);\n  const invalid = Boolean(props.invalid);\n  const value = useMemo(() => ({ required: Boolean(required), describedBy: undefined, invalid, labelId: undefined }), [required, invalid]);\n  return (\n    <FieldContext.Provider value={value}>\n      <BaseField.Root {...props} data-ouro=\"field\" className={cn(rootClass, className)} />\n    </FieldContext.Provider>\n  );\n}\n\n/**\n * Props for {@link FieldLabel}. `className` goes on the element around the label and is for\n * layout only (`sr-only` hides the label visually); every other prop (`style`, `id`, `data-*`,\n * event handlers) goes on the `<label>` itself.\n * @claim \"`className` goes on the element around\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Field wiring > hides the label visually with hideLabel and keeps it as the name)\n * @claim \"`className` goes on the element around\" registry/ouro/components/ouro/field/field-parts.tsx verify:fileLine(registry/ouro/components/ouro/field/field-parts.tsx, /export\\stype\\sFieldLabelProps\\s=\\sOmit<BaseField\\.Label\\.Props,\\s\"className\">/)\n */\nexport type FieldLabelProps = Omit<BaseField.Label.Props, \"className\"> & { className?: string | undefined };\n\n/**\n * Part: the control's label. It points at the control by id. A required field shows a marker\n * after it, drawn by CSS on the element around the label, so the label's text and the\n * control's name stay exactly what you wrote (screen readers hear \"required\" from the\n * control). `className` goes on that element, where `[data-ouro-required]` is too; hide the\n * label visually with `className=\"sr-only\"`. `style`, `id`, `data-*` attributes and event\n * handlers go on the `<label>`.\n */\nexport function FieldLabel({ className, children, ...props }: FieldLabelProps): JSX.Element {\n  const field = useFieldPart(\"FieldLabel\");\n  useLayoutClassName(\"FieldLabel\", className);\n  // The label beside a checkbox or switch is its tap target, so it keeps phone-sized text on touch.\n  const inline = useFieldOwner().layout === \"inline\";\n  return (\n    <div\n      data-ouro-label=\"\"\n      {...(field.required ? { \"data-ouro-required\": \"\" } : {})}\n      className={cn(labelFrameClass, inline && inlineLabelClass, field.required && requiredMarkClass, className)}\n    >\n      <BaseField.Label {...props} className={labelClass}>\n        {children}\n      </BaseField.Label>\n    </div>\n  );\n}\n\n/** Props for {@link FieldDescription}. `className` is for layout only. */\nexport type FieldDescriptionProps = Omit<BaseField.Description.Props, \"className\"> & { className?: string | undefined };\n\n/** Part: supporting text for the control, read after its label through `aria-describedby`. */\nexport function FieldDescription({ className, ...props }: FieldDescriptionProps): JSX.Element {\n  useFieldPart(\"FieldDescription\");\n  useLayoutClassName(\"FieldDescription\", className);\n  return <BaseField.Description {...props} className={cn(descriptionClass, className)} />;\n}\n\n/** Props for {@link FieldError}. `className` is for layout only. */\nexport type FieldErrorProps = Omit<BaseField.Error.Props, \"className\"> & { className?: string | undefined };\n\n/**\n * Part: the error message, linked to the control through `aria-describedby`. Without\n * children it shows the browser's validation message, or a Base UI `Form` error for the\n * field's `name`; with `match` and children it always shows them. It fades and slides in.\n * @claim \"Without children it shows the browser's\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Field wiring > shows a Base UI Form error for its name without an error prop)\n * @claim \"Without children it shows the browser's\" registry/ouro/components/ouro/field/field.test.tsx verify:fileLine(registry/ouro/components/ouro/field/field.test.tsx, /<FieldError\\smatch>Enter\\san\\semail\\saddress\\.</FieldError>/)\n */\nexport function FieldError({ className, ...props }: FieldErrorProps): JSX.Element {\n  useFieldPart(\"FieldError\");\n  useLayoutClassName(\"FieldError\", className);\n  return <BaseField.Error data-ouro-text=\"\" {...props} className={cn(errorClass, className)} />;\n}\n\n/** Props for {@link FieldControl}. `className` is for layout only. */\nexport type FieldControlProps = Omit<BaseField.Control.Props, \"className\"> & {\n  className?: string | undefined;\n  ref?: Ref<HTMLInputElement> | undefined;\n};\n\n/**\n * Part: the control, a text `<input>` by default. It takes the field's id, `name`,\n * `disabled` and `required`, `aria-invalid` from its error (`false` without one, so WebKit does not\n * read an empty required field as invalid before anyone types), and `aria-describedby` from its\n * description and error. Render another element with\n * `render={<textarea />}`.\n */\nexport function FieldControl({ className, required, ...props }: FieldControlProps): JSX.Element {\n  const field = useFieldPart(\"FieldControl\");\n  useLayoutClassName(\"FieldControl\", className);\n  const isRequired = Boolean(field.required || required);\n  const describedBy = [field.describedBy, props[\"aria-describedby\"]].filter(Boolean).join(\" \") || undefined;\n  return (\n    <BaseField.Control\n      data-ouro-control=\"field\"\n      data-ouro-part=\"control\"\n      {...props}\n      required={isRequired}\n      // A passed `aria-required` says \"required\" without the browser's blocking check.\n      aria-required={isRequired || props[\"aria-required\"]}\n      aria-describedby={describedBy}\n      // Said even when valid: without it, WebKit reads an empty required input as invalid before anyone types.\n      aria-invalid={field.invalid || (props[\"aria-invalid\"] ?? false)}\n      className={cn(controlClass, className)}\n    />\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/field/field-parts.tsx"
    },
    {
      "path": "registry/ouro/components/ouro/field/field-styles.ts",
      "content": "import { toneFor } from \"@/registry/ouro/lib/ouro/appearance-hints\";\nimport type { DevWarning } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\nexport {\n  choicesClass,\n  contractWarnings,\n  controlClass,\n  descriptionClass,\n  errorClass,\n  fieldHint,\n  inlineLabelClass,\n  inlineRootClass,\n  labelClass,\n  labelFrameClass,\n  legendClass,\n  requiredMarkClass,\n  rootClass,\n};\nexport type { ContractGuesses };\n\n// Class strings and dev-message helpers shared by Field, Fieldset and the Field parts, apart\n// from the components so each component file exports only components (React Fast Refresh).\n// Class strings are literal so the app's Tailwind finds them when it compiles.\n\n/**\n * The field's stack: label, description, control, error.\n *\n * @internal\n */\nconst rootClass = \"group/field box-border grid min-w-0 content-start gap-2\";\n\n/**\n * A field whose control comes first, with the label to its right (a checkbox, a switch, a\n * radio): the control in the first column, the label, description and error in the second.\n *\n * @internal\n */\nconst inlineRootClass = \"group/field box-border grid min-w-0 grid-cols-[auto_minmax(0,1fr)] content-start items-start gap-x-3 gap-y-1\";\n\n/**\n * The label beside an inline control, which is also its tap target: 16px text on 24px lines\n * on touch screens, stepping down to the field label's 14px on 20px lines from the `sm`\n * breakpoint with a fine pointer, so a landscape phone keeps the phone size.\n *\n * @internal\n * @claim \"The label beside an inline control\" registry/ouro/components/ouro/checkbox/checkbox.touch.test.tsx verify:testExists(registry/ouro/components/ouro/checkbox/checkbox.touch.test.tsx::keeps the 20px box and 16px label on a landscape phone, past the sm breakpoint)\n * @claim \"The label beside an inline control\" registry/ouro/components/ouro/field/field-styles.ts verify:fileLine(registry/ouro/components/ouro/field/field-styles.ts, /const\\sinlineLabelClass\\s=\\s\"text-base\\sleading-6\\ssm:pointer-fine:text-sm\\ssm:pointer-fine:leading-5\"/)\n */\nconst inlineLabelClass = \"text-base leading-6 sm:pointer-fine:text-sm sm:pointer-fine:leading-5\";\n\n/**\n * The choices in a CheckboxGroup or RadioGroup: one under the other, or with `horizontal`,\n * in a row that wraps. On touch screens rows sit 20px apart, so each control's 44px hit area\n * stays clear of its neighbors'; with a fine pointer from the `sm` breakpoint, 12px.\n *\n * @internal\n * @claim \"On touch screens rows sit 20px\" registry/ouro/components/ouro/field/field-styles.ts verify:fileLine(registry/ouro/components/ouro/field/field-styles.ts, /vertical:\\s\"grid\\sgap-5\\ssm:pointer-fine:gap-3\"/)\n */\nconst choicesClass = {\n  vertical: \"grid gap-5 sm:pointer-fine:gap-3\",\n  horizontal: \"flex flex-wrap gap-x-6 gap-y-5 sm:pointer-fine:gap-y-3\",\n} as const;\n\n/**\n * The element around the label, which sizes its text and takes the field's layout classes.\n * The required marker hangs off it, not off the label, so the label's text stays the label.\n *\n * @internal\n */\nconst labelFrameClass = \"block justify-self-start text-sm leading-5 select-none\";\n\n/**\n * The label: medium weight, faded with the field when it is disabled. Inline, so the required\n * marker follows its last word, and padded to its line height, so its hit area is every\n * line it wraps to and the gaps between them: a checkbox's or switch's label is the\n * control's tap target on a phone. Vertical padding on an inline box does not move the lines.\n *\n * @internal\n * @claim \"Inline, so the required marker follows\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Field wiring > shows the required marker beside the label, and in forced colors too)\n * @claim \"Inline, so the required marker follows\" registry/ouro/components/ouro/field/field-styles.ts verify:fileLine(registry/ouro/components/ouro/field/field-styles.ts, /py-\\[calc\\(\\(1lh-1em\\)\\/2\\)\\]/)\n */\nconst labelClass = \"m-0 inline py-[calc((1lh-1em)/2)] font-medium text-foreground data-disabled:opacity-50\";\n\n/**\n * The required marker, on the element around a label or on a group's legend: an asterisk\n * drawn by CSS, so it is in no element's text and no control's name. `getByLabelText(\"Email\")`\n * and `getByLabel(\"Email\", { exact: true })` find a required field, and screen readers hear\n * \"required\" from the control. Its alternative text is empty, so screen readers in reading\n * mode do not say \"star\"; a browser without that syntax shows the plain asterisk. It is\n * generated text, so forced colors keep it visible. It fades when the field is disabled.\n *\n * @internal\n * @claim \"The required marker, on the element\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Field wiring > sets required and aria-required, and marks the label without adding to its text or name)\n * @claim \"The required marker, on the element\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Required marker > is an asterisk with empty alternative text, so screen readers do not read it)\n */\nconst requiredMarkClass =\n  \"after:ms-0.5 after:font-medium after:text-destructive after:content-['*'] supports-[content:'*'_/_'']:after:content-['*'_/_''] \" +\n  \"group-data-disabled/field:after:opacity-50\";\n\n/**\n * Supporting text under the label, and under a fieldset's legend. It stays at full contrast when the\n * field is disabled, because it often says why. It wraps with `text-wrap: pretty`, so it does not end on\n * one stranded word.\n *\n * @internal\n */\nconst descriptionClass = \"m-0 text-sm leading-5 text-pretty text-muted-foreground\";\n\n/**\n * The error message: it fades and slides in, and with reduced motion only fades. Several\n * messages render as a list.\n *\n * @internal\n */\nconst errorClass =\n  \"m-0 text-sm leading-5 text-destructive \" +\n  \"[transition:opacity_var(--ouro-duration-base)_var(--ouro-ease-out),translate_var(--ouro-duration-base)_var(--ouro-ease-out)] \" +\n  \"data-starting-style:opacity-0 data-starting-style:-translate-y-1 \" +\n  \"data-ending-style:opacity-0 data-ending-style:-translate-y-1 \" +\n  \"motion-reduce:[transition:opacity_var(--ouro-duration-base)_var(--ouro-ease-out)] \" +\n  \"motion-reduce:data-starting-style:translate-y-0 motion-reduce:data-ending-style:translate-y-0 \" +\n  \"[&_ul]:m-0 [&_ul]:list-disc [&_ul]:ps-5\";\n\n/**\n * A fieldset's legend.\n *\n * @internal\n */\nconst legendClass = \"m-0 p-0 text-base leading-6 font-semibold text-foreground data-disabled:opacity-50\";\n\n/**\n * The text control: 44px tall with a 16px font on phones (iOS zooms into smaller text on\n * focus), stepping down to desktop density from the `sm` breakpoint with a fine pointer, so a\n * landscape phone keeps the phone size. Its height is one\n * unprefixed class that reads a variable, so an app's `h-*` replaces it at every width.\n *\n * @internal\n * @claim \"The text control: 44px tall with\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Field looks > uses a 16px font on phones, so iOS does not zoom on focus, and steps down from sm)\n * @claim \"The text control: 44px tall with\" registry/ouro/components/ouro/field/field-styles.ts verify:fileLine(registry/ouro/components/ouro/field/field-styles.ts, /h-\\(--ouro-control-h\\)/)\n * @claim \"Its height is one unprefixed class\" registry/ouro/components/ouro/field/field-styles.ts verify:fileLine(registry/ouro/components/ouro/field/field-styles.ts, /h-\\(--ouro-control-h\\)/)\n */\nconst controlClass =\n  \"m-0 box-border block w-full min-w-0 h-(--ouro-control-h) px-3 py-0 \" +\n  \"[--ouro-control-h:calc(var(--spacing)*11)] sm:pointer-fine:[--ouro-control-h:calc(var(--spacing)*9)] \" +\n  \"rounded-ouro-md border border-solid border-input bg-transparent text-base text-foreground sm:pointer-fine:text-sm \" +\n  \"font-[inherit] placeholder:text-muted-foreground \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"transition-[border-color] duration-(--ouro-duration-fast) ease-[ease] \" +\n  \"aria-invalid:border-destructive disabled:cursor-not-allowed disabled:opacity-50 \" +\n  \"dark:bg-input/30\";\n\n/**\n * The fix for an appearance class on a field: an error color is the `error` prop; anything\n * else is the theme's job. Development only.\n *\n * @internal\n */\nfunction fieldHint(token: string, component = \"Field\"): string {\n  return toneFor(token) === \"destructive\" ? `<${component} error=\"What is wrong\">` : \"style fields in your theme (--input, --ring, --radius)\";\n}\n\n/**\n * The Field contract's guessed prop names, which a control built on Field declares as hint types.\n *\n * @internal\n */\ninterface ContractGuesses {\n  errorMessage?: unknown;\n  helperText?: unknown;\n  isInvalid?: unknown;\n  invalid?: unknown;\n  isRequired?: unknown;\n  isDisabled?: unknown;\n}\n\n/**\n * The development messages for the contract's guessed props on a control built on Field,\n * each naming the real prop. Development only.\n *\n * @internal\n * @claim \"The development messages for the contract's\" registry/ouro/components/ouro/text-field/text-field.test.tsx verify:fileLine(registry/ouro/components/ouro/text-field/text-field.test.tsx, /\\[\"helperText\",\\s\\{\\shelperText:\\s\"Hint\"\\s\\},\\s\"helperText\\sis\\snot\\sa\\sprop\",\\s'<TextField\\sdescription=\"Hint\">'\\]/)\n */\nfunction contractWarnings(component: string, guesses: ContractGuesses): DevWarning[] {\n  const { errorMessage, helperText, isInvalid, invalid, isRequired, isDisabled } = guesses;\n  return [\n    errorMessage !== undefined && [\"errorMessage is not a prop\", `<${component} error=\"${String(errorMessage)}\">`],\n    helperText !== undefined && [\"helperText is not a prop\", `<${component} description=\"${String(helperText)}\">`],\n    isInvalid !== undefined && [\"isInvalid is not a prop\", `<${component} error=\"What is wrong\">`],\n    invalid !== undefined && [\"invalid is not a prop\", `<${component} error=\"What is wrong\">`],\n    isRequired !== undefined && [\"isRequired is not a prop\", `<${component} required>`],\n    isDisabled !== undefined && [\"isDisabled is not a prop\", `<${component} disabled>`],\n  ];\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/field/field-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/field/field.tsx",
      "content": "\"use client\";\n\nimport { Field as BaseField } from \"@base-ui/react/field\";\nimport { useCallback, useEffect, useId, useMemo, useRef, type FormEvent, type JSX, type ReactElement, type ReactNode } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport {\n  errorMessageKey,\n  errorMessages,\n  FieldContext,\n  FieldOwnerContext,\n  useField,\n  useFieldOwner,\n  useFormErrors,\n  type ReadonlyErrorMessages,\n} from \"@/registry/ouro/lib/ouro/use-field\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { FieldDescription, FieldError, FieldLabel } from \"@/registry/ouro/components/ouro/field/field-parts\";\nimport { fieldHint, inlineRootClass, labelFrameClass, requiredMarkClass, rootClass } from \"@/registry/ouro/components/ouro/field/field-styles\";\n\n/**\n * The props every Ouro form control takes, with these exact names: a required `label`,\n * `description`, `error`, `required`, `disabled` and `name`.\n * @claim \"The props every Ouro form control\" test/field-contract.test.tsx verify:testExists(test/field-contract.test.tsx::%s with display-only errors > shows its own error prop, marks the control, and resubmits unchanged)\n * @claim \"The props every Ouro form control\" registry/ouro/components/ouro/field/field.test-d.ts verify:fileLine(registry/ouro/components/ouro/field/field.test-d.ts, /expectTypeOf<\\{\\schildren:\\snull\\s\\}>\\(\\)\\.not\\.toExtend<FieldProps>/)\n */\nexport interface FieldProps {\n  /**\n   * What the control is for, shown above it and read as its name. Required: every control\n   * needs a name. To hide it visually, keep it and add `hideLabel`.\n   * @claim \"Required: every control needs a name\" registry/ouro/components/ouro/field/field.test-d.ts verify:fileLine(registry/ouro/components/ouro/field/field.test-d.ts, /expectTypeOf<\\{\\schildren:\\snull\\s\\}>\\(\\)\\.not\\.toExtend<FieldProps>/)\n   */\n  label: string;\n  /** Hides the label visually; screen readers still read it as the control's name. */\n  hideLabel?: boolean | undefined;\n  /** Supporting text under the label, read after the label through `aria-describedby`. */\n  description?: ReactNode | undefined;\n  /**\n   * What is wrong, from your server action or client check. A message (or several, as an\n   * array, each shown once as a list item) shows under the control, which gets `aria-invalid`\n   * and points at the message with `aria-describedby`. A message is text or a React node, so\n   * it can carry a link: `error={<>Already imported. <Link href=\"/recipes/soup\">Open it</Link></>}`.\n   * An empty string or array means valid. It only\n   * shows: it never blocks the next submit of the form around it.\n   * @claim \"A message (or several, as an\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Field wiring > shows every message of an error array as a list)\n   * @claim \"A message (or several, as an\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Field wiring > shows an error that is a React node, such as a message with a link, and describes the control with it)\n   * @claim \"It only shows: it never blocks\" registry/ouro/components/ouro/form/form.test.tsx verify:testExists(registry/ouro/components/ouro/form/form.test.tsx::Form errors are display-only (review fix round 1, finding 1) > resubmits a TextField after a server error, with the field unchanged)\n   */\n  error?: ReadonlyErrorMessages | undefined;\n  /** The control must be filled: it gets `required` and `aria-required`, and the label a marker. */\n  required?: boolean | undefined;\n  /** Disables the control and fades the field. */\n  disabled?: boolean | undefined;\n  /**\n   * The form field name the control submits under. A `Form`'s `errors` for this name show\n   * here when there is no `error` prop, and go away once the user changes the control.\n   * @claim \"A `Form`'s `errors` for this name\" registry/ouro/components/ouro/field/field.test.tsx verify:testExists(registry/ouro/components/ouro/field/field.test.tsx::Field wiring > shows a Base UI Form error for its name without an error prop)\n   */\n  name?: string | undefined;\n  /** The control: `<FieldControl />`, or `<FieldControl render={<textarea />} />` for another element. */\n  children: ReactNode;\n  /**\n   * Layout only: margins, width, grid placement (`mt-4`, `col-span-2`). Appearance\n   * classes warn in development; style fields in your theme.\n   */\n  className?: string | undefined;\n\n  /** Not a prop. Field connects the label to its control itself: `<Field label=\"Email\"><FieldControl /></Field>`. */\n  htmlFor?: { 'Field connects the label itself: <Field label=\"Email\"><FieldControl /></Field>': never };\n  /** Not a prop. Ouro UI uses `error`: `<Field error=\"Required.\">`. */\n  errorMessage?: { 'Use <Field error=\"Required.\">': never };\n  /** Not a prop. Ouro UI uses `description`: `<Field description=\"We never share it.\">`. */\n  helperText?: { 'Use <Field description=\"...\">': never };\n  /** Not a prop. `error` marks the field invalid: `<Field error=\"What is wrong\">`. */\n  isInvalid?: { 'Use <Field error=\"What is wrong\">': never };\n  /** Not a prop. `error` marks the field invalid: `<Field error=\"What is wrong\">`. */\n  invalid?: { 'Use <Field error=\"What is wrong\">': never };\n  /** Not a prop. Ouro UI uses `required`: `<Field required>`. */\n  isRequired?: { 'Use <Field required>': never };\n  /** Not a prop. Ouro UI uses `disabled`: `<Field disabled>`. */\n  isDisabled?: { 'Use <Field disabled>': never };\n  /** Not a prop, and not a label. Pass `label`, and a placeholder example on the control: `<FieldControl placeholder=\"you@example.com\" />`. */\n  placeholder?: { 'Use label=\"Email\"; a placeholder example goes on the control': never };\n}\n\n/** Field's own arrangement: the label, then the rest. */\nconst defaultFrame = (label: ReactElement, rest: ReactNode): ReactNode => (\n  <>\n    {label}\n    {rest}\n  </>\n);\n\n/** The owner a plain Field has, restored for the Field's own children. */\nconst fieldOwner = { name: \"Field\", data: \"field\" };\n\n/**\n * The label is connected when its `for` names an element inside the field, or when an element\n * inside the field names it in `aria-labelledby`: a range Slider's group names the label\n * element's own id, and a label that is not a `<label>` (Select's) is named by `labelId`.\n * Development only.\n */\nfunction labelConnected(root: HTMLElement, data: string, labelId: string, nativeLabel: boolean): boolean {\n  const label = root.querySelector(\"label\");\n  const inside = (element: Element | null) => element?.closest(`[data-ouro=\"${data}\"]`) === root;\n  if (nativeLabel && label?.htmlFor && inside(root.ownerDocument.getElementById(label.htmlFor))) return true;\n  return [label?.id ?? labelId, labelId].some((id) =>\n    [...root.querySelectorAll(`[aria-labelledby~=\"${CSS.escape(id)}\"]`)].some(inside),\n  );\n}\n\n/**\n * A labeled form control: the label, an optional description, the control and its error,\n * wired together with ids that match between the server and the browser. Every Ouro form\n * control takes these props and is built on the same parts.\n *\n * Pass `error` straight from a server action or a client check: it shows the message and\n * sets `aria-invalid`. The error only shows: it never blocks the form's next submit, so the\n * user can always send the form again (only the browser's own checks, such as `required`,\n * block). Inside a `Form`, a field with a `name` shows the form's error for that name when\n * it has no `error` of its own. The control is `FieldControl`, from `field-parts`. Use `Fieldset` instead to group several controls under one legend,\n * and the `FieldRoot` parts when the label, control and error need another layout.\n *\n * The order is fixed: label, `description`, control, error. To put helper text after the\n * control, leave `description` out and render a `FieldDescription` after the `FieldControl`.\n * It is linked to the control (`aria-describedby`) wherever it sits, and the error still\n * comes last. `TextField` and the other one-tag controls render their own control, so\n * build that field from `Field` and `FieldControl`.\n *\n * The required marker is drawn with CSS beside the label and is not part of its text, so a\n * test finds the field by the label alone: `getByLabelText(\"Email\")`, or Playwright's\n * `getByLabel(\"Email\", { exact: true })`. The marker stays visible in forced colors.\n *\n * A field's error is the control's description, not an alert, so screen readers read it\n * when focus reaches the field (a `Form` moves focus to the first invalid one). In a test,\n * assert it with `toHaveAccessibleDescription(\"Enter an email address.\")` or `getByText`;\n * `getByRole(\"alert\")` finds only a Form's message about the whole form.\n *\n * @group Forms\n * @see https://ui.ouroboros.bot/docs/field\n *\n * @example\n * <Field label=\"Email\" name=\"email\" required description=\"We never share it.\" error={errors?.email}>\n *   <FieldControl type=\"email\" autoComplete=\"email\" />\n * </Field>\n *\n * @example\n * // Helper text after the control: a FieldDescription placed where it shows.\n * <Field label=\"Password\" name=\"password\" required error={errors?.password}>\n *   <FieldControl type=\"password\" autoComplete=\"new-password\" />\n *   <FieldDescription>Use 8 or more characters.</FieldDescription>\n * </Field>\n * @claim \"The error only shows: it never\" test/field-contract.test.tsx verify:testExists(test/field-contract.test.tsx::%s with display-only errors > shows its own error prop, marks the control, and resubmits unchanged)\n * @claim \"Inside a `Form`, a field with\" test/field-contract.test.tsx verify:testExists(test/field-contract.test.tsx::%s with display-only errors > shows its own error prop, marks the control, and resubmits unchanged)\n * @claim \"Every Ouro form control takes these\" test/field-contract.test.tsx verify:fileLine(test/field-contract.test.tsx, /const\\scontrols:\\s\\[string,/)\n */\nexport function Field(props: FieldProps): JSX.Element {\n  const {\n    label,\n    hideLabel,\n    description,\n    error,\n    required,\n    disabled,\n    name,\n    children,\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    htmlFor,\n    errorMessage,\n    helperText,\n    isInvalid,\n    invalid: invalidGuess,\n    isRequired,\n    isDisabled,\n    placeholder,\n  } = props;\n  const id = useId();\n  // A control built on Field (TextField) names itself in the messages and the root.\n  const owner = useFieldOwner();\n  const layout = owner.layout ?? \"stack\";\n  const nativeLabel = owner.nativeLabel !== false;\n  // A checkbox or radio inside a CheckboxGroup or RadioGroup is one of the group's items: it\n  // takes the group's name, validity and error, and has none of its own.\n  const parent = useField();\n  const group = parent?.group;\n  const item = layout === \"inline\" && group !== undefined;\n  // A Form's error for this name shows when the field has no `error` of its own. Reading it\n  // here, while rendering, puts the message id in the server HTML's aria-describedby.\n  const form = useFormErrors();\n  const formError = error === undefined && name !== undefined ? form?.errors[name] : undefined;\n  const messages = item ? [] : errorMessages(error ?? formError);\n  const invalid = messages.length > 0;\n  const hasDescription = description !== undefined && description !== null && description !== false && description !== \"\";\n  const labelId = `${id}-label`;\n  const descriptionId = `${id}-description`;\n  const errorId = `${id}-error`;\n  // An item is also described by its group's description and error, as Base UI links them\n  // after hydration, so the server HTML matches.\n  const describedBy =\n    [hasDescription && descriptionId, invalid && errorId, item && parent!.describedBy].filter(Boolean).join(\" \") || undefined;\n  const invalidHere = item ? parent!.invalid : invalid;\n  const requiredHere = Boolean(required) && !item;\n  const ownGroup = layout === \"group\" ? owner.name : undefined;\n  const value = useMemo(\n    () => ({ required: requiredHere, describedBy, invalid: invalidHere, labelId, group: ownGroup }),\n    [requiredHere, describedBy, invalidHere, labelId, ownGroup],\n  );\n  // Changing the control drops its Form error, as Base UI's Form drops its own copy. Every\n  // control's change event bubbles here; a control without one (Select) clears it itself.\n  const clearFormError = (event: FormEvent<HTMLDivElement>) => {\n    if (formError === undefined || (event.target as HTMLElement).closest(`[data-ouro=\"${owner.data}\"]`) !== event.currentTarget) return;\n    form!.clear(name!);\n  };\n\n  // The field claims its name in the Form, so the Form shows its errors here, not at the top.\n  const register = form?.register;\n  useEffect(() => (register && name !== undefined ? register(name) : undefined), [register, name]);\n\n  // The dev checks run after render, when the root is in the page and the control has\n  // registered its id with the label.\n  const rootRef = useRef<HTMLDivElement>(null);\n\n  // A message can leave just after a press starts in its form (the change before it clears the\n  // message, and the message is unmounted once its fade ends), and then the controls below it, Sign\n  // among them, would move out from under the press. Until the press ends the field keeps its\n  // height, so the space stays; then it collapses.\n  useEffect(\n    () => {\n      const root = rootRef.current!;\n      const form = root.closest(\"form\");\n      if (!form) return undefined;\n      const view = root.ownerDocument.defaultView!;\n      let minHeight: string | undefined;\n      const release = () => {\n        // Stryker disable next-line ConditionalExpression: with nothing held this runs only at unmount, and an undefined min-height assigned there changes nothing\n        if (minHeight === undefined) return;\n        root.style.minHeight = minHeight;\n        minHeight = undefined;\n        view.removeEventListener(\"pointerup\", release, true);\n        view.removeEventListener(\"pointercancel\", release, true);\n      };\n      const hold = () => {\n        if (minHeight !== undefined || !root.querySelector(\"[data-ouro-text]\")) return;\n        minHeight = root.style.minHeight;\n        root.style.minHeight = `${root.getBoundingClientRect().height}px`;\n        view.addEventListener(\"pointerup\", release, true);\n        view.addEventListener(\"pointercancel\", release, true);\n      };\n      form.addEventListener(\"pointerdown\", hold);\n      return () => {\n        form.removeEventListener(\"pointerdown\", hold);\n        release();\n      };\n    },\n    // Stryker disable next-line ArrayDeclaration: the field's root and its form are the same elements for the field's whole life, so any constant list runs this effect once, on mount, as this one does.\n    [],\n  );\n\n  const hint = useCallback((token: string) => fieldHint(token, owner.name), [owner.name]);\n  useAppearanceClassNameCheck(\n    owner.name,\n    className,\n    process.env.NODE_ENV !== \"production\" ? hint : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    owner.name,\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !label &&\n            (layout === \"group\"\n              ? [`legend is ${label === \"\" ? \"empty\" : \"missing\"}, so the group has no name`, `<${owner.name} legend=\"Toppings\" hideLegend> to hide a legend you still need`]\n              : [`label is ${label === \"\" ? \"empty\" : \"missing\"}, so the control has no name`, `<${owner.name} label=\"Email\" hideLabel> to hide a label you still need`]),\n          layout !== \"group\" &&\n            !labelConnected(rootRef.current!, owner.data, labelId, nativeLabel) && [\n            \"the label is not connected to a control\",\n            `<Field label=\"${label}\"><FieldControl /></Field>, or <FieldControl render={<textarea />} /> for another element`,\n          ],\n          htmlFor !== undefined && [\"htmlFor is not a prop; Field connects the label itself\", '<Field label=\"Email\"><FieldControl /></Field>'],\n          errorMessage !== undefined && [\"errorMessage is not a prop\", `<Field error=\"${String(errorMessage)}\">`],\n          helperText !== undefined && [\"helperText is not a prop\", `<Field description=\"${String(helperText)}\">`],\n          isInvalid !== undefined && [\"isInvalid is not a prop\", '<Field error=\"What is wrong\">'],\n          invalidGuess !== undefined && [\"invalid is not a prop\", '<Field error=\"What is wrong\">'],\n          isRequired !== undefined && [\"isRequired is not a prop\", \"<Field required>\"],\n          isDisabled !== undefined && [\"isDisabled is not a prop\", \"<Field disabled>\"],\n          placeholder !== undefined && [\n            \"placeholder is not a label\",\n            '<Field label=\"Email\"><FieldControl placeholder=\"you@example.com\" /></Field>',\n          ],\n          item && name !== undefined && [`name belongs on the ${group}`, `<${group} name=\"${name}\">`],\n          item && error !== undefined && [`error belongs on the ${group}, which shows it once for every choice`, `<${group} error=\"What is wrong\">`],\n          item && required !== undefined && [`required belongs on the ${group}`, `<${group} required>`],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const legend =\n    layout === \"group\" ? (\n      // A group's name: not a <label>, because a group has no one element to focus. It names a\n      // section rather than a control, so it keeps full contrast when the group is disabled.\n      // The required marker is CSS on the legend, outside the element that names the group.\n      <div\n        data-ouro-legend=\"\"\n        {...(required ? { \"data-ouro-required\": \"\" } : {})}\n        className={cn(labelFrameClass, required && requiredMarkClass, hideLabel && \"sr-only\")}\n      >\n        <span id={labelId} className=\"font-medium text-foreground\">\n          {label}\n          {/* The asterisk is not text; a group with no aria-required says \"required\" in words. */}\n          {required && owner.requiredLabel && <span className=\"sr-only\"> {owner.requiredLabel}</span>}\n        </span>\n      </div>\n    ) : (\n      <FieldLabel\n        id={labelId}\n        className={cn(layout === \"inline\" && \"col-start-2\", hideLabel && \"sr-only\")}\n        {...(nativeLabel ? {} : { nativeLabel: false, render: <div /> })}\n      >\n        {label}\n      </FieldLabel>\n    );\n  // The owner names this Field only: a plain Field inside (in an adornment's popover) is a Field.\n  const control = <FieldOwnerContext.Provider value={fieldOwner}>{children}</FieldOwnerContext.Provider>;\n  const descriptionPart = hasDescription && (\n    <FieldDescription id={descriptionId} className={layout === \"inline\" ? \"col-start-2\" : undefined}>\n      {description}\n    </FieldDescription>\n  );\n  const errorPart = invalid ? (\n    <FieldError id={errorId} match className={layout === \"inline\" ? \"col-start-2\" : undefined}>\n      {messages.length > 1 ? (\n        <ul>\n          {messages.map((message, index) => (\n            <li key={errorMessageKey(message, index)}>{message}</li>\n          ))}\n        </ul>\n      ) : (\n        messages[0]\n      )}\n    </FieldError>\n  ) : (\n    <FieldError id={errorId} className={layout === \"inline\" ? \"col-start-2\" : undefined} />\n  );\n  // An inline control comes first, so it reads before its label, and sits to its left. A\n  // stacked field lets its owner arrange the label and the rest (NumberField, a range Slider).\n  const content =\n    layout === \"inline\" ? (\n      <>\n        {control}\n        {legend}\n        {descriptionPart}\n        {/* A group shows its error once. A choice in it shares the group's validity, so its own\n            error element would repeat the browser's message under every choice. */}\n        {!item && errorPart}\n      </>\n    ) : layout === \"group\" ? (\n      <>\n        {legend}\n        {descriptionPart}\n        {control}\n        {errorPart}\n      </>\n    ) : (\n      (owner.frame ?? defaultFrame)(\n        legend,\n        <>\n          {descriptionPart}\n          {control}\n          {errorPart}\n        </>,\n      )\n    );\n  const rootClassName = cn(layout === \"inline\" ? inlineRootClass : rootClass, className);\n\n  return (\n    <FieldContext.Provider value={value}>\n      {item ? (\n        <BaseField.Item ref={rootRef} disabled={disabled} data-ouro={owner.data} className={rootClassName}>\n          {content}\n        </BaseField.Item>\n      ) : (\n        // `invalid` stays Ouro's: Base UI would count it as a failed check and block the\n        // form's next submit. Its own checks (`required`, `type`) still mark and block.\n        <BaseField.Root\n          ref={rootRef}\n          name={name}\n          disabled={disabled}\n          {...(invalid ? { \"data-invalid\": \"\" } : {})}\n          data-ouro={owner.data}\n          className={rootClassName}\n          onChange={clearFormError}\n        >\n          {content}\n        </BaseField.Root>\n      )}\n    </FieldContext.Provider>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/field/field.tsx"
    }
  ],
  "docs": "A labeled form control: the label, an optional description, the control and its error, wired together with ids that match between the server and the browser. Import: import { Field } from \"@/components/ouro/field/field\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/field.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}