{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker-tone",
  "title": "Picker-tone date",
  "description": "Styled date: the Picker-tone set. 5 decorative date variations (InfoDatePicker, SuccessDatePicker, WarningDatePicker, DangerDatePicker, MutedDatePicker) 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-tone.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/* Tone date picker family: 5 self-contained pickers. The difference is ONLY the\n   semantic tone: info, success, warning, danger, muted. The tone drives the trigger\n   frame, the calendar header, the selected day and the focus ring. NO radix, NO date\n   library, NO portal, NO Intl. Each export is a complete picker: a relative wrapper\n   + a trigger (role=\"combobox\" + aria-haspopup=\"grid\", aria-expanded) + a month-grid\n   calendar panel (role=\"grid\") absolutely positioned BELOW the trigger. Picking a\n   day updates the value and closes the panel. It closes on an outside click or\n   Escape (focus returns to the trigger).\n\n   CRITICAL: the visible month derives from a FIXED value (the month of the selected\n   date if there is one, otherwise FIXED_MONTH = 2026-01) - NEVER today. Reading the\n   real clock breaks prerender/hydration determinism. Color comes ONLY from the ai2\n   semantic tokens (danger, NEVER destructive), via alpha color-mix. Only a fade\n   under reduced motion.\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\ntype Tone = \"info\" | \"success\" | \"warning\" | \"danger\" | \"muted\"\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 gorunen ay. today ASLA kullanilmaz. */\nconst FIXED_MONTH = new Date(2026, 0, 1)\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\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 border 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 focus-visible:ring-[3px]\"\n\n/* Static class sets per tone: every value is written literally so Tailwind can see the class. Alpha only through color-mix. */\ninterface ToneStyles {\n  trigger: string\n  icon: string\n  headline: string\n  dayHover: string\n  daySelected: string\n  dayRing: string\n  panel: string\n}\n\nconst toneStyles: Record<Tone, ToneStyles> = {\n  info: {\n    trigger:\n      \"border-[color-mix(in_oklab,var(--color-info)_45%,transparent)] bg-info-soft text-info-soft-foreground hover:bg-[color-mix(in_oklab,var(--color-info)_18%,transparent)]\",\n    icon: \"text-info\",\n    headline: \"text-info\",\n    dayHover: \"hover:bg-[color-mix(in_oklab,var(--color-info)_14%,transparent)]\",\n    daySelected:\n      \"bg-info text-info-foreground hover:bg-[color-mix(in_oklab,var(--color-info)_90%,transparent)]\",\n    dayRing: \"focus-visible:ring-[color-mix(in_oklab,var(--color-info)_50%,transparent)]\",\n    panel: \"border-[color-mix(in_oklab,var(--color-info)_30%,transparent)]\",\n  },\n  success: {\n    trigger:\n      \"border-[color-mix(in_oklab,var(--color-success)_45%,transparent)] bg-success-soft text-success-soft-foreground hover:bg-[color-mix(in_oklab,var(--color-success)_18%,transparent)]\",\n    icon: \"text-success\",\n    headline: \"text-success\",\n    dayHover: \"hover:bg-[color-mix(in_oklab,var(--color-success)_14%,transparent)]\",\n    daySelected:\n      \"bg-success text-success-foreground hover:bg-[color-mix(in_oklab,var(--color-success)_90%,transparent)]\",\n    dayRing: \"focus-visible:ring-[color-mix(in_oklab,var(--color-success)_50%,transparent)]\",\n    panel: \"border-[color-mix(in_oklab,var(--color-success)_30%,transparent)]\",\n  },\n  warning: {\n    trigger:\n      \"border-[color-mix(in_oklab,var(--color-warning)_45%,transparent)] bg-warning-soft text-warning-soft-foreground hover:bg-[color-mix(in_oklab,var(--color-warning)_18%,transparent)]\",\n    icon: \"text-warning\",\n    headline: \"text-warning\",\n    dayHover: \"hover:bg-[color-mix(in_oklab,var(--color-warning)_14%,transparent)]\",\n    daySelected:\n      \"bg-warning text-warning-foreground hover:bg-[color-mix(in_oklab,var(--color-warning)_90%,transparent)]\",\n    dayRing: \"focus-visible:ring-[color-mix(in_oklab,var(--color-warning)_50%,transparent)]\",\n    panel: \"border-[color-mix(in_oklab,var(--color-warning)_30%,transparent)]\",\n  },\n  danger: {\n    trigger:\n      \"border-[color-mix(in_oklab,var(--color-danger)_45%,transparent)] bg-danger-soft text-danger-soft-foreground hover:bg-[color-mix(in_oklab,var(--color-danger)_18%,transparent)]\",\n    icon: \"text-danger\",\n    headline: \"text-danger\",\n    dayHover: \"hover:bg-[color-mix(in_oklab,var(--color-danger)_14%,transparent)]\",\n    daySelected:\n      \"bg-danger text-danger-foreground hover:bg-[color-mix(in_oklab,var(--color-danger)_90%,transparent)]\",\n    dayRing: \"focus-visible:ring-[color-mix(in_oklab,var(--color-danger)_50%,transparent)]\",\n    panel: \"border-[color-mix(in_oklab,var(--color-danger)_30%,transparent)]\",\n  },\n  muted: {\n    trigger:\n      \"border-border bg-muted text-muted-foreground hover:bg-[color-mix(in_oklab,var(--color-foreground)_8%,transparent)]\",\n    icon: \"text-muted-foreground\",\n    headline: \"text-muted-foreground\",\n    dayHover: \"hover:bg-[color-mix(in_oklab,var(--color-foreground)_8%,transparent)]\",\n    daySelected:\n      \"bg-[color-mix(in_oklab,var(--color-foreground)_82%,transparent)] text-background hover:bg-[color-mix(in_oklab,var(--color-foreground)_70%,transparent)]\",\n    dayRing: \"focus-visible:ring-ring/50\",\n    panel: \"border-border\",\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}\n\n/* Shared body: the selection state lives OUTSIDE the popover. */\nfunction TonePicker({\n  className,\n  size = \"md\",\n  placeholder = \"Pick a date\",\n  value,\n  defaultValue,\n  onChange,\n  tone,\n}: DatePickerProps & { tone: Tone }) {\n  const t = toneStyles[tone]\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 ?? FIXED_MONTH))\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\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 pick = (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 year = month.getFullYear()\n  const m = month.getMonth()\n  const leading = new Date(year, m, 1).getDay()\n  const total = daysInMonth(year, m)\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  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      data-tone={tone}\n      className={cn(\"relative inline-flex w-64 flex-col\", className)}\n    >\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        role=\"combobox\"\n        aria-haspopup=\"grid\"\n        aria-expanded={open}\n        aria-controls={open ? panelId : undefined}\n        className={cn(triggerBase, triggerHeight[size], \"justify-between\", t.trigger)}\n        onClick={() => setOpen(!open)}\n      >\n        <span className={cn(!selected && \"opacity-70\")}>\n          {selected ? formatDate(selected) : placeholder}\n        </span>\n        <Calendar className={t.icon} />\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 w-64 origin-top rounded-xl border bg-popover p-3 text-popover-foreground shadow-lg outline-none\",\n              t.panel\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 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={() => setMonth(new Date(year, m - 1, 1))}\n                >\n                  <ChevronLeft />\n                </button>\n                <div id={labelId} className={cn(\"text-sm font-semibold\", t.headline)}>\n                  {MONTH_NAMES[m]} {year}\n                </div>\n                <button\n                  type=\"button\"\n                  aria-label=\"Next month\"\n                  className={navBtn}\n                  onClick={() => setMonth(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(\n                        dayBase,\n                        t.dayHover,\n                        t.dayRing,\n                        sameDay(day, selected) && t.daySelected\n                      )}\n                      onClick={() => pick(day)}\n                    >\n                      {day.getDate()}\n                    </button>\n                  )\n                )}\n              </div>\n            </div>\n          </motion.div>\n        ) : null}\n      </AnimatePresence>\n    </div>\n  )\n}\n\n/* InfoDatePicker: bilgilendirici info tonu. */\nexport function InfoDatePicker(props: DatePickerProps) {\n  return <TonePicker {...props} tone=\"info\" />\n}\n\n/* SuccessDatePicker: onaylanmis/gecerli secim tonu. */\nexport function SuccessDatePicker(props: DatePickerProps) {\n  return <TonePicker {...props} tone=\"success\" />\n}\n\n/* WarningDatePicker: dikkat isteyen tarih tonu. */\nexport function WarningDatePicker(props: DatePickerProps) {\n  return <TonePicker {...props} tone=\"warning\" />\n}\n\n/* DangerDatePicker: the tone for an invalid or risky date. ai2 danger tokens, NO destructive. */\nexport function DangerDatePicker(props: DatePickerProps) {\n  return <TonePicker {...props} tone=\"danger\" />\n}\n\n/* MutedDatePicker: sessiz, ikincil tarih tonu. */\nexport function MutedDatePicker(props: DatePickerProps) {\n  return <TonePicker {...props} tone=\"muted\" />\n}\n",
      "type": "registry:component",
      "target": "components/ui/date-picker-tone.tsx"
    }
  ],
  "categories": [
    "styled",
    "date"
  ],
  "type": "registry:component"
}