{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker-preset",
  "title": "Picker-preset date",
  "description": "Styled date: the Picker-preset set. 5 decorative date variations (QuickDatePicker, ShortcutsDatePicker, RecentDatePicker, RelativeDatePicker, CustomDatePicker) on the ai2 token system, powered by framer-motion, reduced-motion aware and sized sm to xl. Part of the free styled layer.",
  "dependencies": [
    "motion@^12.42.2",
    "lucide-react@^1.23.0"
  ],
  "registryDependencies": [
    "@ai2/tokens"
  ],
  "files": [
    {
      "path": "registry/ai2/styled/date-picker-preset.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Calendar, ChevronLeft, ChevronRight } from \"lucide-react\"\nimport { AnimatePresence, motion, useReducedMotion, type Transition } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/* Preset date picker family: 5 self-contained pickers. The difference is the quick\n   selection shortcuts standing BESIDE the calendar: quick, shortcuts, recent,\n   relative, custom. NO radix, NO date library, NO portal, NO Intl. Each export is a\n   complete picker: a relative wrapper + a trigger (aria-haspopup=\"dialog\",\n   aria-expanded) + a panel absolutely positioned BELOW the trigger (a shortcut\n   column + a role=\"grid\" month grid). Picking a day or a shortcut updates the value\n   and closes the panel. It closes on an outside click or Escape (focus returns to\n   the trigger).\n\n   CRITICAL: ALL dates derive from a FIXED reference (BASE_DATE = 2026-01-15) -\n   Date.now/new Date() are NEVER called. Shortcuts such as \"Today\", \"Recent\" and\n   \"Relative\" are computed from that fixed reference too; reading the real clock\n   breaks prerender/hydration determinism. The fixed reference can be changed with\n   the `baseDate` prop, but its default is always fixed.\n\n   State trap: the selection state is held OUTSIDE THE POPOVER TREE - the panel\n   unmounts on close, and the selection lives on. */\n\nexport type StyledSize = \"sm\" | \"md\" | \"lg\" | \"xl\"\n\nconst triggerHeight: Record<StyledSize, string> = {\n  sm: \"h-8 text-sm\",\n  md: \"h-9 text-sm\",\n  lg: \"h-10 text-base\",\n  xl: \"h-12 text-base\",\n}\n\n/* SSR-guvenli sabit referans tarih. today ASLA kullanilmaz. */\nconst BASE_DATE = new Date(2026, 0, 15)\n\nconst MONTH_NAMES = [\n  \"January\",\n  \"February\",\n  \"March\",\n  \"April\",\n  \"May\",\n  \"June\",\n  \"July\",\n  \"August\",\n  \"September\",\n  \"October\",\n  \"November\",\n  \"December\",\n]\n\nconst WEEKDAY_LABELS = [\"Su\", \"Mo\", \"Tu\", \"We\", \"Th\", \"Fr\", \"Sa\"]\n\nfunction pad2(n: number): string {\n  return n < 10 ? `0${n}` : `${n}`\n}\n\nfunction formatDate(d: Date): string {\n  return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`\n}\n\nfunction formatLong(d: Date): string {\n  return `${MONTH_NAMES[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`\n}\n\nfunction startOfMonth(d: Date): Date {\n  return new Date(d.getFullYear(), d.getMonth(), 1)\n}\n\nfunction daysInMonth(year: number, month: number): number {\n  return new Date(year, month + 1, 0).getDate()\n}\n\nfunction sameDay(a: Date | undefined, b: Date | undefined): boolean {\n  return (\n    !!a &&\n    !!b &&\n    a.getFullYear() === b.getFullYear() &&\n    a.getMonth() === b.getMonth() &&\n    a.getDate() === b.getDate()\n  )\n}\n\n/* Shifting days from the fixed reference: every shortcut is built on this. */\nfunction addDays(base: Date, days: number): Date {\n  return new Date(base.getFullYear(), base.getMonth(), base.getDate() + days)\n}\n\nfunction addMonths(base: Date, months: number): Date {\n  return new Date(base.getFullYear(), base.getMonth() + months, base.getDate())\n}\n\nfunction useDismiss(\n  open: boolean,\n  onClose: (refocus: boolean) => void,\n  ref: React.RefObject<HTMLDivElement | null>\n) {\n  React.useEffect(() => {\n    if (!open) return\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") onClose(true)\n    }\n    const onPointer = (e: PointerEvent) => {\n      const node = ref.current\n      if (node && e.target instanceof Node && !node.contains(e.target)) {\n        onClose(false)\n      }\n    }\n    window.addEventListener(\"keydown\", onKey)\n    window.addEventListener(\"pointerdown\", onPointer)\n    return () => {\n      window.removeEventListener(\"keydown\", onKey)\n      window.removeEventListener(\"pointerdown\", onPointer)\n    }\n  }, [open, onClose, ref])\n}\n\nconst springTransition: Transition = { type: \"spring\" as const, stiffness: 340, damping: 26 }\n\nconst panelMotion = {\n  initial: { opacity: 0, scale: 0.96, y: -6 },\n  animate: { opacity: 1, scale: 1, y: 0 },\n  exit: { opacity: 0, scale: 0.96, y: -6 },\n}\n\nconst triggerBase =\n  \"inline-flex w-full select-none items-center gap-2 whitespace-nowrap rounded-lg px-3 font-medium outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none\"\n\nconst navBtn =\n  \"inline-flex size-7 items-center justify-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--color-foreground)_6%,transparent)] hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none\"\n\nconst dayBase =\n  \"relative inline-flex size-8 items-center justify-center rounded-md text-sm text-foreground outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--color-foreground)_6%,transparent)] focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n\nconst daySelected =\n  \"bg-primary text-primary-foreground hover:bg-[color-mix(in_oklab,var(--color-primary)_90%,transparent)]\"\n\nconst presetBtnBase =\n  \"w-full cursor-default select-none rounded-md px-2 py-1.5 text-left text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--color-foreground)_6%,transparent)] hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n\nconst presetActive = \"bg-[color-mix(in_oklab,var(--color-primary)_16%,transparent)] text-foreground\"\n\ninterface Preset {\n  label: string\n  date: Date\n}\n\nfunction CalendarBody({\n  month,\n  onMonthChange,\n  selected,\n  onPick,\n  labelId,\n}: {\n  month: Date\n  onMonthChange: (d: Date) => void\n  selected: Date | undefined\n  onPick: (d: Date) => void\n  labelId: string\n}) {\n  const year = month.getFullYear()\n  const m = month.getMonth()\n  const leading = new Date(year, m, 1).getDay()\n  const total = daysInMonth(year, m)\n\n  const cells: (Date | null)[] = []\n  for (let i = 0; i < leading; i++) cells.push(null)\n  for (let d = 1; d <= total; d++) cells.push(new Date(year, m, d))\n\n  return (\n    <div data-slot=\"styled-date-picker-calendar\" className=\"flex flex-col gap-2\">\n      <div className=\"flex items-center justify-between px-1\">\n        <button\n          type=\"button\"\n          aria-label=\"Previous month\"\n          className={navBtn}\n          onClick={() => onMonthChange(new Date(year, m - 1, 1))}\n        >\n          <ChevronLeft />\n        </button>\n        <div id={labelId} className=\"text-sm font-semibold text-foreground\">\n          {MONTH_NAMES[m]} {year}\n        </div>\n        <button\n          type=\"button\"\n          aria-label=\"Next month\"\n          className={navBtn}\n          onClick={() => onMonthChange(new Date(year, m + 1, 1))}\n        >\n          <ChevronRight />\n        </button>\n      </div>\n\n      <div className=\"grid grid-cols-7 gap-0.5\">\n        {WEEKDAY_LABELS.map((w) => (\n          <div\n            key={w}\n            className=\"flex size-8 items-center justify-center text-xs font-medium text-muted-foreground\"\n          >\n            {w}\n          </div>\n        ))}\n      </div>\n\n      <div role=\"grid\" aria-labelledby={labelId} className=\"grid grid-cols-7 gap-0.5\">\n        {cells.map((day, i) =>\n          day === null ? (\n            <span key={`empty-${i}`} className=\"size-8\" aria-hidden=\"true\" />\n          ) : (\n            <button\n              key={formatDate(day)}\n              type=\"button\"\n              role=\"gridcell\"\n              aria-label={formatLong(day)}\n              aria-selected={sameDay(day, selected)}\n              className={cn(dayBase, sameDay(day, selected) && daySelected)}\n              onClick={() => onPick(day)}\n            >\n              {day.getDate()}\n            </button>\n          )\n        )}\n      </div>\n    </div>\n  )\n}\n\nexport interface DatePickerProps {\n  className?: string\n  size?: StyledSize\n  placeholder?: string\n  value?: Date\n  defaultValue?: Date\n  onChange?: (d: Date) => void\n  /* Tum kisayollarin hesaplandigi sabit referans. Varsayilan deterministiktir. */\n  baseDate?: Date\n}\n\n/* Shared body: the shortcut column on the left, the calendar on the right. The selection state lives OUTSIDE the popover. */\nfunction PresetPicker({\n  className,\n  size = \"md\",\n  placeholder = \"Pick a date\",\n  value,\n  defaultValue,\n  onChange,\n  presets,\n  heading,\n  layout = \"side\",\n}: DatePickerProps & {\n  presets: Preset[]\n  heading?: string\n  layout?: \"side\" | \"top\"\n}) {\n  const isControlled = value !== undefined\n  const [internal, setInternal] = React.useState<Date | undefined>(defaultValue)\n  const selected = isControlled ? value : internal\n\n  const [open, setOpen] = React.useState(false)\n  const [month, setMonth] = React.useState(() => startOfMonth(selected ?? BASE_DATE))\n\n  const reduce = useReducedMotion()\n  const wrapperRef = React.useRef<HTMLDivElement>(null)\n  const triggerRef = React.useRef<HTMLButtonElement>(null)\n  const panelId = React.useId()\n  const labelId = React.useId()\n  const headingId = React.useId()\n\n  const close = React.useCallback((refocus: boolean) => {\n    setOpen(false)\n    if (refocus) triggerRef.current?.focus()\n  }, [])\n\n  useDismiss(open, close, wrapperRef)\n\n  const commit = (day: Date) => {\n    if (!isControlled) setInternal(day)\n    onChange?.(day)\n    setMonth(startOfMonth(day))\n    setOpen(false)\n    triggerRef.current?.focus()\n  }\n\n  const fade = { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } }\n  const mp = reduce ? fade : panelMotion\n\n  return (\n    <div\n      ref={wrapperRef}\n      data-slot=\"styled-date-picker\"\n      className={cn(\"relative inline-flex w-64 flex-col\", className)}\n    >\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        aria-haspopup=\"dialog\"\n        aria-expanded={open}\n        aria-controls={open ? panelId : undefined}\n        className={cn(\n          triggerBase,\n          triggerHeight[size],\n          \"justify-between border border-field-border bg-transparent text-foreground hover:bg-[color-mix(in_oklab,var(--color-foreground)_4%,transparent)]\"\n        )}\n        onClick={() => setOpen(!open)}\n      >\n        <span className={cn(!selected && \"text-muted-foreground\")}>\n          {selected ? formatDate(selected) : placeholder}\n        </span>\n        <Calendar className=\"text-muted-foreground\" />\n      </button>\n\n      <AnimatePresence>\n        {open ? (\n          <motion.div\n            id={panelId}\n            data-slot=\"styled-date-picker-popover\"\n            className={cn(\n              \"absolute left-0 top-full z-50 mt-2 origin-top rounded-xl border border-border bg-popover p-3 text-popover-foreground shadow-lg outline-none\",\n              layout === \"side\" ? \"flex w-[22rem] gap-3\" : \"flex w-64 flex-col gap-3\"\n            )}\n            initial={mp.initial}\n            animate={mp.animate}\n            exit={mp.exit}\n            transition={reduce ? ({ duration: 0.12 } as Transition) : springTransition}\n          >\n            <div\n              data-slot=\"styled-date-picker-presets\"\n              className={cn(\n                \"flex flex-col gap-1\",\n                layout === \"side\"\n                  ? \"w-28 shrink-0 border-r border-border pr-2\"\n                  : \"border-b border-border pb-3\"\n              )}\n            >\n              {heading ? (\n                <div\n                  id={headingId}\n                  className=\"px-2 pb-1 text-[0.6875rem] font-semibold uppercase tracking-wide text-muted-foreground\"\n                >\n                  {heading}\n                </div>\n              ) : null}\n              <div\n                className={cn(layout === \"top\" && \"grid grid-cols-2 gap-1\")}\n                role=\"group\"\n                aria-labelledby={heading ? headingId : undefined}\n              >\n                {presets.map((p) => (\n                  <button\n                    key={p.label}\n                    type=\"button\"\n                    aria-label={`${p.label}, ${formatLong(p.date)}`}\n                    className={cn(presetBtnBase, sameDay(p.date, selected) && presetActive)}\n                    onClick={() => commit(p.date)}\n                  >\n                    {p.label}\n                  </button>\n                ))}\n              </div>\n            </div>\n\n            <div className=\"min-w-0 flex-1\">\n              <CalendarBody\n                month={month}\n                onMonthChange={setMonth}\n                selected={selected}\n                onPick={commit}\n                labelId={labelId}\n              />\n            </div>\n          </motion.div>\n        ) : null}\n      </AnimatePresence>\n    </div>\n  )\n}\n\n/* QuickDatePicker: en sik kullanilan birkac atlama, sabit referanstan turetilir. */\nexport function QuickDatePicker({ baseDate = BASE_DATE, ...props }: DatePickerProps) {\n  const presets = React.useMemo<Preset[]>(\n    () => [\n      { label: \"Today\", date: baseDate },\n      { label: \"Tomorrow\", date: addDays(baseDate, 1) },\n      { label: \"In a week\", date: addDays(baseDate, 7) },\n      { label: \"In a month\", date: addMonths(baseDate, 1) },\n    ],\n    [baseDate]\n  )\n  return <PresetPicker {...props} presets={presets} heading=\"Quick\" />\n}\n\n/* ShortcutsDatePicker: hafta ve ay sinirlarina atlayan kisayollar. */\nexport function ShortcutsDatePicker({ baseDate = BASE_DATE, ...props }: DatePickerProps) {\n  const presets = React.useMemo<Preset[]>(() => {\n    const startOfWeek = addDays(baseDate, -baseDate.getDay())\n    return [\n      { label: \"Start of week\", date: startOfWeek },\n      { label: \"End of week\", date: addDays(startOfWeek, 6) },\n      { label: \"Start of month\", date: startOfMonth(baseDate) },\n      {\n        label: \"End of month\",\n        date: new Date(baseDate.getFullYear(), baseDate.getMonth() + 1, 0),\n      },\n      { label: \"Start of year\", date: new Date(baseDate.getFullYear(), 0, 1) },\n    ]\n  }, [baseDate])\n  return <PresetPicker {...props} presets={presets} heading=\"Jump to\" className=\"w-72\" />\n}\n\n/* RecentDatePicker: backward-looking jumps. Computed from a fixed reference, NOT from the real clock. */\nexport function RecentDatePicker({ baseDate = BASE_DATE, ...props }: DatePickerProps) {\n  const presets = React.useMemo<Preset[]>(\n    () => [\n      { label: \"Yesterday\", date: addDays(baseDate, -1) },\n      { label: \"3 days ago\", date: addDays(baseDate, -3) },\n      { label: \"Last week\", date: addDays(baseDate, -7) },\n      { label: \"Last month\", date: addMonths(baseDate, -1) },\n    ],\n    [baseDate]\n  )\n  return <PresetPicker {...props} presets={presets} heading=\"Recent\" />\n}\n\n/* RelativeDatePicker: forward-looking relative jumps, shortcuts in two columns at the top. */\nexport function RelativeDatePicker({ baseDate = BASE_DATE, ...props }: DatePickerProps) {\n  const presets = React.useMemo<Preset[]>(\n    () => [\n      { label: \"+1 day\", date: addDays(baseDate, 1) },\n      { label: \"+3 days\", date: addDays(baseDate, 3) },\n      { label: \"+2 weeks\", date: addDays(baseDate, 14) },\n      { label: \"+3 months\", date: addMonths(baseDate, 3) },\n    ],\n    [baseDate]\n  )\n  return <PresetPicker {...props} presets={presets} heading=\"Relative\" layout=\"top\" />\n}\n\n/* CustomDatePicker: is akisina ozel adlandirilmis kisayollar. */\nexport function CustomDatePicker({ baseDate = BASE_DATE, ...props }: DatePickerProps) {\n  const presets = React.useMemo<Preset[]>(\n    () => [\n      { label: \"Kickoff\", date: baseDate },\n      { label: \"Review\", date: addDays(baseDate, 5) },\n      { label: \"Beta\", date: addDays(baseDate, 21) },\n      { label: \"Launch\", date: addMonths(baseDate, 2) },\n    ],\n    [baseDate]\n  )\n  return <PresetPicker {...props} presets={presets} heading=\"Milestones\" />\n}\n",
      "type": "registry:component",
      "target": "components/ui/date-picker-preset.tsx"
    }
  ],
  "categories": [
    "styled",
    "date"
  ],
  "type": "registry:component"
}