{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "field",
  "title": "Field",
  "description": "Form row with a label, a control, and helper or error text.",
  "registryDependencies": [
    "@pestoui/label",
    "@pestoui/style",
    "@pestoui/utils"
  ],
  "files": [
    {
      "path": "pestoui/components/field.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Label } from \"@/components/ui/label\"\nimport { cn } from \"@/lib/utils\"\n\n/* Label + control + helper/error text — the standard form row */\nexport function Field({\n  label,\n  htmlFor,\n  hint,\n  error,\n  optional = false,\n  children,\n  className,\n}: {\n  label: string\n  htmlFor?: string\n  hint?: string\n  error?: string\n  optional?: boolean\n  children: React.ReactNode\n  className?: string\n}) {\n  const messageId = React.useId()\n  const message = error ?? hint\n\n  /* The shake fires on the transition INTO an error, not on a row that happens\n     to mount already invalid — a form rendered with server-side errors would\n     otherwise jitter on load, which reads as noise rather than as feedback. A\n     second, different failure re-arms it; the class is dropped again on\n     animationend so the next one can restart the keyframes. */\n  const [shaking, setShaking] = React.useState(false)\n  const previousError = React.useRef(error)\n  React.useEffect(() => {\n    if (error && error !== previousError.current) setShaking(true)\n    previousError.current = error\n  }, [error])\n\n  /* The control carries the wiring: it points at the message and reports its\n     own invalidity, so the shake is something a screen reader can follow.\n     Anything set explicitly on the child wins — this only fills in gaps. */\n  const control = React.Children.map(children, (child) => {\n    if (!React.isValidElement<Record<string, unknown>>(child)) return child\n    if (child.type === React.Fragment) return child\n\n    const describedBy = [\n      child.props[\"aria-describedby\"],\n      message ? messageId : null,\n    ]\n      .filter(Boolean)\n      .join(\" \")\n\n    return React.cloneElement(child, {\n      \"aria-describedby\": describedBy || undefined,\n      \"aria-invalid\": child.props[\"aria-invalid\"] ?? (error ? true : undefined),\n    })\n  })\n\n  return (\n    <div\n      className={cn(\"space-y-2\", shaking && \"animate-shake\", className)}\n      onAnimationEnd={(event) => {\n        if (event.target === event.currentTarget) setShaking(false)\n      }}\n    >\n      <Label htmlFor={htmlFor}>\n        {label}\n        {optional && (\n          <span className=\"font-normal text-muted-foreground\">Optional</span>\n        )}\n      </Label>\n      {control}\n      {message && (\n        /* Keyed on the text so a hint→error swap remounts the node: the enter\n           is an @starting-style transition, and only a fresh element fires it. */\n        <p\n          key={error ? `error:${error}` : `hint:${hint}`}\n          id={messageId}\n          className={cn(\n            \"text-caption transition-[opacity,translate,filter] duration-base ease-out-expo starting:-translate-y-1 starting:opacity-0 starting:blur-xs\",\n            error ? \"text-destructive\" : \"text-muted-foreground\"\n          )}\n        >\n          {message}\n        </p>\n      )}\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}