{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker-motion",
  "title": "Picker-motion date",
  "description": "Styled date: the Picker-motion set. 5 decorative date variations (SlideDatePicker, PopDatePicker, FadeDatePicker, SpringDatePicker, MorphDatePicker) 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-motion.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/* Motion date picker family: 5 self-contained pickers. The difference is ONLY in the\n   popover's opening motion: slide, pop, fade, spring, morph. 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. Formatting is manual\n   (YYYY-MM-DD), NO Intl. Color comes ONLY from tokens, via alpha color-mix. Only a\n   fade 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\n/* Trigger yuksekligi base kontrol olcegiyle hizali (sm h-8, md h-9, lg h-10, xl h-12). */\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\n/* Locale bagimsiz, deterministik format. */\nfunction formatDate(d: Date): string {\n  return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`\n}\n\n/* Gun butonlarinin erisilebilir adi: tam tarih. */\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/* Closes on Escape and on an outside click; Escape returns focus to the trigger. */\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\ninterface PanelMotion {\n  initial: Record<string, number>\n  animate: Record<string, number>\n  exit: Record<string, number>\n  transition: Transition\n  origin: string\n}\n\n/* Her varyantin acilis hareketi. */\nconst slideMotion: PanelMotion = {\n  initial: { opacity: 0, y: -12 },\n  animate: { opacity: 1, y: 0 },\n  exit: { opacity: 0, y: -12 },\n  transition: { duration: 0.2, ease: \"easeOut\" },\n  origin: \"origin-top\",\n}\n\nconst popMotion: PanelMotion = {\n  initial: { opacity: 0, scale: 0.85 },\n  animate: { opacity: 1, scale: 1 },\n  exit: { opacity: 0, scale: 0.85 },\n  transition: { type: \"spring\" as const, stiffness: 520, damping: 22 },\n  origin: \"origin-top-left\",\n}\n\nconst fadeMotion: PanelMotion = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0 },\n  transition: { duration: 0.24, ease: \"easeInOut\" },\n  origin: \"origin-top\",\n}\n\nconst springMotion: PanelMotion = {\n  initial: { opacity: 0, scale: 0.9, y: -14 },\n  animate: { opacity: 1, scale: 1, y: 0 },\n  exit: { opacity: 0, scale: 0.94, y: -8 },\n  transition: springTransition,\n  origin: \"origin-top\",\n}\n\nconst morphMotion: PanelMotion = {\n  initial: { opacity: 0, scaleY: 0.4, scaleX: 0.9 },\n  animate: { opacity: 1, scaleY: 1, scaleX: 1 },\n  exit: { opacity: 0, scaleY: 0.4, scaleX: 0.9 },\n  transition: { duration: 0.26, ease: \"easeOut\" },\n  origin: \"origin-top\",\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\n/* Ortak takvim govdesi: baslik (ay adi + prev/next) + weekday satiri + role=\"grid\"\n   gun izgarasi. */\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}\n\n/* Shared body: the selection state lives OUTSIDE the popover. */\nfunction MotionPicker({\n  className,\n  size = \"md\",\n  placeholder = \"Pick a date\",\n  value,\n  defaultValue,\n  onChange,\n  spec,\n}: DatePickerProps & { spec: PanelMotion }) {\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 fade = { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } }\n  const mp = reduce ? fade : spec\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        role=\"combobox\"\n        aria-haspopup=\"grid\"\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 w-64 rounded-xl border border-border bg-popover p-3 text-popover-foreground shadow-lg outline-none\",\n              reduce ? \"origin-top\" : spec.origin\n            )}\n            initial={mp.initial}\n            animate={mp.animate}\n            exit={mp.exit}\n            transition={reduce ? ({ duration: 0.12 } as Transition) : spec.transition}\n          >\n            <CalendarBody\n              month={month}\n              onMonthChange={setMonth}\n              selected={selected}\n              onPick={pick}\n              labelId={labelId}\n            />\n          </motion.div>\n        ) : null}\n      </AnimatePresence>\n    </div>\n  )\n}\n\n/* SlideDatePicker: panel ustten asagi kayarak girer. */\nexport function SlideDatePicker(props: DatePickerProps) {\n  return <MotionPicker {...props} spec={slideMotion} />\n}\n\n/* PopDatePicker: sol ust kosesinden yaylanarak buyur. */\nexport function PopDatePicker(props: DatePickerProps) {\n  return <MotionPicker {...props} spec={popMotion} />\n}\n\n/* FadeDatePicker: an opacity transition only, no transform. */\nexport function FadeDatePicker(props: DatePickerProps) {\n  return <MotionPicker {...props} spec={fadeMotion} />\n}\n\n/* SpringDatePicker: yay fizigiyle olcek + kayma birlikte. */\nexport function SpringDatePicker(props: DatePickerProps) {\n  return <MotionPicker {...props} spec={springMotion} />\n}\n\n/* MorphDatePicker: enters by opening vertically (scaleY) as if it grew out of the trigger. */\nexport function MorphDatePicker(props: DatePickerProps) {\n  return <MotionPicker {...props} spec={morphMotion} />\n}\n",
      "type": "registry:component",
      "target": "components/ui/date-picker-motion.tsx"
    }
  ],
  "categories": [
    "styled",
    "date"
  ],
  "type": "registry:component"
}