{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker",
  "title": "DatePicker",
  "description": "A labeled date field.",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/calendar",
    "@ouro/field",
    "@ouro/lib-env",
    "@ouro/lib-refs",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-field",
    "@ouro/lib-use-media-query",
    "@ouro/popover",
    "@ouro/text-field"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/calendar/date-picker-styles.ts",
      "content": "export { formatDateInput, parseDateInput };\n\n// Typing a date into DatePicker's text box: the locale's numeric date (10/11/2026 in en-US,\n// 11/10/2026 in en-GB, 11.10.2026 in de) both ways, apart from the component so its file\n// exports only components (React Fast Refresh).\n\n/** The locale's numeric date format, in Latin digits so it can be typed back. */\nfunction numeric(locale: string): Intl.DateTimeFormat {\n  return new Intl.DateTimeFormat(locale, { year: \"numeric\", month: \"2-digit\", day: \"2-digit\", numberingSystem: \"latn\", timeZone: \"UTC\" });\n}\n\n/**\n * The year ending in two typed digits that lies from 50 years before this year to 49 after it.\n *\n * @claim \"The year ending in two typed\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > reads a two-digit year as the year within 50 years of today)\n */\nfunction fullYear(twoDigits: number): number {\n  const earliest = new Date().getFullYear() - 50;\n  const year = Math.floor(earliest / 100) * 100 + twoDigits;\n  return year < earliest ? year + 100 : year;\n}\n\n/**\n * An ISO date as the locale writes it in numbers (`\"2026-10-11\"` is `\"10/11/2026\"` in\n * en-US), or `\"\"` for no date.\n *\n * @internal\n * @claim \"An ISO date as the locale\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > reads the locale's numbers or ISO, and writes the date the locale's way on blur)\n * @claim \"An ISO date as the locale\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > value > reformats when the locale changes, and ignores values that are not ISO dates)\n */\nfunction formatDateInput(iso: string, locale: string): string {\n  return iso === \"\" ? \"\" : numeric(locale).format(new Date(`${iso}T00:00:00Z`));\n}\n\n/**\n * What the user typed as an ISO date, or `null` when it is not a real date. It reads the\n * locale's order of day, month and year with any separators, a two-digit year as the year\n * ending in those digits within 50 years of today (in 2026, 85 is 1985 and 30 is 2030), and\n * an ISO date as it is.\n *\n * @internal\n * @claim \"It reads the locale's order of\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > reads a two-digit year as the year within 50 years of today)\n * @claim \"It reads the locale's order of\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > reads the locale's numbers or ISO, and writes the date the locale's way on blur)\n */\nfunction parseDateInput(text: string, locale: string): string | null {\n  const iso = /^\\s*(\\d{4})-(\\d{1,2})-(\\d{1,2})\\s*$/.exec(text);\n  const numbers = iso ? iso.slice(1) : text.match(/\\d+/g);\n  if (!numbers || numbers.length !== 3) return null;\n  const order = iso\n    ? [\"year\", \"month\", \"day\"]\n    : numeric(locale)\n        .formatToParts(new Date(0))\n        .map((part) => part.type)\n        .filter((type) => type === \"year\" || type === \"month\" || type === \"day\");\n  const parts: Record<string, number> = {};\n  order.forEach((type, index) => (parts[type] = Number(numbers[index])));\n  const year = numbers[order.indexOf(\"year\")]!.length <= 2 ? fullYear(parts.year!) : parts.year!;\n  const { month, day } = parts as { month: number; day: number };\n  const date = new Date(0);\n  date.setUTCFullYear(year, month - 1, day);\n  if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) return null;\n  return `${String(year).padStart(4, \"0\")}-${String(month).padStart(2, \"0\")}-${String(day).padStart(2, \"0\")}`;\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/calendar/date-picker-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/calendar/date-picker.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useLayoutEffect, useRef, useState, type ChangeEvent, type JSX, type MouseEvent, type ReactNode, type Ref } from \"react\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { Calendar } from \"@/registry/ouro/components/ouro/calendar/calendar\";\nimport { isIsoDate, isoWarning } from \"@/registry/ouro/components/ouro/calendar/calendar-styles\";\nimport { formatDateInput, parseDateInput } from \"@/registry/ouro/components/ouro/calendar/date-picker-styles\";\nimport { Field } from \"@/registry/ouro/components/ouro/field/field\";\nimport { FieldControl } from \"@/registry/ouro/components/ouro/field/field-parts\";\nimport { contractWarnings } from \"@/registry/ouro/components/ouro/field/field-styles\";\nimport {\n  PopoverClose,\n  PopoverPopupUnchecked,\n  PopoverPortal,\n  PopoverPositionerUnchecked,\n  PopoverRoot,\n  PopoverTitle,\n  PopoverTrigger,\n} from \"@/registry/ouro/components/ouro/popover/popover-parts\";\nimport { endSlotClass, groupClass, inputClass } from \"@/registry/ouro/components/ouro/text-field/text-field-styles\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { FieldOwnerContext, useFormErrors, type ReadonlyErrorMessages } from \"@/registry/ouro/lib/ouro/use-field\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { useMediaQuery } from \"@/registry/ouro/lib/ouro/use-media-query\";\n\n/** Props for {@link DatePicker}. */\nexport interface DatePickerProps {\n  /**\n   * What the date is for, shown above the field 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/calendar/date-picker.tsx verify:fileLine(registry/ouro/components/ouro/calendar/date-picker.test-d.ts, /expectTypeOf<\\{ name: \"date\" \\}>\\(\\)\\.not\\.toExtend<DatePickerProps>\\(\\)/)\n   */\n  label: string;\n  /** Hides the label visually; screen readers still read it as the field'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. The message (or several, as a\n   * list) shows under the field, which gets `aria-invalid`. A message is text or a React node (one with a link); an empty string or array means valid.\n   */\n  error?: ReadonlyErrorMessages | undefined;\n  /** A date must be given: the field gets `required` and `aria-required`, and the label a marker. */\n  required?: boolean | undefined;\n  /** Disables the field and its calendar button, and fades it. */\n  disabled?: boolean | undefined;\n  /** The form field name. The form submits the ISO date (`2026-10-11`) under it, or an empty string. */\n  name?: string | undefined;\n  /**\n   * The date as an ISO date (`\"2026-10-11\"`), or `\"\"` for none. Pass it with `onValueChange` to control the field.\n   *\n   * @claim \"The date as an ISO date\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > the phone's own picker > is a native date input holding the ISO value, with min and max)\n   * @claim \"The date as an ISO date\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > reads the locale's numbers or ISO, and writes the date the locale's way on blur)\n   */\n  value?: string | undefined;\n  /** The date at first, as an ISO date, when you do not control `value`. */\n  defaultValue?: string | undefined;\n  /**\n   * Called with the ISO date when the user picks or types an allowed date, and with `\"\"` when\n   * the field no longer holds one. A date before `min`, after `max` or named by\n   * `isDateDisabled`, typed or chosen in the phone's own picker, is not a value: it reports\n   * `\"\"`, and the field shows why and blocks the submit.\n   * @claim \"Called with the ISO date when\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > reads the locale's numbers or ISO, and writes the date the locale's way on blur)\n   * @claim \"Called with the ISO date when\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > marks what is not an allowed date invalid, with a translatable message, so the form does not submit it)\n   * @claim \"Called with the ISO date when\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > forms > submits a picked or typed date)\n   */\n  onValueChange?: ((value: string) => void) | undefined;\n  /** The earliest date allowed, as an ISO date. Earlier days are unavailable in the calendar, and a typed one is invalid. */\n  min?: string | undefined;\n  /** The latest date allowed, as an ISO date. Later days are unavailable in the calendar, and a typed one is invalid. */\n  max?: string | undefined;\n  /**\n   * Marks single days unavailable: `isDateDisabled={(date) => booked.has(date)}`. It gets each\n   * day as an ISO date. Such a day, typed or picked in the phone's own picker, is invalid.\n   * @claim \"It gets each day as an\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > the calendar popover > passes min, max and isDateDisabled to the calendar)\n   */\n  isDateDisabled?: ((date: string) => boolean) | undefined;\n  /**\n   * The BCP 47 locale for the calendar and the typed format: `\"en-GB\"` reads 11/10/2026 as\n   * 11 October and starts weeks on Monday. Pass your app's locale; the default is the same\n   * on the server and in the browser. Phones show their own picker in the phone's language.\n   * @default \"en-US\"\n   * @claim \"The BCP 47 locale for the\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > reads day-first in en-GB)\n   * @claim \"The BCP 47 locale for the\" registry/ouro/components/ouro/calendar/calendar.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/calendar.test.tsx::Calendar > locale > takes the first day of the week from the locale)\n   */\n  locale?: string | undefined;\n  /** An example of what to type, shown while the field is empty: `\"MM/DD/YYYY\"`. It is not a label. */\n  placeholder?: string | undefined;\n  /** The field shows its date but cannot be changed; its calendar button is disabled. */\n  readOnly?: boolean | undefined;\n  /**\n   * The name of the button that opens the calendar, as visually hidden text and not an\n   * `aria-label`, so a test's `getByLabel(\"Date\")` finds the text box alone. Translate it with your app.\n   * @default \"Choose date\"\n   */\n  chooseDateLabel?: string | undefined;\n  /**\n   * The calendar's previous month button's label. Translate it with your app.\n   * @default \"Previous month\"\n   */\n  previousMonthLabel?: string | undefined;\n  /**\n   * The calendar's next month button's label. Translate it with your app.\n   * @default \"Next month\"\n   */\n  nextMonthLabel?: string | undefined;\n  /**\n   * The label of the calendar's close button, which only screen readers and the keyboard\n   * reach. Translate it with your app.\n   * @default \"Close\"\n   */\n  closeLabel?: string | undefined;\n  /**\n   * The browser's message for typed text that is not a date, or a date `isDateDisabled` names. Translate it with your app.\n   * @default \"Enter a valid date.\"\n   */\n  invalidDateMessage?: string | undefined;\n  /**\n   * The browser's message for a typed date before `min` or after `max`. Translate it with your app.\n   * @default \"Enter a date in the allowed range.\"\n   */\n  outOfRangeMessage?: string | undefined;\n  /**\n   * Layout only: margins, width, grid placement (`mt-4`, `col-span-2`). Appearance classes\n   * warn in development; style fields in your theme.\n   */\n  className?: string | undefined;\n  /** The input element. */\n  ref?: Ref<HTMLInputElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `error`: `<DatePicker error=\"Required.\">`. */\n  errorMessage?: { 'Use <DatePicker error=\"Required.\">': never };\n  /** Not a prop. Ouro UI uses `description`: `<DatePicker description=\"...\">`. */\n  helperText?: { 'Use <DatePicker description=\"...\">': never };\n  /** Not a prop. `error` marks the field invalid: `<DatePicker error=\"What is wrong\">`. */\n  isInvalid?: { 'Use <DatePicker error=\"What is wrong\">': never };\n  /** Not a prop. `error` marks the field invalid: `<DatePicker error=\"What is wrong\">`. */\n  invalid?: { 'Use <DatePicker error=\"What is wrong\">': never };\n  /** Not a prop. Ouro UI uses `required`: `<DatePicker required>`. */\n  isRequired?: { 'Use <DatePicker required>': never };\n  /** Not a prop. Ouro UI uses `disabled`: `<DatePicker disabled>`. */\n  isDisabled?: { 'Use <DatePicker disabled>': never };\n  /** Not a prop. Ouro UI uses `onValueChange`, which gets the ISO date: `<DatePicker onValueChange={setDate}>`. */\n  onChange?: { 'Use onValueChange={setDate}; it gets the ISO date': never };\n  /** Not a prop. Ouro UI uses `value`: `<DatePicker value={date} onValueChange={setDate}>`. */\n  selected?: { 'Use value={date} onValueChange={setDate}': never };\n  /** Not a prop. Ouro UI uses `min`: `<DatePicker min=\"2026-10-11\">`. */\n  minDate?: { 'Use min=\"2026-10-11\"': never };\n  /** Not a prop. Ouro UI uses `max`: `<DatePicker max=\"2026-12-31\">`. */\n  maxDate?: { 'Use max=\"2026-12-31\"': never };\n  /** Not a prop. The locale sets the format: `<DatePicker locale=\"en-GB\">`. */\n  dateFormat?: { 'The locale sets it: locale=\"en-GB\"': never };\n  /** Not a prop. The locale sets the format: `<DatePicker locale=\"en-GB\">`. */\n  format?: { 'The locale sets it: locale=\"en-GB\"': never };\n}\n\n/** Field's messages and root name DatePicker. */\nconst owner = { name: \"DatePicker\", data: \"date-picker\" };\n\n/**\n * A labeled date field. With a mouse or trackpad it is a text box you can type the date into\n * (in the locale's numbers, or ISO; a two-digit year is the one within 50 years of today) with a button that opens a `Calendar` in a popover; on a\n * touch screen it is the phone's own date picker (`<input type=\"date\">`). Either way the\n * value is an ISO date (`\"2026-10-11\"`) and the form submits it under `name`, as a native\n * date input does.\n *\n * Use `Calendar` instead for a calendar always on the page or for a range of dates, and\n * `TextField type=\"time\"` for a time.\n *\n * @group Forms\n * @see https://ui.ouroboros.bot/docs/date-picker\n *\n * @example\n * <DatePicker label=\"Delivery date\" name=\"delivery\" min=\"2026-10-11\" required error={errors?.delivery} />\n * <DatePicker label=\"Birthday\" value={birthday} onValueChange={setBirthday} locale=\"en-GB\" />\n * @claim \"With a mouse or trackpad it\" registry/ouro/components/ouro/calendar/date-picker.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.test.tsx::DatePicker > typing > reads a two-digit year as the year within 50 years of today)\n * @claim \"With a mouse or trackpad it\" registry/ouro/components/ouro/calendar/date-picker.touch.test.tsx verify:testExists(registry/ouro/components/ouro/calendar/date-picker.touch.test.tsx::uses the phone's own date picker on a touch screen, submitting the ISO date)\n */\nexport function DatePicker(props: DatePickerProps): JSX.Element {\n  const {\n    label,\n    hideLabel,\n    description,\n    error,\n    required,\n    disabled,\n    name,\n    value,\n    defaultValue,\n    onValueChange,\n    min,\n    max,\n    isDateDisabled,\n    locale = \"en-US\",\n    placeholder,\n    readOnly,\n    chooseDateLabel = \"Choose date\",\n    previousMonthLabel,\n    nextMonthLabel,\n    closeLabel = \"Close\",\n    invalidDateMessage = \"Enter a valid date.\",\n    outOfRangeMessage = \"Enter a date in the allowed range.\",\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    errorMessage,\n    helperText,\n    isInvalid,\n    invalid,\n    isRequired,\n    isDisabled,\n    onChange,\n    selected,\n    minDate,\n    maxDate,\n    dateFormat,\n    format,\n  } = props;\n\n  useDevWarnings(\n    \"DatePicker\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          ...(\n            [\n              [\"value\", value],\n              [\"defaultValue\", defaultValue],\n              [\"min\", min],\n              [\"max\", max],\n            ] as const\n          ).map(([prop, given]) => given !== undefined && given !== \"\" && !isIsoDate(given) && isoWarning(\"DatePicker\", prop, given)),\n          ...contractWarnings(\"DatePicker\", { errorMessage, helperText, isInvalid, invalid, isRequired, isDisabled }),\n          onChange !== undefined && [\"onChange is not a prop; onValueChange gets the ISO date\", \"<DatePicker onValueChange={setDate}>\"],\n          selected !== undefined && [\"selected is not a prop\", \"<DatePicker value={date} onValueChange={setDate}>\"],\n          minDate !== undefined && [\"minDate is not a prop\", '<DatePicker min=\"2026-10-11\">'],\n          maxDate !== undefined && [\"maxDate is not a prop\", '<DatePicker max=\"2026-12-31\">'],\n          dateFormat !== undefined && [\"dateFormat is not a prop; the locale sets the format\", '<DatePicker locale=\"en-GB\">'],\n          format !== undefined && [\"format is not a prop; the locale sets the format\", '<DatePicker locale=\"en-GB\">'],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  // A touch screen gets the phone's own picker; the server renders the text box and calendar.\n  const touch = useMediaQuery(\"(pointer: coarse)\", false);\n\n  const low = isIsoDate(min) ? min : undefined;\n  const high = isIsoDate(max) ? max : undefined;\n  const inRange = (date: string) => !(low && date < low) && !(high && date > high);\n  /** The value a date stands for: itself when it is an allowed one, else `\"\"`. */\n  const allowedOrEmpty = (date: string | null) => (date !== null && date !== \"\" && inRange(date) && !isDateDisabled?.(date) ? date : \"\");\n  const defaultDate = isIsoDate(defaultValue) ? defaultValue : \"\";\n  // An invalid default remains visible as a draft, but is not a submitted date.\n  const [own, setOwn] = useState(() => allowedOrEmpty(defaultDate));\n  const controlled = value !== undefined;\n  const iso = controlled ? (isIsoDate(value) ? value : \"\") : own;\n  const currentIso = useRef(iso);\n  const formErrors = useFormErrors();\n  const report = (next: string) => {\n    if (name !== undefined) formErrors?.clear(name);\n    onValueChange?.(next);\n  };\n  const commit = (next: string) => {\n    if (next === currentIso.current) return;\n    if (!controlled) {\n      currentIso.current = next;\n      setOwn(next);\n    }\n    report(next);\n  };\n\n  /** The value a typed text stands for. */\n  const valueOf = (typedText: string) => allowedOrEmpty(parseDateInput(typedText, locale));\n\n  // What the phone's own picker shows: the date the user chose, which may not be an allowed one.\n  const initialDate = controlled ? iso : defaultDate;\n  const [chosen, setChosen] = useState(initialDate);\n  // What the text box shows. A new value from outside rewrites it, unless it already stands for that value.\n  const [text, setText] = useState(() => formatDateInput(initialDate, locale));\n  const [shown, setShown] = useState(`${iso} ${locale}`);\n  if (shown !== `${iso} ${locale}`) {\n    setShown(`${iso} ${locale}`);\n    if (valueOf(text) !== iso) setText(formatDateInput(iso, locale));\n    if (allowedOrEmpty(isIsoDate(chosen) ? chosen : null) !== iso) setChosen(iso);\n  }\n\n  // The browser blocks the submit with a message while the field holds what is not an\n  // allowed date.\n  const inputRef = useRef<HTMLInputElement>(null);\n  const typed = text.trim() === \"\" ? null : parseDateInput(text, locale);\n  // Both paths give the same messages; the native input checks its own format.\n  const problem = touch\n    ? isIsoDate(chosen) && (isDateDisabled?.(chosen) ? invalidDateMessage : !inRange(chosen) && outOfRangeMessage)\n    : text.trim() !== \"\" && (typed === null || isDateDisabled?.(typed) ? invalidDateMessage : !inRange(typed) && outOfRangeMessage);\n  const message = problem || \"\";\n  useEffect(() => {\n    inputRef.current!.setCustomValidity(message);\n  }, [message, touch]);\n\n  // What the field holds as a value: the picker's or the box's date when it is allowed. Typing\n  // and picking report it as they go; when the app changes min, max or isDateDisabled, a held\n  // date can become allowed (or stop being allowed), so report the change then too.\n  const held = touch ? allowedOrEmpty(isIsoDate(chosen) ? chosen : null) : valueOf(text);\n  const lastHeld = useRef(held);\n  useEffect(() => {\n    if (held === lastHeld.current) return;\n    lastHeld.current = held;\n    commit(held);\n  });\n\n  const backingRef = useRef<HTMLInputElement>(null);\n  const resetDate = controlled ? iso : defaultDate;\n  const resetIso = controlled ? iso : allowedOrEmpty(resetDate);\n  const restore = () => {\n    const changed = resetIso !== currentIso.current;\n    lastHeld.current = allowedOrEmpty(resetDate);\n    if (!controlled) {\n      currentIso.current = resetIso;\n      setOwn(resetIso);\n    }\n    setText(formatDateInput(resetDate, locale));\n    setChosen(resetDate);\n    if (!controlled && changed) report(resetIso);\n  };\n  const restoreRef = useRef(restore);\n  useLayoutEffect(() => {\n    currentIso.current = iso;\n    restoreRef.current = restore;\n    // Native reset needs defaults distinct from the current React-owned draft and ISO value.\n    if (backingRef.current) backingRef.current.value = iso;\n    inputRef.current!.defaultValue = touch ? resetDate : formatDateInput(resetDate, locale);\n  });\n  const lastReset = useRef<Event | undefined>(undefined);\n  useEffect(() => {\n    const input = inputRef.current;\n    const form = input?.form;\n    if (!form) return;\n    const reset = (event: Event) => {\n      lastReset.current = event;\n      queueMicrotask(() => {\n        if (lastReset.current !== event) return;\n        lastReset.current = undefined;\n        // Observe cancellation after propagation; a later edit or replacement wins over this reset.\n        const current = inputRef.current;\n        if (!event.defaultPrevented && event.target === form && current === input && current.value === current.defaultValue) restoreRef.current();\n      });\n    };\n    form.addEventListener(\"reset\", reset);\n    return () => form.removeEventListener(\"reset\", reset);\n  }, [touch]);\n\n  // A typed date outside min and max, or one isDateDisabled names, is not a value: the field\n  // reports `\"\"` and shows why, as the browser blocks the submit.\n  const onType = (event: ChangeEvent<HTMLInputElement>) => {\n    lastReset.current = undefined;\n    const next = event.currentTarget.value;\n    setText(next);\n    commit(valueOf(next));\n  };\n  // Leaving the box writes a typed date the locale's way: 10/11/26 becomes 10/11/2026.\n  const tidy = () => {\n    if (typed !== null) setText(formatDateInput(typed, locale));\n  };\n\n  const [open, setOpen] = useState(false);\n  const calendarRef = useRef<HTMLDivElement>(null);\n  const pick = (date: string) => {\n    lastReset.current = undefined;\n    commit(date);\n    setText(formatDateInput(date, locale));\n    setOpen(false);\n  };\n\n  // Pressing the box outside the input focuses the input, as TextField does; the button keeps its own focus.\n  const focusInput = (event: MouseEvent<HTMLDivElement>) => {\n    const target = event.target as HTMLElement;\n    if (target === inputRef.current || target.closest(\"button\")) return;\n    event.preventDefault();\n    inputRef.current!.focus();\n  };\n\n  const setRef = useMergedRef(ref, inputRef);\n\n  return (\n    <FieldOwnerContext.Provider value={owner}>\n      <Field\n        label={label}\n        hideLabel={hideLabel}\n        description={description}\n        error={error}\n        required={required}\n        disabled={disabled}\n        name={name}\n        className={className}\n      >\n        <div data-ouro-input-group=\"\" className={groupClass} onMouseDown={focusInput}>\n          {touch ? (\n            <FieldControl\n              ref={setRef}\n              type=\"date\"\n              value={chosen}\n              min={low}\n              max={high}\n              readOnly={readOnly}\n              onChange={(event) => {\n                lastReset.current = undefined;\n                const next = event.currentTarget.value;\n                setChosen(next);\n                commit(allowedOrEmpty(isIsoDate(next) ? next : null));\n              }}\n              render={(controlProps) => <input {...controlProps} name={undefined} data-ouro-control=\"date-picker\" data-ouro-part=\"input\" className={inputClass} />}\n            />\n          ) : (\n            <>\n              {/* The text box submits nothing; the hidden input submits the ISO date, as the native input does. */}\n              <FieldControl\n                ref={setRef}\n                type=\"text\"\n                value={text}\n                placeholder={placeholder}\n                readOnly={readOnly}\n                autoComplete=\"off\"\n                spellCheck={false}\n                onChange={onType}\n                onBlur={tidy}\n                render={(controlProps) => <input {...controlProps} name={undefined} data-ouro-control=\"date-picker\" data-ouro-part=\"input\" className={inputClass} />}\n              />\n              <span className={endSlotClass}>\n                <PopoverRoot open={open} onOpenChange={setOpen}>\n                  <PopoverTrigger\n                    render={\n                      <Button\n                        variant=\"plain\"\n                        tone=\"secondary\"\n                        size=\"sm\"\n                        data-ouro-choose-date=\"\"\n                        data-ouro-control=\"date-picker\"\n                        data-ouro-part=\"trigger\"\n                        disabled={disabled || readOnly}\n                        className=\"aspect-square px-0\"\n                      >\n                        <svg\n                          aria-hidden=\"true\"\n                          viewBox=\"0 0 16 16\"\n                          fill=\"none\"\n                          stroke=\"currentColor\"\n                          strokeWidth=\"1.5\"\n                          strokeLinecap=\"round\"\n                          strokeLinejoin=\"round\"\n                          className=\"size-4\"\n                        >\n                          <rect x=\"2.5\" y=\"3.5\" width=\"11\" height=\"10\" rx=\"1.5\" />\n                          <path d=\"M2.5 6.5h11M5.5 2v3M10.5 2v3\" />\n                        </svg>\n                        {/* Named by hidden text, not `aria-label`, which is label text: a label\n                            lookup for a field called \"Date\" would also find \"Choose date\". */}\n                        <span className=\"sr-only\">{chooseDateLabel}</span>\n                      </Button>\n                    }\n                  />\n                  <PopoverPortal>\n                    <PopoverPositionerUnchecked side=\"bottom\" align=\"end\">\n                      <PopoverPopupUnchecked\n                        className=\"w-auto\"\n                        initialFocus={() => calendarRef.current!.querySelector<HTMLElement>('[data-ouro-day][tabindex=\"0\"]')}\n                      >\n                        <PopoverTitle visuallyHidden>{label}</PopoverTitle>\n                        <Calendar\n                          ref={calendarRef}\n                          label={label}\n                          value={iso}\n                          onValueChange={pick}\n                          min={low}\n                          max={high}\n                          isDateDisabled={isDateDisabled}\n                          locale={locale}\n                          previousMonthLabel={previousMonthLabel}\n                          nextMonthLabel={nextMonthLabel}\n                        />\n                        <PopoverClose data-ouro-popover-close=\"\">{closeLabel}</PopoverClose>\n                      </PopoverPopupUnchecked>\n                    </PopoverPositionerUnchecked>\n                  </PopoverPortal>\n                </PopoverRoot>\n              </span>\n            </>\n          )}\n          {name !== undefined && <input ref={backingRef} type=\"text\" hidden readOnly data-ouro-control=\"date-picker\" data-ouro-part=\"hidden-input\" name={name} defaultValue={resetIso} disabled={disabled} />}\n        </div>\n      </Field>\n    </FieldOwnerContext.Provider>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/calendar/date-picker.tsx"
    }
  ],
  "docs": "A labeled date field. Import: import { DatePicker } from \"@/components/ouro/calendar/date-picker\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, calendar, field, popover, sheet, text-field, the helpers they import 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/date-picker.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}