{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker",
  "title": "Date picker",
  "description": "Single-date calendar and picker on react-day-picker, sharing the range calendar's look, wording and bounds; the chosen day floods ink. DateTimePicker adds a time row (a TimeField cell, 24- or 12-hour, with optional minTime/maxTime) under the calendar.",
  "dependencies": [
    "@base-ui/react@1.9.0",
    "react-day-picker@9.14.0"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/keyline-scope",
    "@keyline-ui/keyline-render",
    "@keyline-ui/calendar",
    "@keyline-ui/date-range",
    "@keyline-ui/field",
    "@keyline-ui/time-field"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/date-picker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Popover } from \"@base-ui/react/popover\";\nimport { Field as FieldPrimitive } from \"@base-ui/react/field\";\nimport { RadioGroup } from \"@base-ui/react/radio-group\";\nimport { Radio } from \"@base-ui/react/radio\";\nimport { DayPicker } from \"react-day-picker\";\n\nimport { cn } from \"@/lib/utils\";\nimport { dockGeometry, scopeProps, useKeylineScope } from \"../lib/keyline-scope\";\nimport { resolveClassName, resolveStyle, type PartProps } from \"../lib/keyline-render\";\nimport { sameDay, sod, type Unavailable } from \"../lib/calendar\";\nimport {\n  CalendarGlyph,\n  calendarStyles,\n  gridDay,\n  pickerStyles,\n  useDayPicker,\n  usePart,\n  useRefs,\n  type Bounds,\n  type EmptyState,\n} from \"./date-range\";\nimport { FieldMessages, useDescribedByMirror, type FieldParticipantProps } from \"./field\";\nimport { TimeField, timeOutside } from \"./time-field\";\n\ntype CalendarProps = Bounds & {\n  value: Date | null;\n  onValueChange: (d: Date) => void;\n  isDateUnavailable?: Unavailable;\n  today?: Date;\n  defaultMonth?: Date;\n  weekStartsOn?: number;\n  locale?: string;\n  className?: string;\n  /** Escape inside the grid (lets a popover close). */\n  onEscape?: () => void;\n};\n\n/**\n * Single-date calendar on react-day-picker, with RangeCalendar's look, locale wording and bounds. The\n * chosen day is the current choice among exclusive options, so it floods INK; today is underlined;\n * unavailable days are hatched, disabled and skipped by the arrow keys.\n */\nfunction Calendar({\n  value,\n  onValueChange,\n  isDateUnavailable,\n  today = sod(new Date()),\n  defaultMonth,\n  weekStartsOn = 1,\n  locale = \"en-GB\",\n  min,\n  max,\n  className,\n  onEscape,\n}: CalendarProps) {\n  const startMonth = sod(defaultMonth ?? value ?? today);\n  const { wrap, props } = useDayPicker({\n    locale,\n    weekStartsOn,\n    today,\n    min,\n    max,\n    isDateUnavailable,\n    anchorMonth: startMonth,\n    label: () => \"\",\n  });\n  return (\n    <div ref={wrap} data-slot=\"calendar\" className={cn(calendarStyles.root, className)}>\n      <DayPicker\n        {...props}\n        mode=\"single\"\n        required\n        selected={value ?? undefined}\n        onSelect={(d) => d && onValueChange(d)}\n        defaultMonth={startMonth}\n        modifiers={{ kl_ink: () => true, kl_on: (d: Date) => sameDay(d, value) }}\n        onDayKeyDown={(_, __, e) => {\n          if (e.key !== \"Escape\" || !onEscape) return;\n          e.preventDefault();\n          e.stopPropagation();\n          onEscape();\n        }}\n      />\n    </div>\n  );\n}\n\n/* ------------------------------------------------------------------ parts */\n\ntype Layout = \"control\" | \"cell\";\n\n/** Base UI's Popover.Root: open state and its event details pass through untouched. */\nconst DatePickerRoot = Popover.Root;\n\n/** The trigger: a field frame of cells (pass the affix and the value; a Field's ! cell first). `layout=\"cell\"`: a\n * cell of an enclosing frame. The look is DateRangePicker's (`pickerStyles`). */\nfunction DatePickerTrigger({\n  layout = \"control\",\n  className,\n  ...props\n}: Popover.Trigger.Props & { layout?: Layout }): React.ReactElement {\n  return (\n    <Popover.Trigger\n      data-kl-layout={layout}\n      className={resolveClassName(pickerStyles.trigger, className)}\n      {...props}\n      data-slot=\"date-picker-trigger\"\n    />\n  );\n}\n\n/** The calendar glyph's cell at the trigger's start (hidden from assistive tech). Children replace the glyph. */\nfunction DatePickerAffix({ children, ...props }: PartProps<\"span\", EmptyState>): React.ReactElement {\n  return usePart(\"span\", \"date-picker-affix\", pickerStyles.affix, props, {\n    \"aria-hidden\": true,\n    children: children ?? <CalendarGlyph />,\n  });\n}\n\n/** The value cell: the chosen day, or the placeholder. */\nfunction DatePickerValue({\n  placeholder,\n  children,\n  ...props\n}: PartProps<\"span\", EmptyState> & {\n  /** Shown, in the placeholder's ink, while there are no children. */\n  placeholder?: React.ReactNode;\n}): React.ReactElement {\n  return usePart(\"span\", \"date-picker-value\", pickerStyles.value, props, {\n    children:\n      children ??\n      (placeholder != null ? (\n        <span data-slot=\"date-picker-placeholder\" className={pickerStyles.placeholder}>\n          {placeholder}\n        </span>\n      ) : null),\n  });\n}\n\ntype PopupProps = Popover.Popup.Props &\n  Pick<Popover.Positioner.Props, \"anchor\" | \"side\" | \"align\" | \"sideOffset\" | \"alignOffset\" | \"collisionPadding\"> & {\n    /** The frame the popup docks to: `cell` when the trigger has `layout=\"cell\"`. */\n    layout?: Layout;\n    /** Where the portal renders (defaults to <body>). */\n    container?: Popover.Portal.Props[\"container\"];\n    /** Props for Base UI's Popover.Portal. */\n    portalProps?: Omit<Popover.Portal.Props, \"container\" | \"children\">;\n  };\n\n/**\n * The calendar's surface: Base UI's Portal, Positioner and Popup in one part, with the positioner's placement props\n * lifted. It docks to the trigger (seven days wide, or the trigger's width when the two are within --kl-snap) and\n * carries the configuration (density, motion, theme, dir) of the place it is written. Focus lands on the grid's day.\n */\nfunction DatePickerPopup({\n  layout = \"control\",\n  anchor,\n  side,\n  align = \"start\",\n  sideOffset,\n  alignOffset,\n  collisionPadding = 12,\n  container,\n  portalProps,\n  className,\n  style,\n  initialFocus,\n  ref,\n  ...props\n}: PopupProps): React.ReactElement {\n  const dock = dockGeometry(layout);\n  const [marker, scope, probe] = useKeylineScope(false, container);\n  const own = React.useRef<HTMLDivElement>(null);\n  const refs = useRefs(own, ref);\n  return (\n    <>\n      {marker}\n      <Popover.Portal container={container} {...portalProps}>\n        {probe}\n        <Popover.Positioner\n          anchor={anchor}\n          side={side}\n          align={align}\n          sideOffset={sideOffset ?? dock.sideOffset}\n          alignOffset={alignOffset ?? dock.alignOffset}\n          collisionPadding={collisionPadding}\n          {...scopeProps(scope, { className: \"kl-positioner\" })}\n        >\n          <Popover.Popup\n            ref={refs}\n            className={resolveClassName(pickerStyles.popup, className)}\n            style={resolveStyle(dock.style, style)}\n            initialFocus={initialFocus ?? (() => gridDay(own.current))}\n            {...props}\n            data-slot=\"date-picker-popup\"\n          />\n        </Popover.Positioner>\n      </Popover.Portal>\n    </>\n  );\n}\n\n/** A row of quick choices under the calendar. */\nfunction DatePickerPresets(props: PartProps<\"div\", EmptyState>): React.ReactElement {\n  return usePart(\"div\", \"date-picker-presets\", pickerStyles.presets, props);\n}\n\n/** One quick choice: a key cell (its label travels under a press). */\nfunction DatePickerPreset({ children, ...props }: PartProps<\"button\", EmptyState>): React.ReactElement {\n  return usePart(\n    \"button\",\n    \"date-picker-preset\",\n    pickerStyles.preset,\n    { type: \"button\", ...props },\n    {\n      children: <span>{children}</span>,\n    },\n  );\n}\n\n/** Closes the popup (DateTimePicker's Done): a key cell at the end of a row. */\nfunction DatePickerClose({ className, children, ...props }: Popover.Close.Props): React.ReactElement {\n  return (\n    <Popover.Close\n      className={resolveClassName(\n        \"kl-cell kl-key flex-none justify-center px-(--kl-inset) text-[13px] font-(--kl-weight-strong)\",\n        className,\n      )}\n      {...props}\n      data-slot=\"date-picker-close\"\n    >\n      <span>{children}</span>\n    </Popover.Close>\n  );\n}\n\n/* ------------------------------------------------------------------ the fields */\n\ntype DatePickerProps = Omit<CalendarProps, \"onEscape\" | \"value\" | \"onValueChange\"> & {\n  /** The chosen day. Controlled with `value` + `onValueChange`, or uncontrolled from `defaultValue`. */\n  value?: Date | null;\n  defaultValue?: Date | null;\n  onValueChange?: (d: Date) => void;\n  label: React.ReactNode;\n  placeholder?: React.ReactNode;\n  /** Quick choices shown as a row of cells under the calendar (\"Today\", \"Next Monday\"). */\n  presets?: { label: string; date: () => Date }[];\n  /** control: its own 2px frame. cell: a cell of an enclosing frame; the label is visually hidden. */\n  layout?: Layout;\n  /** Submitted with a form, as YYYY-MM-DD. */\n  name?: string;\n  container?: Popover.Portal.Props[\"container\"];\n};\n\nconst iso = (d: Date) =>\n  `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, \"0\")}-${String(d.getDate()).padStart(2, \"0\")}`;\n\n/** Trigger field (calendar affix · formatted date) + the calendar docked to the field frame, built from the parts. */\nfunction DatePicker({\n  label,\n  value: valueProp,\n  defaultValue = null,\n  onValueChange: onChange,\n  placeholder = \"Choose a date\",\n  presets = [],\n  layout = \"control\",\n  name,\n  container,\n  className,\n  ...cal\n}: DatePickerProps) {\n  const [inner, setInner] = React.useState<Date | null>(defaultValue);\n  const value = valueProp !== undefined ? valueProp : inner;\n  const onValueChange = (d: Date) => {\n    if (valueProp === undefined) setInner(d);\n    onChange?.(d);\n  };\n  const [open, setOpen] = React.useState(false);\n  const id = React.useId();\n  const fmt = new Intl.DateTimeFormat(cal.locale ?? \"en-GB\", {\n    weekday: \"short\",\n    day: \"numeric\",\n    month: \"short\",\n    year: \"numeric\",\n  });\n  const pick = (d: Date) => {\n    onValueChange(d);\n    setOpen(false);\n  };\n  return (\n    <DatePickerRoot open={open} onOpenChange={setOpen}>\n      <div data-slot=\"date-picker\" data-kl-layout={layout} className={cn(\"kl-field\", className)}>\n        <span className={cn(\"kl-field-label\", layout === \"cell\" && \"kl-sr\")} id={id}>\n          {label}\n        </span>\n        <DatePickerTrigger aria-labelledby={`${id} ${id}v`} layout={layout}>\n          <DatePickerAffix />\n          <DatePickerValue id={`${id}v`} placeholder={placeholder}>\n            {value ? fmt.format(value) : null}\n          </DatePickerValue>\n        </DatePickerTrigger>\n        {name ? <input type=\"hidden\" name={name} value={value ? iso(value) : \"\"} /> : null}\n        <DatePickerPopup layout={layout} container={container} aria-labelledby={id}>\n          <Calendar value={value} onValueChange={pick} onEscape={() => setOpen(false)} {...cal} />\n          {presets.length ? (\n            <DatePickerPresets>\n              {presets.map((p) => (\n                <DatePickerPreset key={p.label} onClick={() => pick(p.date())}>\n                  {p.label}\n                </DatePickerPreset>\n              ))}\n            </DatePickerPresets>\n          ) : null}\n        </DatePickerPopup>\n      </div>\n    </DatePickerRoot>\n  );\n}\n\ntype DateTimePickerProps = Omit<CalendarProps, \"onEscape\" | \"value\" | \"onValueChange\"> &\n  FieldParticipantProps & {\n    label: React.ReactNode;\n    /** The chosen moment (local time). Controlled with `value` + `onValueChange`, or uncontrolled from `defaultValue`. */\n    value?: Date | null;\n    defaultValue?: Date | null;\n    /** Called on every complete change (a day, a time, a preset), and with null when cleared. */\n    onValueChange?: (d: Date | null) => void;\n    placeholder?: React.ReactNode;\n    /** Quick choices under the calendar. A preset whose time is midnight keeps the chosen time; any other time is used as given. */\n    presets?: { label: string; date: () => Date }[];\n    /** 24 (default) or 12 with a day-period part; also how the trigger prints the time. */\n    hourCycle?: 12 | 24;\n    minuteStep?: number;\n    /** Time given to a day chosen before any time (default \"09:00\", or `minTime` when that is later). */\n    defaultTime?: string;\n    /** Earliest and latest time of day (\"HH:MM\", 24-hour), on every day. The time cell's arrows stay inside;\n     *  a typed time outside is invalid (on the time cell and the field) with `rangeMessage`. */\n    minTime?: string;\n    maxTime?: string;\n    rangeMessage?: string;\n    /** Offered times (\"HH:MM\", 24-hour), the same every day or per day. Given, the time row becomes a list\n     *  of slots to choose from (a radio group) instead of the typed time cell. */\n    slots?: string[] | ((day: Date) => string[]);\n    /** A booked or closed time on a day: true, or a short reason (\"booked\"). With `slots`, the slot is\n     *  hatched, disabled and skipped by the arrows, its name ends \"unavailable (reason)\", and a day with\n     *  no slot left is unavailable in the calendar (\"fully booked\"). Without `slots`, a typed time it\n     *  returns true for is invalid with `unavailableMessage`. */\n    isTimeUnavailable?: (day: Date, time: string) => string | boolean | undefined;\n    unavailableMessage?: string;\n    /** Zone affix printed in the time cell and the trigger (\"CET\"). Values are local times; this is a label. */\n    zone?: React.ReactNode;\n    timeLabel?: string;\n    doneLabel?: string;\n    layout?: Layout;\n    /** Submitted with a form as local \"YYYY-MM-DDTHH:MM\" (or \"\" when empty). */\n    name?: string;\n    required?: boolean;\n    disabled?: boolean;\n    container?: Popover.Portal.Props[\"container\"];\n  };\n\nconst hhmm = (d: Date) => `${String(d.getHours()).padStart(2, \"0\")}:${String(d.getMinutes()).padStart(2, \"0\")}`;\nconst withTime = (d: Date, t: string) => {\n  const [h, m] = t.split(\":\").map(Number);\n  return new Date(d.getFullYear(), d.getMonth(), d.getDate(), h, m);\n};\n\n/**\n * A day and a time of day in one field: the DatePicker's trigger and docked calendar, with a time row\n * (TimeField as a cell, and Done) under the calendar.\n *\n *   Pickup\n *   ┌────┬───────────────────────────────┐\n *   │ ▦  │ Thu 12 Nov 2026, 14:30 CET     │   trigger: affix · date and time\n *   ├────┴───────────────────────────────┤\n *   │ calendar …                         │\n *   ├──────┬─────────────────────┬───────┤\n *   │ Time │ 14 : 30  CET         │ Done  │   time row\n *   └──────┴─────────────────────┴───────┘\n *\n * - Choosing a day keeps the popup open (the time is still to set) and keeps the time already chosen\n *   (or `defaultTime`). Changes apply as they are made; Done, Escape or a press outside closes, and focus\n *   returns to the trigger.\n * - Keyboard: the calendar's grid keys; Tab moves grid → presets → hours → minutes (→ period) → Done.\n *   Delete or Backspace on the closed trigger clears the value (unless `required`).\n * - A time typed before any day is held and given to the day chosen next. A part cleared while editing\n *   leaves the last complete time in place.\n * - Field: Base UI Field.Root; `name` submits local \"YYYY-MM-DDTHH:MM\"; `required` (\"Choose a date and\n *   time.\"), `validate`, `invalid`, `error` and the Form's server errors show under the frame, with the\n *   ! cell in the trigger.\n */\nfunction DateTimePicker({\n  label,\n  value: valueProp,\n  defaultValue = null,\n  onValueChange,\n  placeholder = \"Choose a date and time\",\n  presets = [],\n  hourCycle = 24,\n  minuteStep,\n  defaultTime: defaultTimeProp = \"09:00\",\n  minTime,\n  maxTime,\n  rangeMessage,\n  slots,\n  isTimeUnavailable,\n  unavailableMessage,\n  zone,\n  timeLabel = \"Time\",\n  doneLabel = \"Done\",\n  layout = \"control\",\n  name,\n  required,\n  disabled,\n  container,\n  className,\n  invalid,\n  error,\n  description,\n  validate,\n  validationMode,\n  orientation,\n  ...cal\n}: DateTimePickerProps) {\n  const [inner, setInner] = React.useState<Date | null>(defaultValue);\n  const value = valueProp !== undefined ? valueProp : inner;\n  const set = (d: Date | null) => {\n    if (valueProp === undefined) setInner(d);\n    onValueChange?.(d);\n  };\n  const [heldTime, setHeldTime] = React.useState<string | null>(null);\n  const time = value ? hhmm(value) : heldTime;\n  const defaultTime =\n    minTime && defaultTimeProp < minTime ? minTime : maxTime && defaultTimeProp > maxTime ? maxTime : defaultTimeProp;\n  const [open, setOpen] = React.useState(false);\n  const id = React.useId();\n  // the trigger is what focus lands on, so it carries the description and error\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  useDescribedByMirror(rootRef, '[data-slot=\"date-picker-trigger\"]');\n  const locale = cal.locale ?? \"en-GB\";\n  // date and time formatted apart and joined with a comma: engines join them differently (\"at\" in WebKit)\n  const fmtDay = new Intl.DateTimeFormat(locale, { weekday: \"short\", day: \"numeric\", month: \"short\", year: \"numeric\" });\n  const fmtTime = new Intl.DateTimeFormat(locale, {\n    hour: \"2-digit\",\n    minute: \"2-digit\",\n    hourCycle: hourCycle === 12 ? \"h12\" : \"h23\",\n  });\n  const showT = (t: string) => fmtTime.format(withTime(new Date(2020, 0, 1), t));\n  const fmt = { format: (d: Date) => `${fmtDay.format(d)}, ${fmtTime.format(d)}` };\n  const slotsFor = (d: Date) =>\n    (typeof slots === \"function\" ? slots(d) : (slots ?? [])).filter((t) => !timeOutside(t, minTime, maxTime));\n  const why = (d: Date, t: string) => isTimeUnavailable?.(d, t);\n  // with slots, a day is chosen first and held until one of its free slots is (value stays as it was);\n  // the held day is dropped when the popup closes without one\n  const [heldDay, setHeldDay] = React.useState<Date | null>(null);\n  const day = heldDay ?? value;\n  const show = (o: boolean) => {\n    setOpen(o);\n    if (!o) setHeldDay(null);\n  };\n  const pickDay = (d: Date) => {\n    if (!slots) return set(withTime(d, time ?? defaultTime));\n    if (time && slotsFor(d).includes(time) && !why(d, time)) {\n      setHeldDay(null);\n      set(withTime(d, time));\n    } else setHeldDay(d);\n  };\n  const pickSlot = (t: string) => {\n    if (!day) return;\n    setHeldDay(null);\n    set(withTime(day, t));\n  };\n  const isDateUnavailable = slots\n    ? (d: Date) =>\n        cal.isDateUnavailable?.(d) ||\n        (slotsFor(d).every((t) => why(d, t)) ? (slotsFor(d).length ? \"fully booked\" : \"no times\") : false)\n    : cal.isDateUnavailable;\n  const pickPreset = (d: Date) => set(d.getHours() || d.getMinutes() ? d : withTime(d, time ?? defaultTime));\n  const pickTime = (t: string | null) => {\n    if (t == null) return;\n    if (value) set(withTime(value, t));\n    else setHeldTime(t);\n  };\n  const local = value ? `${iso(value)}T${hhmm(value)}` : \"\";\n  const check = React.useCallback(\n    (v: unknown, all: Record<string, unknown>) => {\n      if (required && !v) return \"Choose a date and time.\";\n      if (typeof v === \"string\" && v && timeOutside(v.slice(11), minTime, maxTime))\n        return rangeMessage ?? `Choose a time from ${showT(minTime ?? \"00:00\")} to ${showT(maxTime ?? \"23:59\")}.`;\n      if (typeof v === \"string\" && v && isTimeUnavailable) {\n        const r = isTimeUnavailable(new Date(+v.slice(0, 4), +v.slice(5, 7) - 1, +v.slice(8, 10)), v.slice(11));\n        if (r)\n          return (\n            unavailableMessage ??\n            `${showT(v.slice(11))} is ${typeof r === \"string\" ? r : \"unavailable\"}. Choose another time.`\n          );\n      }\n      return validate ? validate(v, all) : null;\n    },\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [required, validate, minTime, maxTime, rangeMessage, isTimeUnavailable, unavailableMessage, hourCycle, locale],\n  );\n  return (\n    <FieldPrimitive.Root\n      ref={rootRef}\n      data-slot=\"date-time-picker\"\n      data-kl-layout={layout}\n      data-kl-orientation={orientation}\n      name={name}\n      disabled={disabled}\n      invalid={invalid}\n      validate={check}\n      validationMode={validationMode}\n      className={cn(\"kl-field\", className)}\n    >\n      <DatePickerRoot open={open} onOpenChange={show}>\n        <span className={cn(\"kl-field-label\", layout === \"cell\" && \"kl-sr\")} id={id}>\n          {label}\n        </span>\n        {/* Field.Validity carries the field's combined state (the invalid prop, Form errors, validate and the\n            built-in range/unavailable checks), so the trigger is marked invalid whenever the message shows */}\n        <FieldPrimitive.Validity>\n          {(fv) => (\n            <DatePickerTrigger\n              aria-labelledby={`${id} ${id}v`}\n              aria-invalid={invalid || fv.validity.valid === false || undefined}\n              aria-required={required || undefined}\n              disabled={disabled}\n              layout={layout}\n              onKeyDown={(e) => {\n                if ((e.key === \"Delete\" || e.key === \"Backspace\") && value && !required && !open) {\n                  e.preventDefault();\n                  set(null);\n                }\n              }}\n            >\n              <span className=\"kl-slot kl-field-bang\" aria-hidden>\n                <span>\n                  <span>!</span>\n                </span>\n              </span>\n              <DatePickerAffix />\n              {/* a long value (a narrow cell, a long locale format) ends in an ellipsis; the trigger's name reads it\n                  whole. The gap is the cell's, not a margin on the zone: a <bdi> takes its own direction (LTR for\n                  \"CET\"), so its logical margin would land on the far side in RTL */}\n              <DatePickerValue id={`${id}v`} placeholder={placeholder} className=\"min-w-0 gap-2\">\n                {value ? (\n                  <>\n                    <span data-slot=\"date-time-picker-text\" className=\"min-w-0 truncate\">\n                      {fmt.format(value)}\n                    </span>\n                    {zone != null ? (\n                      <>\n                        {\" \"}\n                        <bdi data-slot=\"date-time-picker-zone\" className=\"kl-code\">\n                          {zone}\n                        </bdi>\n                      </>\n                    ) : null}\n                  </>\n                ) : null}\n              </DatePickerValue>\n            </DatePickerTrigger>\n          )}\n        </FieldPrimitive.Validity>\n        <FieldPrimitive.Control type=\"hidden\" value={local} onValueChange={() => {}} />\n        <FieldMessages description={description} error={error} invalid={invalid} layout={layout} />\n        <DatePickerPopup layout={layout} container={container} aria-labelledby={id}>\n          <Calendar\n            value={day}\n            onValueChange={pickDay}\n            onEscape={() => show(false)}\n            {...cal}\n            isDateUnavailable={isDateUnavailable}\n          />\n          {presets.length ? (\n            <DatePickerPresets>\n              {presets.map((p) => (\n                <DatePickerPreset key={p.label} onClick={() => pickPreset(p.date())}>\n                  {p.label}\n                </DatePickerPreset>\n              ))}\n            </DatePickerPresets>\n          ) : null}\n          {slots ? (\n            <Slots\n              day={day}\n              times={day ? slotsFor(day) : []}\n              why={why}\n              value={day && !heldDay && value ? hhmm(value) : null}\n              onPick={pickSlot}\n              show={showT}\n              label={day ? `${timeLabel}, ${fmtDay.format(day)}` : timeLabel}\n            />\n          ) : null}\n          {/* the time row: one run of cells, a label cell, the TimeField as a cell (it hugs its parts, so the\n                  row's spare room stays after it) and Done. Compact: seven 34px days leave no room for the label\n                  cell; the time cell is still named */}\n          <div\n            data-slot=\"date-time-picker-time\"\n            className=\"kl-cells min-h-(--kl-row) border-t-(length:--kl-k1) border-t-kl-seam *:data-[slot=time-field]:min-w-0\"\n          >\n            <span\n              data-slot=\"date-time-picker-time-label\"\n              className=\"kl-cell flex-none text-[13px] font-(--kl-weight-strong) text-kl-ink-2 in-data-[kl-density=compact]:hidden\"\n              aria-hidden\n            >\n              {timeLabel}\n            </span>\n            {slots ? (\n              <span\n                data-slot=\"date-time-picker-slot-status\"\n                className=\"kl-cell flex-auto text-[15px] font-(--kl-weight-strong) whitespace-nowrap\"\n                aria-live=\"polite\"\n              >\n                {!day ? \"Choose a day\" : heldDay || !value ? \"Choose a time\" : fmtTime.format(value)}\n                {zone != null && day && !heldDay && value ? (\n                  <bdi data-slot=\"date-time-picker-zone\" className=\"kl-code\">\n                    {zone}\n                  </bdi>\n                ) : null}\n              </span>\n            ) : (\n              <TimeField\n                layout=\"cell\"\n                label={timeLabel}\n                value={time}\n                onValueChange={pickTime}\n                hourCycle={hourCycle}\n                minuteStep={minuteStep}\n                locale={cal.locale}\n                zone={zone}\n                min={minTime}\n                max={maxTime}\n                rangeMessage={rangeMessage}\n              />\n            )}\n            <DatePickerClose>{doneLabel}</DatePickerClose>\n          </div>\n        </DatePickerPopup>\n      </DatePickerRoot>\n    </FieldPrimitive.Root>\n  );\n}\n\n/** The slots' grid: cells on the calendar's seams, four rows tall whatever the day offers, scrolling past that. */\nconst slotsGrid = cn(\n  \"grid h-[calc(4*var(--kl-day))] grid-cols-[repeat(auto-fill,minmax(max(4.5em,calc(25%-var(--kl-k1))),1fr))]\",\n  \"[align-content:start] gap-(--kl-k1) overflow-y-auto overscroll-contain border-t-(length:--kl-k1) border-t-kl-seam\",\n  \"[scrollbar-width:thin]\",\n);\n\n/**\n * The day's offered times as one radio group of cells (Base UI RadioGroup): arrows move and choose,\n * skipping unavailable slots; the chosen slot floods INK like the chosen day. Four rows tall, scrolling\n * past that.\n */\nfunction Slots({\n  day,\n  times,\n  why,\n  value,\n  onPick,\n  show,\n  label,\n}: {\n  day: Date | null;\n  times: string[];\n  why: (d: Date, t: string) => string | boolean | undefined;\n  value: string | null;\n  onPick: (t: string) => void;\n  show: (t: string) => string;\n  label: string;\n}) {\n  // one fixed height whatever the day offers, so choosing a day never resizes (or flips) the popup\n  if (!day || !times.length)\n    return (\n      <p\n        data-slot=\"date-time-picker-slots\"\n        className={cn(slotsGrid, \"m-0 place-items-center px-(--kl-inset) text-center text-[13px] text-kl-ink-2\")}\n      >\n        {day ? \"No times on this day.\" : \"Choose a day to see its times.\"}\n      </p>\n    );\n  return (\n    <RadioGroup\n      aria-label={label}\n      value={value}\n      onValueChange={(t) => onPick(t as string)}\n      data-slot=\"date-time-picker-slots\"\n      className={slotsGrid}\n    >\n      {times.map((t) => {\n        const r = why(day, t);\n        return (\n          <Radio.Root\n            key={t}\n            value={t}\n            disabled={!!r}\n            aria-label={r ? `${show(t)}, unavailable${typeof r === \"string\" ? ` (${r})` : \"\"}` : show(t)}\n            data-slot=\"date-time-picker-slot\"\n            className={cn(\n              calendarStyles.day,\n              // each slot draws the seams on its end and foot into the grid gap, so a short last row ends cleanly\n              \"[box-shadow:var(--kl-k1)_var(--kl-k1)_0_0_var(--kl-line-soft)]\",\n              \"kl-rtl:[box-shadow:calc(-1*var(--kl-k1))_var(--kl-k1)_0_0_var(--kl-line-soft)]\",\n              \"font-(family-name:--kl-font-mono) text-[13px] tabular-nums\",\n              !r && \"kl-sig-ink\",\n            )}\n            data-kl-flood=\"manual\"\n            data-kl-on={value === t ? \"\" : undefined}\n            data-unavailable={r ? \"\" : undefined}\n          >\n            <span className={calendarStyles.dayLabel}>{show(t)}</span>\n          </Radio.Root>\n        );\n      })}\n    </RadioGroup>\n  );\n}\n\nexport {\n  Calendar,\n  DatePicker,\n  DateTimePicker,\n  DatePickerRoot,\n  DatePickerTrigger,\n  DatePickerAffix,\n  DatePickerValue,\n  DatePickerPopup,\n  DatePickerPresets,\n  DatePickerPreset,\n  DatePickerClose,\n  type CalendarProps,\n  type DatePickerProps,\n  type DateTimePickerProps,\n};\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/date-picker.tsx"
    }
  ],
  "type": "registry:ui"
}