{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "birth-date-field",
  "title": "Birth Date Field",
  "description": "A typed date of birth that cannot be in the future or implausibly old, and that shows the age it implies so a typo in the year is caught straight away. Use this when a form asks for a date of birth and a typo in the year should be obvious.",
  "registryDependencies": [
    "@tealmac/date-field",
    "@tealmac/date-time-core"
  ],
  "files": [
    {
      "path": "registry/patterns/birth-date-field/birth-date-field.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { DateField } from \"@/components/ui/date-field\"\nimport { ageOn, today as todayISO } from \"@/components/ui/date-time-core\"\n\nexport interface BirthDateFieldProps {\n  value?: string | null\n  defaultValue?: string | null\n  onValueChange?: (value: string | null) => void\n  maxAge?: number\n  today?: string\n  name?: string\n  locale?: string\n}\n\nexport function validateBirthDate(\n  date: string | null,\n  today: string,\n  maxAge = 120\n) {\n  if (!date) return { age: null, error: null }\n  if (date > today)\n    return { age: null, error: \"A date of birth cannot be in the future.\" }\n  const age = ageOn(date, today)\n  if (age > maxAge)\n    return { age, error: `Check the year: that would make you ${age}.` }\n  return { age, error: null }\n}\n\nexport function BirthDateField({\n  value,\n  defaultValue = null,\n  onValueChange,\n  maxAge = 120,\n  today,\n  name,\n  locale,\n}: BirthDateFieldProps) {\n  const now = today ?? todayISO()\n  const [inner, setInner] = React.useState<string | null>(defaultValue)\n  const date = value === undefined ? inner : value\n  const { age, error } = validateBirthDate(date, now, maxAge)\n  const id = React.useId()\n\n  return (\n    <div className=\"flex flex-col gap-1.5\">\n      <DateField\n        label=\"Date of birth\"\n        locale={locale}\n        name={name}\n        value={date}\n        aria-describedby={id}\n        invalid={!!error}\n        onValueChange={(next) => {\n          if (value === undefined) setInner(next)\n          onValueChange?.(next)\n        }}\n      />\n      <p\n        id={id}\n        role={error ? \"alert\" : \"status\"}\n        className={\n          error ? \"text-destructive text-sm\" : \"text-muted-foreground text-sm\"\n        }\n      >\n        {error ??\n          (age !== null\n            ? `You are ${age} year${age === 1 ? \"\" : \"s\"} old.`\n            : \"\")}\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}