{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker",
  "title": "Date picker",
  "description": "Picks one date from a single-month calendar in a popover, with full keyboard navigation and no date library.",
  "dependencies": [
    "lucide-react",
    "radix-ui"
  ],
  "registryDependencies": [
    "https://www.gliakit.com/r/tokens.json",
    "https://www.gliakit.com/r/input.json"
  ],
  "files": [
    {
      "path": "src/components/ui/date-picker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Popover } from \"radix-ui\";\nimport { Calendar as CalendarIcon, ChevronLeft, ChevronRight } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useField, useFieldControl } from \"@/components/ui/input\";\n\nconst WEEKDAYS = [\"S\", \"M\", \"T\", \"W\", \"T\", \"F\", \"S\"];\nconst WEEKDAY_NAMES = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"];\nconst sameDay = (a?: Date, b?: Date) =>\n  !!a && !!b && a.toDateString() === b.toDateString();\nconst fullDate = (d: Date) => d.toLocaleDateString(\"en-US\", { weekday: \"long\", month: \"long\", day: \"numeric\", year: \"numeric\" });\n\n/**\n * Weekday header + day cells for one month. Shared by Calendar and\n * DateRangePicker; `dayClassName` decides how each day looks and\n * `isSelected` what a screen reader hears (pressed). Each day reads as its\n * full date, today is marked, and the arrows move by day (left, right) and\n * week (up, down), Home and End to the month's ends; Tab leaves the grid in\n * one step.\n */\nfunction MonthGrid({\n  year,\n  month,\n  dayClassName,\n  isSelected,\n  onPick,\n}: {\n  year: number;\n  month: number;\n  dayClassName: (date: Date) => string;\n  isSelected?: (date: Date) => boolean;\n  onPick?: (date: Date) => void;\n}) {\n  const startDay = new Date(year, month, 1).getDay();\n  const daysInMonth = new Date(year, month + 1, 0).getDate();\n  const cells: (Date | null)[] = [];\n  for (let i = 0; i < startDay; i++) cells.push(null);\n  for (let d = 1; d <= daysInMonth; d++) cells.push(new Date(year, month, d));\n  const today = new Date();\n  // The day that takes Tab: the one moved to with the arrows, else the selected day, today, or the 1st.\n  const [moved, setMoved] = React.useState<number | null>(null);\n  const preferred = cells.find((d) => d && isSelected?.(d)) ?? cells.find((d) => d && sameDay(d, today));\n  const focusDay = Math.min(moved ?? preferred?.getDate() ?? 1, daysInMonth);\n  const days = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const onKey = (e: React.KeyboardEvent, day: number) => {\n    const step = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7 }[e.key];\n    const to = e.key === \"Home\" ? 1 : e.key === \"End\" ? daysInMonth : step ? day + step : null;\n    if (to === null) return;\n    e.preventDefault();\n    const next = Math.max(1, Math.min(daysInMonth, to));\n    setMoved(next);\n    days.current[next]?.focus();\n  };\n\n  return (\n    <>\n      <div className=\"mb-1 grid grid-cols-7\">\n        {WEEKDAYS.map((d, i) => (\n          <div\n            key={i}\n            className=\"flex h-6 items-center justify-center text-[11px] font-medium text-muted-foreground\"\n          >\n            <span aria-hidden=\"true\">{d}</span>\n            <span className=\"sr-only\">{WEEKDAY_NAMES[i]}</span>\n          </div>\n        ))}\n      </div>\n      <div className=\"grid grid-cols-7 gap-1\">\n        {cells.map((date, i) =>\n          date ? (\n            <button\n              key={i}\n              ref={(el) => {\n                days.current[date.getDate()] = el;\n              }}\n              type=\"button\"\n              aria-label={fullDate(date)}\n              aria-pressed={isSelected ? isSelected(date) : undefined}\n              aria-current={sameDay(date, today) ? \"date\" : undefined}\n              tabIndex={date.getDate() === focusDay ? 0 : -1}\n              onKeyDown={(e) => onKey(e, date.getDate())}\n              onClick={() => onPick?.(date)}\n              className={cn(\n                \"flex size-9 items-center justify-center rounded-md text-sm transition-colors\",\n                dayClassName(date),\n              )}\n            >\n              {date.getDate()}\n            </button>\n          ) : (\n            <div key={i} aria-hidden=\"true\" className=\"size-9\" />\n          ),\n        )}\n      </div>\n    </>\n  );\n}\n\n/** Single-month calendar grid. Self-contained — no external date library. */\nfunction Calendar({\n  selected,\n  onSelect,\n}: {\n  selected?: Date;\n  onSelect?: (date: Date) => void;\n}) {\n  const [view, setView] = React.useState(() => selected ?? new Date());\n  const year = view.getFullYear();\n  const month = view.getMonth();\n  const today = new Date();\n\n  return (\n    <div className=\"w-[280px] rounded-lg border border-border bg-card p-4 shadow-lg\">\n      <div className=\"mb-3 flex items-center justify-between\">\n        <button\n          type=\"button\"\n          aria-label=\"Previous month\"\n          onClick={() => setView(new Date(year, month - 1, 1))}\n          className=\"flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\"\n        >\n          <ChevronLeft className=\"size-4\" />\n        </button>\n        <span className=\"text-sm font-medium text-foreground\">\n          {view.toLocaleString(\"en-US\", { month: \"long\", year: \"numeric\" })}\n        </span>\n        <button\n          type=\"button\"\n          aria-label=\"Next month\"\n          onClick={() => setView(new Date(year, month + 1, 1))}\n          className=\"flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\"\n        >\n          <ChevronRight className=\"size-4\" />\n        </button>\n      </div>\n      <MonthGrid\n        year={year}\n        month={month}\n        onPick={onSelect}\n        isSelected={(date) => sameDay(date, selected)}\n        dayClassName={(date) =>\n          sameDay(date, selected)\n            ? \"bg-primary-strong font-medium text-primary-foreground\"\n            : sameDay(date, today)\n              ? \"border border-border text-foreground hover:bg-muted\"\n              : \"text-foreground hover:bg-muted\"\n        }\n      />\n    </div>\n  );\n}\n\ninterface DatePickerProps {\n  /** The trigger's id, for a label's htmlFor (inside a Field, its label's). */\n  id?: string;\n  /** Names the trigger where there's no visible label. */\n  \"aria-label\"?: string;\n  value?: Date;\n  onChange?: (date: Date) => void;\n  placeholder?: string;\n  className?: string;\n}\n\n/** Date picker — input trigger + calendar popover. Single date. */\nfunction DatePicker({\n  id: ownId,\n  \"aria-label\": ariaLabel,\n  value,\n  onChange,\n  placeholder = \"Pick a date\",\n  className,\n}: DatePickerProps) {\n  const [open, setOpen] = React.useState(false);\n  const [internal, setInternal] = React.useState<Date | undefined>(value);\n  const date = value ?? internal;\n  const field = useField();\n  const control = useFieldControl({ id: ownId });\n  const valueId = React.useId();\n\n  const handleSelect = (d: Date) => {\n    setInternal(d);\n    onChange?.(d);\n    setOpen(false);\n  };\n\n  return (\n    <Popover.Root open={open} onOpenChange={setOpen}>\n      <Popover.Trigger {...{ asChild: true }}>\n        <button\n          type=\"button\"\n          {...control}\n          // Its label and the date, so a screen reader says \"Due date, November 14, 2026\", not only \"Due date\".\n          aria-labelledby={field?.labelId && !ariaLabel ? `${field.labelId} ${valueId}` : undefined}\n          aria-label={ariaLabel}\n          aria-haspopup=\"dialog\"\n          data-slot=\"date-trigger\"\n          className={cn(\n            \"flex h-control w-60 items-center justify-between rounded-md border border-border bg-card px-3 text-sm transition-colors hover:bg-muted/40 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-solid focus-visible:outline-primary-ink\",\n            className,\n          )}\n        >\n          {date ? (\n            <span id={valueId} className=\"text-foreground\">\n              {date.toLocaleDateString(\"en-US\", {\n                month: \"long\",\n                day: \"numeric\",\n                year: \"numeric\",\n              })}\n            </span>\n          ) : (\n            <span id={valueId} className=\"text-muted-foreground\">{placeholder}</span>\n          )}\n          <CalendarIcon aria-hidden=\"true\" className=\"size-4 text-muted-foreground\" />\n        </button>\n      </Popover.Trigger>\n      <Popover.Portal>\n        <Popover.Content align=\"start\" sideOffset={6} className=\"z-50\">\n          <Calendar selected={date} onSelect={handleSelect} />\n        </Popover.Content>\n      </Popover.Portal>\n    </Popover.Root>\n  );\n}\n\nexport { DatePicker, Calendar, MonthGrid, sameDay };\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "forms"
  ],
  "type": "registry:ui"
}
