{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "calendar-date-picker-28",
  "title": "Popover range picker",
  "description": "A field-like trigger that opens a range calendar in a popover.",
  "dependencies": [
    "date-fns",
    "motion",
    "react-day-picker"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/calendar.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/popover.json",
    "https://ui.ndekocode.dev/r/recipes.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/calendar-date-picker/calendar-date-picker-28.tsx",
      "content": "'use client';\n\nimport { format } from 'date-fns';\nimport { useId, useState } from 'react';\nimport type { DateRange } from 'react-day-picker';\n\nimport { CalendarIcon } from '@/registry/ndeko/lib/icons';\nimport { CONTROL_RECIPE, CONTROL_SIZES } from '@/registry/ndeko/lib/recipes';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport {\n  Popover,\n  PopoverContent,\n  PopoverTrigger,\n} from '@/registry/ndeko/ui/popover';\n\nimport { AnimatedCalendar } from './_parts/animated-calendar';\nimport { SwapText } from './_parts/swap-text';\n\nconst TRIGGER = cn(\n  CONTROL_RECIPE,\n  CONTROL_SIZES.default,\n  'group flex cursor-pointer items-center justify-between gap-2 text-left data-popup-open:border-foreground/30'\n);\n\nconst DAY_FORMAT = 'LLL dd, y';\n\nfunction rangeLabelOf(range: DateRange | undefined) {\n  if (!range?.from) {\n    return 'Pick a date range';\n  }\n  const fromLabel = format(range.from, DAY_FORMAT);\n  if (!range.to) {\n    return fromLabel;\n  }\n  const toLabel = format(range.to, DAY_FORMAT);\n  return `${fromLabel} - ${toLabel}`;\n}\n\nexport default function CalendarDatePicker28() {\n  const id = useId();\n  const [range, setRange] = useState<DateRange | undefined>();\n  const isEmpty = !range?.from;\n\n  return (\n    <div className='flex w-full max-w-xs flex-col gap-1.5'>\n      <Label htmlFor={id}>Date range picker</Label>\n      <Popover>\n        <PopoverTrigger id={id} className={TRIGGER}>\n          <SwapText\n            text={rangeLabelOf(range)}\n            className={cn(isEmpty && 'text-muted-foreground/75')}\n          />\n          <CalendarIcon className='text-muted-foreground group-hover:text-foreground size-4 shrink-0 transition-colors' />\n        </PopoverTrigger>\n        <PopoverContent className='w-auto p-2' align='start'>\n          <AnimatedCalendar mode='range' selected={range} onSelect={setRange} />\n        </PopoverContent>\n      </Popover>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/calendar-date-picker/calendar-date-picker-28.tsx"
    },
    {
      "path": "registry/ndeko/components/calendar-date-picker/_parts/animated-calendar.tsx",
      "content": "'use client';\n\nimport { differenceInCalendarDays } from 'date-fns';\nimport {\n  motion,\n  type TargetAndTransition,\n  type Transition,\n} from 'motion/react';\nimport { useState } from 'react';\nimport {\n  Day,\n  useDayPicker,\n  type DayProps,\n  type MonthProps,\n} from 'react-day-picker';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Calendar } from '@/registry/ndeko/ui/calendar';\n\ntype CalendarProps = React.ComponentProps<typeof Calendar>;\n\ntype ShownMonth = { time: number; direction: number };\n\nconst MONTH_SHIFT_PX = 12;\nconst RANGE_STEP_MS = 12;\nconst RANGE_GROWTH_MAX_MS = 240;\n\nconst MONTH_TRANSITION: Transition = {\n  duration: 0.2,\n  ease: [0.23, 1, 0.32, 1],\n};\n\nconst MONTH_AT_REST: TargetAndTransition = { opacity: 1, x: 0 };\n\nconst SETTLING_DAY_BUTTON = [\n  'transition-[color,background-color,border-radius,box-shadow,scale] ease-(--ease-out-strong) active:scale-90',\n  'group-[.range-middle]:[transition-delay:var(--range-delay),var(--range-delay),0ms,0ms,0ms]',\n].join(' ');\n\nfunction rangeStartOf(selected: unknown) {\n  if (!selected) {\n    return undefined;\n  }\n  if (typeof selected !== 'object') {\n    return undefined;\n  }\n  if (!('from' in selected)) {\n    return undefined;\n  }\n  return selected.from as Date | undefined;\n}\n\nfunction rangeDelayOf(day: Date, rangeStart: Date | undefined) {\n  if (!rangeStart) {\n    return '0ms';\n  }\n  const step = differenceInCalendarDays(day, rangeStart);\n  const delay = Math.min(step * RANGE_STEP_MS, RANGE_GROWTH_MAX_MS);\n  const positiveDelay = Math.max(0, delay);\n  return `${positiveDelay}ms`;\n}\n\nfunction monthEnterOf(direction: number, shouldReduceMotion: boolean | null) {\n  if (direction === 0) {\n    return false;\n  }\n  if (shouldReduceMotion) {\n    return { opacity: 0 };\n  }\n  const offset = direction * MONTH_SHIFT_PX;\n  return { opacity: 0, x: offset };\n}\n\nfunction GrowingRangeDay({ style, ...props }: DayProps) {\n  const { selected } = useDayPicker();\n  const rangeStart = rangeStartOf(selected);\n  const delay = rangeDelayOf(props.day.date, rangeStart);\n  const dayStyle = { ...style, '--range-delay': delay } as React.CSSProperties;\n\n  return <Day {...props} style={dayStyle} />;\n}\n\nfunction SlidingMonth({\n  calendarMonth,\n  displayIndex,\n  children,\n  ...props\n}: MonthProps) {\n  const time = calendarMonth.date.getTime();\n  const [shown, setShown] = useState<ShownMonth>({ time, direction: 0 });\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  if (shown.time !== time) {\n    const direction = Math.sign(time - shown.time);\n    setShown({ time, direction });\n  }\n\n  return (\n    <div data-display-index={displayIndex} {...props}>\n      <AnimatedSize>\n        <motion.div\n          key={time}\n          initial={monthEnterOf(shown.direction, shouldReduceMotion)}\n          animate={MONTH_AT_REST}\n          transition={MONTH_TRANSITION}\n        >\n          {children}\n        </motion.div>\n      </AnimatedSize>\n    </div>\n  );\n}\n\nfunction withSettlingDays(classNames: CalendarProps['classNames']) {\n  const dayButton = cn(SETTLING_DAY_BUTTON, classNames?.day_button);\n  return { ...classNames, day_button: dayButton };\n}\n\n/**\n * The calendar primitive with the date picker micro-interactions: a picked day settles in,\n * a range grows from its start to its end, a new month slides in from the side it comes from\n * and the card resizes to the number of weeks.\n */\nfunction AnimatedCalendar({ classNames, components, ...props }: CalendarProps) {\n  return (\n    <Calendar\n      classNames={withSettlingDays(classNames)}\n      components={{ Day: GrowingRangeDay, Month: SlidingMonth, ...components }}\n      {...props}\n    />\n  );\n}\n\nexport { AnimatedCalendar };\n",
      "type": "registry:component",
      "target": "components/calendar-date-picker/_parts/animated-calendar.tsx"
    },
    {
      "path": "registry/ndeko/components/calendar-date-picker/_parts/swap-text.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst SWAP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\n/** A label that becomes its next value with the swap micro-interaction. */\nfunction SwapText({ text, className }: { text: string; className?: string }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = swapVariantsOf(shouldReduceMotion);\n\n  return (\n    <span className={cn('relative flex min-w-0', className)}>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={text}\n          className='origin-left truncate'\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={SWAP_TRANSITION}\n        >\n          {text}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nexport { SwapText };\n",
      "type": "registry:component",
      "target": "components/calendar-date-picker/_parts/swap-text.tsx"
    }
  ],
  "categories": [
    "components",
    "calendar-date-picker"
  ],
  "type": "registry:component"
}