{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker",
  "title": "Date Picker",
  "description": "A date picker with a popover calendar: single date or range selection, month navigation, min/max and disabled dates, Today and Clear shortcuts, localized labels and full keyboard support.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/date-picker/date-picker.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface DateRange {\n  from?: Date;\n  to?: Date;\n}\n\nexport type DatePickerSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface DatePickerProps {\n  mode?: \"single\" | \"range\";\n  value?: Date | null;\n  defaultValue?: Date | null;\n  onValueChange?: (value: Date | null) => void;\n  range?: DateRange;\n  defaultRange?: DateRange;\n  onRangeChange?: (range: DateRange) => void;\n  placeholder?: string;\n  label?: string;\n  helperText?: string;\n  minDate?: Date;\n  maxDate?: Date;\n  isDateDisabled?: (date: Date) => boolean;\n  weekStartsOn?: 0 | 1;\n  locale?: string;\n  clearable?: boolean;\n  closeOnSelect?: boolean;\n  size?: DatePickerSize;\n  theme?: \"dark\" | \"light\";\n  width?: number | string;\n  disabled?: boolean;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.28)\", bg: \"rgba(255,255,255,0.03)\", border: \"rgba(255,255,255,0.12)\", borderHover: \"rgba(255,255,255,0.24)\", focus: \"rgba(245,244,241,0.85)\", menuBg: \"#0E0E0E\", menuBorder: \"rgba(255,255,255,0.1)\", hover: \"rgba(255,255,255,0.08)\", band: \"rgba(255,255,255,0.09)\", sel: \"#F5F4F1\", selText: \"#0A0A0A\", today: \"rgba(245,244,241,0.55)\", shadow: \"0 24px 60px rgba(0,0,0,0.55)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.28)\", bg: \"#FFFFFF\", border: \"rgba(10,10,10,0.16)\", borderHover: \"rgba(10,10,10,0.3)\", focus: \"rgba(10,10,10,0.85)\", menuBg: \"#FFFFFF\", menuBorder: \"rgba(10,10,10,0.14)\", hover: \"rgba(10,10,10,0.06)\", band: \"rgba(10,10,10,0.07)\", sel: \"#0A0A0A\", selText: \"#FFFFFF\", today: \"rgba(10,10,10,0.5)\", shadow: \"0 20px 50px rgba(0,0,0,0.18)\" },\n};\n\nconst SIZES: Record<DatePickerSize, { font: number; height: number; padX: number; radius: number; cell: number }> = {\n  sm: { font: 13, height: 36, padX: 12, radius: 11, cell: 34 },\n  md: { font: 14.5, height: 44, padX: 14, radius: 13, cell: 38 },\n  lg: { font: 16, height: 52, padX: 16, radius: 15, cell: 42 },\n};\n\nconst startOfDay = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate());\nconst addDays = (d: Date, n: number) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);\nconst addMonths = (d: Date, n: number) => {\n  const target = new Date(d.getFullYear(), d.getMonth() + n, 1);\n  const last = new Date(target.getFullYear(), target.getMonth() + 1, 0).getDate();\n  return new Date(target.getFullYear(), target.getMonth(), Math.min(d.getDate(), last));\n};\nconst sameDay = (a?: Date | null, b?: Date | null) => Boolean(a && b) && a!.getFullYear() === b!.getFullYear() && a!.getMonth() === b!.getMonth() && a!.getDate() === b!.getDate();\nconst sameMonth = (a: Date, b: Date) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();\nconst dayKey = (d: Date) => `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;\n\nfunction CalendarIcon({ size }: { size: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <rect x=\"2.5\" y=\"3.5\" width=\"11\" height=\"10\" rx=\"2\" />\n      <path d=\"M2.5 7h11M5.5 2v3M10.5 2v3\" />\n    </svg>\n  );\n}\n\nfunction Chevron({ dir, size }: { dir: \"left\" | \"right\"; size: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={dir === \"left\" ? \"M10 3.5L5.5 8L10 12.5\" : \"M6 3.5L10.5 8L6 12.5\"} />\n    </svg>\n  );\n}\n\nexport function DatePicker({\n  mode = \"single\",\n  value,\n  defaultValue = null,\n  onValueChange,\n  range,\n  defaultRange,\n  onRangeChange,\n  placeholder,\n  label,\n  helperText,\n  minDate,\n  maxDate,\n  isDateDisabled,\n  weekStartsOn = 0,\n  locale = \"en-US\",\n  clearable = true,\n  closeOnSelect = true,\n  size = \"md\",\n  theme = \"dark\",\n  width = 320,\n  disabled = false,\n  className,\n}: DatePickerProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const gridRef = React.useRef<HTMLDivElement>(null);\n  const isRange = mode === \"range\";\n  const [internalDate, setInternalDate] = React.useState<Date | null>(defaultValue);\n  const [internalRange, setInternalRange] = React.useState<DateRange>(defaultRange ?? {});\n  const [open, setOpen] = React.useState(false);\n  const [hovered, setHovered] = React.useState(false);\n  const [focusDate, setFocusDate] = React.useState<Date>(() => startOfDay(defaultValue ?? defaultRange?.from ?? new Date()));\n  const [viewMonth, setViewMonth] = React.useState<Date>(() => new Date(focusDate.getFullYear(), focusDate.getMonth(), 1));\n  const [direction, setDirection] = React.useState(1);\n  const [hoverDate, setHoverDate] = React.useState<Date | null>(null);\n  const isControlledDate = value !== undefined;\n  const isControlledRange = range !== undefined;\n  const date = isControlledDate ? value : internalDate;\n  const rng = isControlledRange ? range : internalRange;\n\n  const fmt = React.useMemo(() => new Intl.DateTimeFormat(locale, { dateStyle: \"medium\" }), [locale]);\n  const monthFmt = React.useMemo(() => new Intl.DateTimeFormat(locale, { month: \"long\", year: \"numeric\" }), [locale]);\n  const weekdayFmt = React.useMemo(() => new Intl.DateTimeFormat(locale, { weekday: \"short\" }), [locale]);\n  const longFmt = React.useMemo(() => new Intl.DateTimeFormat(locale, { dateStyle: \"full\" }), [locale]);\n\n  const outOfRange = (d: Date) => Boolean((minDate && startOfDay(d) < startOfDay(minDate)) || (maxDate && startOfDay(d) > startOfDay(maxDate)) || isDateDisabled?.(d));\n\n  const weekdays = Array.from({ length: 7 }, (_, i) => {\n    const base = new Date(2023, 0, 1 + ((i + weekStartsOn) % 7));\n    return weekdayFmt.format(base).slice(0, 2);\n  });\n\n  const days = React.useMemo(() => {\n    const first = new Date(viewMonth.getFullYear(), viewMonth.getMonth(), 1);\n    const offset = (first.getDay() - weekStartsOn + 7) % 7;\n    const start = addDays(first, -offset);\n    return Array.from({ length: 42 }, (_, i) => addDays(start, i));\n  }, [viewMonth, weekStartsOn]);\n\n  const goMonth = (n: number) => {\n    setDirection(n);\n    setViewMonth((m) => addMonths(m, n));\n  };\n\n  const moveFocus = (next: Date) => {\n    setFocusDate(next);\n    if (!sameMonth(next, viewMonth)) {\n      setDirection(next > viewMonth ? 1 : -1);\n      setViewMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n    }\n    requestAnimationFrame(() => gridRef.current?.querySelector<HTMLElement>(`[data-day=\"${dayKey(next)}\"]`)?.focus());\n  };\n\n  const openMenu = () => {\n    if (disabled) return;\n    const base = startOfDay((isRange ? rng.from : date) ?? new Date());\n    setFocusDate(base);\n    setViewMonth(new Date(base.getFullYear(), base.getMonth(), 1));\n    setOpen(true);\n  };\n\n  const closeMenu = (returnFocus = true) => {\n    setOpen(false);\n    setHoverDate(null);\n    if (returnFocus) triggerRef.current?.focus();\n  };\n\n  const pick = (d: Date) => {\n    if (outOfRange(d)) return;\n    const day = startOfDay(d);\n    if (!isRange) {\n      if (!isControlledDate) setInternalDate(day);\n      onValueChange?.(day);\n      if (closeOnSelect) closeMenu();\n      return;\n    }\n    let next: DateRange;\n    if (!rng.from || (rng.from && rng.to)) next = { from: day };\n    else next = day < rng.from ? { from: day, to: rng.from } : { from: rng.from, to: day };\n    if (!isControlledRange) setInternalRange(next);\n    onRangeChange?.(next);\n    if (next.from && next.to && closeOnSelect) closeMenu();\n  };\n\n  const clear = () => {\n    if (isRange) {\n      if (!isControlledRange) setInternalRange({});\n      onRangeChange?.({});\n    } else {\n      if (!isControlledDate) setInternalDate(null);\n      onValueChange?.(null);\n    }\n  };\n\n  const onGridKeyDown = (e: React.KeyboardEvent) => {\n    let next: Date | null = null;\n    const d = focusDate;\n    if (e.key === \"ArrowLeft\") next = addDays(d, -1);\n    else if (e.key === \"ArrowRight\") next = addDays(d, 1);\n    else if (e.key === \"ArrowUp\") next = addDays(d, -7);\n    else if (e.key === \"ArrowDown\") next = addDays(d, 7);\n    else if (e.key === \"PageUp\") next = addMonths(d, e.shiftKey ? -12 : -1);\n    else if (e.key === \"PageDown\") next = addMonths(d, e.shiftKey ? 12 : 1);\n    else if (e.key === \"Home\") next = addDays(d, -((d.getDay() - weekStartsOn + 7) % 7));\n    else if (e.key === \"End\") next = addDays(d, 6 - ((d.getDay() - weekStartsOn + 7) % 7));\n    if (next) {\n      e.preventDefault();\n      moveFocus(next);\n    }\n  };\n\n  React.useEffect(() => {\n    if (!open) return;\n    const onDown = (e: MouseEvent) => {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) {\n        setOpen(false);\n        setHoverDate(null);\n      }\n    };\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setOpen(false);\n        setHoverDate(null);\n        triggerRef.current?.focus();\n      }\n    };\n    document.addEventListener(\"mousedown\", onDown);\n    document.addEventListener(\"keydown\", onKey);\n    const t = setTimeout(() => gridRef.current?.querySelector<HTMLElement>(`[data-day=\"${dayKey(focusDate)}\"]`)?.focus(), 40);\n    return () => {\n      document.removeEventListener(\"mousedown\", onDown);\n      document.removeEventListener(\"keydown\", onKey);\n      clearTimeout(t);\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [open]);\n\n  const today = startOfDay(new Date());\n  const rangeEnd = isRange ? (rng.to ?? (rng.from && hoverDate ? hoverDate : undefined)) : undefined;\n  const lo = isRange && rng.from && rangeEnd ? (rng.from < rangeEnd ? rng.from : rangeEnd) : undefined;\n  const hi = isRange && rng.from && rangeEnd ? (rng.from < rangeEnd ? rangeEnd : rng.from) : undefined;\n\n  const hasValue = isRange ? Boolean(rng.from) : Boolean(date);\n  const text = isRange ? (rng.from ? `${fmt.format(rng.from)}${rng.to ? ` – ${fmt.format(rng.to)}` : \" – …\"}` : \"\") : date ? fmt.format(date) : \"\";\n  const shownPlaceholder = placeholder ?? (isRange ? \"Pick a date range\" : \"Pick a date\");\n  const borderColor = open ? p.focus : hovered ? p.borderHover : p.border;\n  const cellPad = 2;\n\n  return (\n    <div ref={rootRef} className={cn(\"relative inline-flex flex-col gap-2\", className)} style={{ width, maxWidth: \"100%\", fontFamily: \"Inter, sans-serif\", opacity: disabled ? 0.5 : 1 }}>\n      {label && (\n        <label id={`${uid}-label`} className=\"font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: s.font }}>\n          {label}\n        </label>\n      )}\n\n      <div className=\"relative\">\n        <button\n          ref={triggerRef}\n          type=\"button\"\n          aria-haspopup=\"dialog\"\n          aria-expanded={open}\n          aria-labelledby={label ? `${uid}-label` : undefined}\n          disabled={disabled}\n          onClick={() => (open ? closeMenu(false) : openMenu())}\n          onMouseEnter={() => setHovered(true)}\n          onMouseLeave={() => setHovered(false)}\n          className=\"flex w-full items-center text-left outline-none\"\n          style={{ height: s.height, gap: 10, padding: `0 ${s.padX}px`, borderRadius: s.radius, background: p.bg, border: `1px solid ${borderColor}`, boxShadow: open ? `0 0 0 3px color-mix(in srgb, ${p.focus} 14%, transparent)` : \"0 0 0 0 transparent\", color: hasValue ? p.text : p.muted, fontSize: s.font, fontWeight: 500, cursor: disabled ? \"default\" : \"pointer\", transition: \"border-color 0.18s ease, box-shadow 0.18s ease\" }}\n        >\n          <span className=\"flex shrink-0\" style={{ color: p.muted }}>\n            <CalendarIcon size={s.font + 2} />\n          </span>\n          <span className=\"min-w-0 flex-1 truncate\">{hasValue ? text : shownPlaceholder}</span>\n          {clearable && hasValue && !disabled && (\n            <span\n              role=\"button\"\n              tabIndex={-1}\n              aria-label=\"Clear date\"\n              onClick={(e) => {\n                e.stopPropagation();\n                clear();\n              }}\n              className=\"flex shrink-0 cursor-pointer items-center justify-center rounded-full\"\n              style={{ width: 20, height: 20, background: p.hover, color: p.muted }}\n            >\n              <svg width=\"9\" height=\"9\" viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n                <path d=\"M3 3L9 9M9 3L3 9\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" />\n              </svg>\n            </span>\n          )}\n        </button>\n\n        <AnimatePresence>\n          {open && (\n            <motion.div\n              role=\"dialog\"\n              aria-label=\"Choose date\"\n              className=\"absolute left-0 z-50\"\n              style={{ top: \"calc(100% + 8px)\", padding: 14, borderRadius: s.radius + 6, border: `1px solid ${p.menuBorder}`, background: p.menuBg, boxShadow: p.shadow, transformOrigin: \"top left\", width: s.cell * 7 + 28 + cellPad * 14 }}\n              initial={{ opacity: 0, y: -6, scale: 0.97 }}\n              animate={{ opacity: 1, y: 0, scale: 1 }}\n              exit={{ opacity: 0, y: -6, scale: 0.97 }}\n              transition={{ duration: 0.16, ease: [0.16, 1, 0.3, 1] }}\n            >\n              <div className=\"flex items-center justify-between\" style={{ marginBottom: 10 }}>\n                <button type=\"button\" aria-label=\"Previous month\" onClick={() => goMonth(-1)} className=\"flex cursor-pointer items-center justify-center rounded-lg border-none bg-transparent outline-none focus-visible:ring-2\" style={{ width: 30, height: 30, color: p.muted, [\"--tw-ring-color\" as string]: p.focus }} onMouseEnter={(e) => (e.currentTarget.style.background = p.hover)} onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}>\n                  <Chevron dir=\"left\" size={16} />\n                </button>\n                <div className=\"relative overflow-hidden text-center\" style={{ height: 22, minWidth: 140 }} aria-live=\"polite\">\n                  <AnimatePresence initial={false} custom={direction} mode=\"popLayout\">\n                    <motion.div key={`${viewMonth.getFullYear()}-${viewMonth.getMonth()}`} custom={direction} initial={{ opacity: 0, y: direction * 10 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: direction * -10 }} transition={{ duration: 0.18 }} className=\"font-semibold\" style={{ color: p.text, fontSize: s.font, lineHeight: \"22px\" }}>\n                      {monthFmt.format(viewMonth)}\n                    </motion.div>\n                  </AnimatePresence>\n                </div>\n                <button type=\"button\" aria-label=\"Next month\" onClick={() => goMonth(1)} className=\"flex cursor-pointer items-center justify-center rounded-lg border-none bg-transparent outline-none focus-visible:ring-2\" style={{ width: 30, height: 30, color: p.muted, [\"--tw-ring-color\" as string]: p.focus }} onMouseEnter={(e) => (e.currentTarget.style.background = p.hover)} onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}>\n                  <Chevron dir=\"right\" size={16} />\n                </button>\n              </div>\n\n              <div className=\"grid\" style={{ gridTemplateColumns: `repeat(7, ${s.cell + cellPad * 2}px)` }} aria-hidden=\"true\">\n                {weekdays.map((w, i) => (\n                  <div key={i} className=\"text-center font-medium\" style={{ height: 26, lineHeight: \"26px\", color: p.faint, fontSize: s.font - 2.5 }}>\n                    {w}\n                  </div>\n                ))}\n              </div>\n\n              <div ref={gridRef} role=\"grid\" onKeyDown={onGridKeyDown} className=\"grid\" style={{ gridTemplateColumns: `repeat(7, ${s.cell + cellPad * 2}px)` }}>\n                {days.map((d) => {\n                  const inMonth = sameMonth(d, viewMonth);\n                  const dis = outOfRange(d);\n                  const isSel = isRange ? sameDay(d, rng.from) || sameDay(d, rng.to) : sameDay(d, date);\n                  const inBand = Boolean(lo && hi && d > lo && d < hi);\n                  const isEdgeLo = Boolean(lo && sameDay(d, lo) && hi && !sameDay(lo, hi));\n                  const isEdgeHi = Boolean(hi && sameDay(d, hi) && lo && !sameDay(lo, hi));\n                  const isToday = sameDay(d, today);\n                  const isFocus = sameDay(d, focusDate);\n                  return (\n                    <div key={dayKey(d)} role=\"gridcell\" aria-selected={isSel || undefined} className=\"relative flex items-center justify-center\" style={{ height: s.cell + cellPad * 2 }}>\n                      {(inBand || isEdgeLo || isEdgeHi) && <span aria-hidden=\"true\" className=\"absolute\" style={{ top: cellPad, bottom: cellPad, left: isEdgeLo ? \"50%\" : 0, right: isEdgeHi ? \"50%\" : 0, background: p.band }} />}\n                      <button\n                        type=\"button\"\n                        data-day={dayKey(d)}\n                        tabIndex={isFocus ? 0 : -1}\n                        disabled={dis}\n                        aria-label={longFmt.format(d)}\n                        aria-current={isToday ? \"date\" : undefined}\n                        onClick={() => pick(d)}\n                        onFocus={() => setFocusDate(d)}\n                        onMouseEnter={() => isRange && rng.from && !rng.to && setHoverDate(d)}\n                        className=\"relative flex items-center justify-center rounded-full border-none outline-none focus-visible:ring-2\"\n                        style={{ width: s.cell, height: s.cell, fontSize: s.font - 1, fontWeight: isSel ? 700 : 500, background: isSel ? p.sel : \"transparent\", color: isSel ? p.selText : inMonth ? p.text : p.faint, opacity: dis ? 0.3 : 1, cursor: dis ? \"default\" : \"pointer\", boxShadow: isToday && !isSel ? `inset 0 0 0 1.5px ${p.today}` : undefined, transition: \"background 0.12s ease\", [\"--tw-ring-color\" as string]: p.focus }}\n                        onMouseOver={(e) => !isSel && !dis && (e.currentTarget.style.background = p.hover)}\n                        onMouseOut={(e) => !isSel && (e.currentTarget.style.background = \"transparent\")}\n                      >\n                        {d.getDate()}\n                      </button>\n                    </div>\n                  );\n                })}\n              </div>\n\n              <div className=\"flex items-center justify-between\" style={{ marginTop: 10, paddingTop: 10, borderTop: `1px solid ${p.menuBorder}` }}>\n                <button\n                  type=\"button\"\n                  onClick={() => {\n                    setDirection(today > viewMonth ? 1 : -1);\n                    setViewMonth(new Date(today.getFullYear(), today.getMonth(), 1));\n                    moveFocus(today);\n                  }}\n                  className=\"cursor-pointer border-none bg-transparent p-0 font-semibold outline-none hover:underline\"\n                  style={{ color: p.text, fontSize: s.font - 1.5 }}\n                >\n                  Today\n                </button>\n                {clearable && hasValue && (\n                  <button type=\"button\" onClick={clear} className=\"cursor-pointer border-none bg-transparent p-0 font-medium outline-none hover:underline\" style={{ color: p.muted, fontSize: s.font - 1.5 }}>\n                    Clear\n                  </button>\n                )}\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n\n      {helperText && <span style={{ color: p.muted, fontSize: s.font - 1.5, lineHeight: 1.4 }}>{helperText}</span>}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}