{
  "schemaVersion": 1,
  "target": "react",
  "name": "date-range-picker",
  "version": "0.1.1",
  "category": "forms",
  "title": "Date Range Picker",
  "description": "A trigger that opens two months with presets and optional start and end times, where the picked range fills in as one band that sweeps from the first day to the last.",
  "tags": [
    "date",
    "range",
    "picker",
    "calendar",
    "presets",
    "time",
    "form",
    "popover"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "motion": "^14.14.0"
  },
  "registryDependencies": [
    {
      "name": "calendar",
      "version": "0.1.0"
    },
    {
      "name": "popover",
      "version": "0.2.2"
    },
    {
      "name": "button",
      "version": "0.2.1"
    },
    {
      "name": "time-picker",
      "version": "0.1.1"
    }
  ],
  "docsPath": "/components/date-range-picker",
  "props": [
    {
      "name": "value / defaultValue / onValueChange",
      "type": "{ from: Date | null; to: Date | null }",
      "description": "The applied range, controlled or not. onValueChange fires on Apply."
    },
    {
      "name": "presets",
      "type": "{ label, range: (today) => { from, to } }[]",
      "default": "defaultRangePresets",
      "description": "Quick ranges in the side column: Today, Last 7 days, Last 30 days, This month, Last month. Custom is always added. Pass [] to hide the column."
    },
    {
      "name": "minDate / maxDate",
      "type": "Date",
      "description": "Bounds for picking and month navigation. Presets that fall outside are turned off."
    },
    {
      "name": "isDateDisabled",
      "type": "(date) => boolean",
      "description": "Days that cannot be picked. A range never spans one."
    },
    {
      "name": "withTime",
      "type": "boolean",
      "default": "false",
      "description": "Adds Starts and Ends time fields; the applied dates carry the times."
    },
    {
      "name": "defaultTimes",
      "type": "{ start: string; end: string }",
      "default": "{ start: \"09:00\", end: \"17:00\" }",
      "description": "Times for a fresh range, as HH:mm."
    },
    {
      "name": "hourCycle",
      "type": "12 | 24",
      "description": "Hour cycle of the time fields and trigger. Defaults to the locale."
    },
    {
      "name": "numberOfMonths",
      "type": "1 | 2",
      "default": "2",
      "description": "Months side by side on wide screens; under 640px it is always one."
    },
    {
      "name": "weekStartsOn / locale / today",
      "type": "number / string / Date",
      "description": "First weekday (defaults to the locale's), BCP 47 locale for names and formatting, and an override for today."
    },
    {
      "name": "placeholder / disabled / id / aria-label / className / align",
      "type": "string / boolean / string / string / string / \"start\" | \"center\" | \"end\"",
      "description": "Trigger text, state, attributes and classes, and the popover alignment."
    }
  ],
  "accessibility": [
    "The trigger is a Base UI Popover trigger (aria-expanded, aria-controls) showing the applied range; opening moves focus to the start day (or today) in the grid, and Escape closes and returns focus to the trigger.",
    "Each month is a role=\"grid\" with rows and gridcells; aria-selected marks days in the range and aria-current=\"date\" marks today. Days have full date labels such as \"Tuesday, November 17, 2026\".",
    "Arrow keys move by day and week, Home and End to the ends of the week, Page Up and Page Down by month (with Shift, by year), crossing into hidden months as needed. Enter or Space picks a day.",
    "Disabled days stay focusable with aria-disabled so arrow keys can pass them, and they are struck through, not only dimmed.",
    "Presets are toggle buttons with aria-pressed; Custom is pressed when the range matches no preset and moves focus into the grid.",
    "The footer summary is a polite live region (\"Nov 17 to 19, 3 days\", or \"Pick an end date\"); Apply stays disabled until the range is complete and the times are valid.",
    "The band sweep and the popover scale play only with motion allowed; with reduced motion the band appears filled at once."
  ],
  "states": [
    "empty",
    "picking end date",
    "hover preview",
    "range picked",
    "with time",
    "disabled days",
    "open"
  ],
  "files": [
    {
      "path": "ui/date-range-picker.tsx",
      "content": "\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { type KeyboardEvent, type ReactNode, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { Button } from \"./button\";\nimport { addDays, addMonths, countDays, type DateRange, isSameDay, startOfDay } from \"./calendar\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\nimport { TimePicker } from \"./time-picker\";\n\nexport type { DateRange } from \"./calendar\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nconst startOfMonth = (date: Date) => new Date(date.getFullYear(), date.getMonth(), 1);\nconst isSameMonth = (a: Date, b: Date) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();\nconst dayKey = (date: Date) => `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;\nconst lastOfMonth = (date: Date) => new Date(date.getFullYear(), date.getMonth() + 1, 0);\n\nfunction localeWeekStart(locale?: string): number {\n  try {\n    const info = new Intl.Locale(locale ?? navigator.language) as Intl.Locale & {\n      getWeekInfo?: () => { firstDay: number };\n      weekInfo?: { firstDay: number };\n    };\n    const firstDay = info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay;\n    if (firstDay) return firstDay % 7;\n  } catch {\n    // Older engines: fall through to Sunday.\n  }\n  return 0;\n}\n\nfunction useWide() {\n  const [wide, setWide] = useState(true);\n  useEffect(() => {\n    const query = window.matchMedia(\"(min-width: 640px)\");\n    const update = () => setWide(query.matches);\n    update();\n    query.addEventListener(\"change\", update);\n    return () => query.removeEventListener(\"change\", update);\n  }, []);\n  return wide;\n}\n\nexport interface RangePreset {\n  label: string;\n  /** Computes the range from today when the preset is shown or picked. */\n  range: (today: Date) => { from: Date; to: Date };\n}\n\n/** Today, Last 7 days, Last 30 days, This month, and Last month. */\nexport const defaultRangePresets: RangePreset[] = [\n  { label: \"Today\", range: (today) => ({ from: today, to: today }) },\n  { label: \"Last 7 days\", range: (today) => ({ from: addDays(today, -6), to: today }) },\n  { label: \"Last 30 days\", range: (today) => ({ from: addDays(today, -29), to: today }) },\n  { label: \"This month\", range: (today) => ({ from: startOfMonth(today), to: today }) },\n  {\n    label: \"Last month\",\n    range: (today) => {\n      const start = addMonths(startOfMonth(today), -1);\n      return { from: start, to: lastOfMonth(start) };\n    },\n  },\n];\n\nconst timeOf = (date: Date | null, fallback: string) =>\n  date && (date.getHours() || date.getMinutes()) ? `${String(date.getHours()).padStart(2, \"0\")}:${String(date.getMinutes()).padStart(2, \"0\")}` : fallback;\n\nfunction withTime(date: Date | null, time: string | null) {\n  if (!date) return null;\n  const [hours, minutes] = (time ?? \"00:00\").split(\":\").map(Number);\n  return new Date(date.getFullYear(), date.getMonth(), date.getDate(), hours ?? 0, minutes ?? 0);\n}\n\nexport interface DateRangePickerProps {\n  /** The applied range. With `withTime`, `from` and `to` carry their times. */\n  value?: DateRange;\n  defaultValue?: DateRange;\n  /** Called when Apply is pressed. */\n  onValueChange?: (range: DateRange) => void;\n  /** Quick ranges in the side column, followed by Custom. Pass `[]` to hide the column. */\n  presets?: RangePreset[];\n  /** Earliest pickable day. Navigation stops at its month. */\n  minDate?: Date;\n  /** Latest pickable day. Navigation stops at its month. */\n  maxDate?: Date;\n  /** Days that cannot be picked. A range never spans one. */\n  isDateDisabled?: (date: Date) => boolean;\n  /** Adds start and end time fields under the months. */\n  withTime?: boolean;\n  /** 12 or 24 for the time fields. Defaults to the locale. */\n  hourCycle?: 12 | 24;\n  /** Default times for a fresh range, \"HH:mm\". */\n  defaultTimes?: { start: string; end: string };\n  /** Months side by side on wide screens. Narrow screens always show one. */\n  numberOfMonths?: 1 | 2;\n  /** First column, 0 for Sunday. Defaults to the locale's first day. */\n  weekStartsOn?: number;\n  /** BCP 47 locale for names and formatting. Defaults to the browser's. */\n  locale?: string;\n  /** Overrides \"today\". */\n  today?: Date;\n  /** Trigger text when nothing is applied. */\n  placeholder?: string;\n  /** Turns the trigger off. */\n  disabled?: boolean;\n  \"aria-label\"?: string;\n  id?: string;\n  /** Classes for the trigger. */\n  className?: string;\n  align?: \"start\" | \"center\" | \"end\";\n}\n\n/**\n * A trigger that opens two months side by side (one on narrow screens) with a preset column and\n * optional start and end times. Picks are a draft until Apply; Escape or Cancel drops them. The\n * committed range fills in as one band that sweeps from the start day to the end day.\n */\nexport function DateRangePicker({\n  value: valueProp,\n  defaultValue,\n  onValueChange,\n  presets = defaultRangePresets,\n  minDate,\n  maxDate,\n  isDateDisabled,\n  withTime: timed = false,\n  hourCycle,\n  defaultTimes = { start: \"09:00\", end: \"17:00\" },\n  numberOfMonths = 2,\n  weekStartsOn: weekStartsOnProp,\n  locale,\n  today: todayProp,\n  placeholder = \"Pick a date range\",\n  disabled = false,\n  id,\n  className,\n  align = \"start\",\n  ...aria\n}: DateRangePickerProps) {\n  const wide = useWide();\n  const months = wide ? numberOfMonths : 1;\n  const [inner, setInner] = useState<DateRange>(defaultValue ?? { from: null, to: null });\n  const value = valueProp ?? inner;\n  const [open, setOpen] = useState(false);\n  const [today, setToday] = useState(() => startOfDay(todayProp ?? new Date()));\n  const [draft, setDraft] = useState<DateRange>({ from: null, to: null });\n  const [times, setTimes] = useState<{ start: string | null; end: string | null }>({ start: defaultTimes.start, end: defaultTimes.end });\n  const [month, setMonth] = useState(() => startOfMonth(value.from ?? today));\n  const [sweep, setSweep] = useState(0);\n  const [weekStartsOn, setWeekStartsOn] = useState(weekStartsOnProp ?? 0);\n  const gridRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => setWeekStartsOn(weekStartsOnProp ?? localeWeekStart(locale)), [weekStartsOnProp, locale]);\n\n  const min = minDate ? startOfDay(minDate) : null;\n  const max = maxDate ? startOfDay(maxDate) : null;\n  const blocked = (date: Date) => (min !== null && date < min) || (max !== null && date > max) || (isDateDisabled?.(date) ?? false);\n\n  function onOpenChange(next: boolean) {\n    if (next) {\n      const now = startOfDay(todayProp ?? new Date());\n      setToday(now);\n      const from = value.from ? startOfDay(value.from) : null;\n      const to = value.to ? startOfDay(value.to) : null;\n      setDraft({ from, to });\n      setTimes({ start: timeOf(value.from, defaultTimes.start), end: timeOf(value.to, defaultTimes.end) });\n      setMonth(from && to ? fitMonths(from, to, now) : startOfMonth(from ?? now));\n    }\n    setOpen(next);\n  }\n\n  /**\n   * The first visible month for a range: the end is always on screen, and a short range leans\n   * toward today's month rather than an empty month after it.\n   */\n  function fitMonths(from: Date, to: Date, now = today) {\n    const toMonth = startOfMonth(to);\n    let right = addMonths(startOfMonth(from), months - 1);\n    const ceiling = startOfMonth(now) > toMonth ? startOfMonth(now) : toMonth;\n    if (right > ceiling) right = ceiling;\n    if (right < toMonth) right = toMonth;\n    return addMonths(right, -(months - 1));\n  }\n\n  function commitDraft(next: DateRange, animate: boolean) {\n    setDraft(next);\n    if (animate && next.from && next.to) setSweep((count) => count + 1);\n  }\n\n  function pickPreset(preset: RangePreset) {\n    const range = preset.range(today);\n    commitDraft({ from: startOfDay(range.from), to: startOfDay(range.to) }, true);\n    setMonth(fitMonths(range.from, range.to));\n  }\n\n  function apply() {\n    const next = timed ? { from: withTime(draft.from, times.start), to: withTime(draft.to, times.end) } : draft;\n    if (valueProp === undefined) setInner(next);\n    onValueChange?.(next);\n    setOpen(false);\n  }\n\n  const presetState = presets.map((preset) => {\n    const range = preset.range(today);\n    const outside = blocked(startOfDay(range.from)) || blocked(startOfDay(range.to));\n    const active = isSameDay(range.from, draft.from) && isSameDay(range.to, draft.to);\n    return { preset, outside, active };\n  });\n  const customActive = !!draft.from && !presetState.some((item) => item.active);\n\n  const longFormat = useMemo(\n    () => new Intl.DateTimeFormat(locale, { month: \"short\", day: \"numeric\", year: \"numeric\", ...(timed ? { hour: \"numeric\", minute: \"2-digit\", hourCycle: hourCycle === 12 ? \"h12\" : hourCycle === 24 ? \"h23\" : undefined } : {}) }),\n    [locale, timed, hourCycle],\n  );\n  const shortFormat = useMemo(() => new Intl.DateTimeFormat(locale, { month: \"short\", day: \"numeric\" }), [locale]);\n\n  const triggerLabel = value.from && value.to ? longFormat.formatRange(value.from, value.to) : null;\n  const days = draft.from && draft.to ? countDays(draft.from, draft.to) : 0;\n  const summary = draft.from && draft.to ? `${shortFormat.formatRange(draft.from, draft.to)}, ${days} ${days === 1 ? \"day\" : \"days\"}` : draft.from ? \"Pick an end date\" : \"Pick a start date\";\n  const timesValid = !timed || (times.start !== null && times.end !== null && !(draft.from && draft.to && isSameDay(draft.from, draft.to) && times.start > times.end));\n\n  return (\n    <Popover open={open} onOpenChange={onOpenChange}>\n      <PopoverTrigger\n        id={id}\n        disabled={disabled}\n        aria-label={aria[\"aria-label\"] ? `${aria[\"aria-label\"]}${triggerLabel ? `, ${triggerLabel}` : \"\"}` : undefined}\n        render={<Button variant=\"secondary\" />}\n        className={cx(\n          \"min-w-60 justify-start px-3 font-normal tabular-nums data-[popup-open]:border-zinc-950/20 dark:data-[popup-open]:border-white/25\",\n          className,\n        )}\n      >\n        <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className=\"text-zinc-500\">\n          <rect x=\"2.25\" y=\"3.25\" width=\"11.5\" height=\"10.5\" rx=\"2\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n          <path d=\"M2.5 6.75h11M5.5 1.75v3M10.5 1.75v3\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n        </svg>\n        {/* Intl output can differ by a space between server and browser. */}\n        <span suppressHydrationWarning className={cx(\"truncate\", !triggerLabel && \"text-zinc-500\")}>\n          {triggerLabel ?? placeholder}\n        </span>\n      </PopoverTrigger>\n      <PopoverContent\n        align={align}\n        initialFocus={() => gridRef.current?.querySelector<HTMLElement>('button[tabindex=\"0\"]') ?? true}\n        className=\"w-auto max-w-[calc(100vw-2rem)] p-0\"\n      >\n        <div className={cx(\"flex\", presets.length > 0 && \"max-sm:flex-col\")}>\n          {presets.length > 0 ? (\n            <div\n              role=\"group\"\n              aria-label=\"Presets\"\n              className={cx(\n                \"flex gap-0.5 border-zinc-950/[0.07] p-2 dark:border-white/[0.08]\",\n                \"max-sm:w-0 max-sm:min-w-full max-sm:overflow-x-auto max-sm:border-b sm:w-36 sm:flex-col sm:border-r\",\n              )}\n            >\n              {presetState.map(({ preset, outside, active }) => (\n                <PresetButton key={preset.label} active={active} disabled={outside} onClick={() => pickPreset(preset)}>\n                  {preset.label}\n                </PresetButton>\n              ))}\n              <PresetButton\n                active={customActive}\n                onClick={() => gridRef.current?.querySelector<HTMLElement>('button[tabindex=\"0\"]')?.focus()}\n              >\n                Custom\n              </PresetButton>\n            </div>\n          ) : null}\n          <div className=\"grid min-w-0\">\n            <div ref={gridRef} className=\"p-3\">\n              <RangeMonths\n                month={month}\n                onMonthChange={setMonth}\n                count={months}\n                draft={draft}\n                onDraftChange={commitDraft}\n                blocked={blocked}\n                min={min}\n                max={max}\n                today={today}\n                weekStartsOn={weekStartsOn}\n                locale={locale}\n                sweep={sweep}\n              />\n            </div>\n            {timed ? (\n              <div className=\"flex flex-wrap items-center gap-x-4 gap-y-2 border-t border-zinc-950/[0.07] px-4 py-3 dark:border-white/[0.08]\">\n                <TimeRow label=\"Starts\" value={times.start} hourCycle={hourCycle} locale={locale} onChange={(start) => setTimes((t) => ({ ...t, start }))} />\n                <TimeRow\n                  label=\"Ends\"\n                  value={times.end}\n                  hourCycle={hourCycle}\n                  locale={locale}\n                  invalid={!timesValid}\n                  onChange={(end) => setTimes((t) => ({ ...t, end }))}\n                />\n              </div>\n            ) : null}\n            <div className=\"flex items-center gap-2 border-t border-zinc-950/[0.07] py-2.5 ps-4 pe-2.5 dark:border-white/[0.08]\">\n              <p aria-live=\"polite\" className=\"min-w-0 truncate text-xs text-zinc-500 tabular-nums\">\n                {!timesValid && draft.from && draft.to ? <span className=\"text-red-600 dark:text-red-400\">End time is before the start</span> : summary}\n              </p>\n              <Button variant=\"ghost\" size=\"sm\" className=\"ms-auto\" onClick={() => setOpen(false)}>\n                Cancel\n              </Button>\n              <Button size=\"sm\" disabled={!draft.from || !draft.to || !timesValid} onClick={apply}>\n                Apply\n              </Button>\n            </div>\n          </div>\n        </div>\n      </PopoverContent>\n    </Popover>\n  );\n}\n\nfunction TimeRow({\n  label,\n  value,\n  hourCycle,\n  locale,\n  invalid,\n  onChange,\n}: {\n  label: string;\n  value: string | null;\n  hourCycle?: 12 | 24;\n  locale?: string;\n  invalid?: boolean;\n  onChange: (value: string | null) => void;\n}) {\n  const labelId = useId();\n  return (\n    <div className=\"flex items-center gap-2.5\">\n      <span id={labelId} className=\"w-11 text-xs font-medium text-zinc-500\">\n        {label}\n      </span>\n      <TimePicker aria-labelledby={labelId} value={value} onValueChange={onChange} hourCycle={hourCycle} locale={locale} invalid={invalid} className=\"h-8\" />\n    </div>\n  );\n}\n\nfunction PresetButton({\n  active,\n  disabled,\n  onClick,\n  className,\n  children,\n}: {\n  active: boolean;\n  disabled?: boolean;\n  onClick: () => void;\n  className?: string;\n  children: ReactNode;\n}) {\n  return (\n    <button\n      type=\"button\"\n      aria-pressed={active}\n      disabled={disabled}\n      onClick={onClick}\n      className={cx(\n        \"h-8 shrink-0 rounded-md px-2.5 text-left text-sm whitespace-nowrap\",\n        \"transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none\",\n        \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n        \"disabled:pointer-events-none disabled:opacity-40\",\n        active\n          ? \"bg-zinc-950/[0.06] font-medium text-zinc-950 dark:bg-white/[0.09] dark:text-white\"\n          : \"text-zinc-600 hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:text-zinc-400 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n        className,\n      )}\n    >\n      {children}\n    </button>\n  );\n}\n\nconst EASE = [0.23, 1, 0.32, 1] as const;\n\nfunction RangeMonths({\n  month,\n  onMonthChange,\n  count,\n  draft,\n  onDraftChange,\n  blocked,\n  min,\n  max,\n  today,\n  weekStartsOn,\n  locale,\n  sweep,\n}: {\n  month: Date;\n  onMonthChange: (month: Date) => void;\n  count: number;\n  draft: DateRange;\n  onDraftChange: (range: DateRange, animate: boolean) => void;\n  blocked: (date: Date) => boolean;\n  min: Date | null;\n  max: Date | null;\n  today: Date;\n  weekStartsOn: number;\n  locale?: string;\n  sweep: number;\n}) {\n  const reduce = useReducedMotion();\n  const [focused, setFocused] = useState<Date>(() => draft.from ?? today);\n  const [hovered, setHovered] = useState<Date | null>(null);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const shouldFocus = useRef(false);\n  // The sweep plays once per commit; rows that mount later (after paging) appear filled.\n  const played = useRef(sweep);\n  const playing = sweep !== played.current;\n  useEffect(() => {\n    played.current = sweep;\n  });\n  useEffect(() => {\n    if (!shouldFocus.current) return;\n    shouldFocus.current = false;\n    rootRef.current?.querySelector<HTMLButtonElement>('button[tabindex=\"0\"]')?.focus();\n  });\n\n  const visible = Array.from({ length: count }, (_, index) => addMonths(month, index));\n  const firstVisible = visible[0]!;\n  const lastVisible = lastOfMonth(visible[visible.length - 1]!);\n  const canPrev = !min || startOfMonth(min) < month;\n  const canNext = !max || startOfMonth(max) > visible[visible.length - 1]!;\n\n  function select(date: Date) {\n    if (blocked(date)) return;\n    setFocused(date);\n    let next: DateRange;\n    if (!draft.from || draft.to) next = { from: date, to: null };\n    else if (date < draft.from) next = { from: date, to: draft.from };\n    else next = { from: draft.from, to: date };\n    if (next.from && next.to) {\n      for (let day = next.from; day <= next.to; day = addDays(day, 1)) {\n        if (blocked(day)) {\n          next = { from: date, to: null };\n          break;\n        }\n      }\n    }\n    onDraftChange(next, true);\n  }\n\n  function moveFocus(target: Date) {\n    let next = target;\n    if (min && next < min) next = min;\n    if (max && next > max) next = max;\n    setFocused(next);\n    if (next < firstVisible) onMonthChange(startOfMonth(next));\n    else if (next > lastVisible) onMonthChange(addMonths(startOfMonth(next), -(count - 1)));\n    shouldFocus.current = true;\n  }\n\n  function onKeyDown(event: KeyboardEvent<HTMLDivElement>) {\n    const column = (focused.getDay() - weekStartsOn + 7) % 7;\n    const moves: Record<string, () => Date> = {\n      ArrowLeft: () => addDays(focused, -1),\n      ArrowRight: () => addDays(focused, 1),\n      ArrowUp: () => addDays(focused, -7),\n      ArrowDown: () => addDays(focused, 7),\n      Home: () => addDays(focused, -column),\n      End: () => addDays(focused, 6 - column),\n      PageUp: () => addMonths(focused, event.shiftKey ? -12 : -1),\n      PageDown: () => addMonths(focused, event.shiftKey ? 12 : 1),\n    };\n    const move = moves[event.key];\n    if (!move) return;\n    event.preventDefault();\n    moveFocus(move());\n  }\n\n  const monthFormat = useMemo(() => new Intl.DateTimeFormat(locale, { month: \"long\", year: \"numeric\" }), [locale]);\n  const dayFormat = useMemo(() => new Intl.DateTimeFormat(locale, { weekday: \"long\", month: \"long\", day: \"numeric\", year: \"numeric\" }), [locale]);\n  const weekdays = useMemo(() => {\n    const short = new Intl.DateTimeFormat(locale, { weekday: \"short\" });\n    const long = new Intl.DateTimeFormat(locale, { weekday: \"long\" });\n    return Array.from({ length: 7 }, (_, index) => {\n      const date = new Date(2023, 0, 1 + ((index + weekStartsOn) % 7));\n      return { short: short.format(date).slice(0, 2), long: long.format(date) };\n    });\n  }, [locale, weekStartsOn]);\n\n  // Hovering a day the range could not reach (a disabled day in between) previews nothing.\n  let preview = draft.from && !draft.to && hovered ? (hovered < draft.from ? { from: hovered, to: draft.from } : { from: draft.from, to: hovered }) : null;\n  if (preview) {\n    for (let day = preview.from; day <= preview.to; day = addDays(day, 1)) {\n      if (blocked(day)) {\n        preview = null;\n        break;\n      }\n    }\n  }\n  const committed = draft.from && draft.to ? { from: draft.from, to: draft.to } : null;\n  const span = preview ?? committed;\n\n  // The visible part of the committed range sets the sweep's pace: about 14ms a day, 480ms at most.\n  const sweepFrom = committed ? (committed.from < firstVisible ? firstVisible : committed.from) : null;\n  const sweepTo = committed ? (committed.to > lastVisible ? lastVisible : committed.to) : null;\n  const sweepDays = sweepFrom && sweepTo && sweepFrom <= sweepTo ? countDays(sweepFrom, sweepTo) : 0;\n  const sweepTotal = Math.min(480, 200 + sweepDays * 14) / 1000;\n\n  const focusTarget = visible.some((m) => isSameMonth(m, focused)) ? focused : draft.from && visible.some((m) => isSameMonth(m, draft.from!)) ? draft.from : firstVisible;\n\n  return (\n    <div\n      ref={rootRef}\n      data-slot=\"range-months\"\n      className={cx(\"grid gap-4 text-sm text-zinc-950 dark:text-white\", count === 2 && \"sm:grid-cols-2 sm:gap-6\")}\n    >\n      {visible.map((shown, monthIndex) => {\n        const first = startOfMonth(shown);\n        const offset = (first.getDay() - weekStartsOn + 7) % 7;\n        const gridStart = addDays(first, -offset);\n        const weeks = Array.from({ length: 6 }, (_, row) => Array.from({ length: 7 }, (_, col) => addDays(gridStart, row * 7 + col)));\n        const titleId = `range-${dayKey(first)}-title`;\n        return (\n          <div key={dayKey(first)} className=\"grid w-[15.75rem] content-start gap-2\">\n            <div className=\"relative flex h-8 items-center justify-center\">\n              {monthIndex === 0 ? (\n                <NavButton label=\"Previous month\" disabled={!canPrev} onClick={() => onMonthChange(addMonths(month, -1))} className=\"absolute left-0\">\n                  <path d=\"M10 3.5 5.5 8l4.5 4.5\" />\n                </NavButton>\n              ) : null}\n              <h2 id={titleId} aria-live=\"polite\" className=\"text-sm font-semibold\">\n                {monthFormat.format(shown)}\n              </h2>\n              {monthIndex === count - 1 ? (\n                <NavButton label=\"Next month\" disabled={!canNext} onClick={() => onMonthChange(addMonths(month, 1))} className=\"absolute right-0\">\n                  <path d=\"M6 3.5 10.5 8 6 12.5\" />\n                </NavButton>\n              ) : null}\n            </div>\n            <div role=\"grid\" aria-labelledby={titleId} aria-multiselectable onKeyDown={onKeyDown} onPointerLeave={() => setHovered(null)} className=\"grid gap-0.5\">\n              <div role=\"row\" className=\"grid grid-cols-7\">\n                {weekdays.map((weekday) => (\n                  <div key={weekday.long} role=\"columnheader\" aria-label={weekday.long} className=\"flex h-8 items-center justify-center text-xs text-zinc-500\">\n                    {weekday.short}\n                  </div>\n                ))}\n              </div>\n              {weeks.map((week, row) => {\n                // This row's slice of the span, inside the month.\n                const inRow = week.map((date, col) => ({ date, col })).filter(({ date }) => isSameMonth(date, shown) && span && date >= span.from && date <= span.to);\n                const band = inRow.length > 0 ? { start: inRow[0]!, end: inRow[inRow.length - 1]! } : null;\n                if (week.every((date) => !isSameMonth(date, shown)) && row > 3) return <div key={row} role=\"row\" aria-hidden=\"true\" className=\"h-9\" />;\n                let bandNode: ReactNode = null;\n                if (band) {\n                  const style = { left: `${(band.start.col / 7) * 100}%`, width: `${((band.end.col - band.start.col + 1) / 7) * 100}%` };\n                  if (preview) {\n                    bandNode = <span aria-hidden=\"true\" className=\"absolute inset-y-0 rounded-lg bg-zinc-950/[0.035] dark:bg-white/[0.05]\" style={style} />;\n                  } else {\n                    const delay = sweepFrom && sweepDays ? ((countDays(sweepFrom, band.start.date) - 1) / sweepDays) * sweepTotal : 0;\n                    const duration = (inRow.length / Math.max(1, sweepDays)) * sweepTotal;\n                    const isLast = sweepTo !== null && isSameDay(band.end.date, sweepTo);\n                    const isFirst = sweepFrom !== null && isSameDay(band.start.date, sweepFrom);\n                    bandNode = (\n                      <motion.span\n                        key={`${sweep}-${dayKey(band.start.date)}`}\n                        aria-hidden=\"true\"\n                        className=\"absolute inset-y-0 rounded-lg bg-zinc-950/[0.06] dark:bg-white/[0.09]\"\n                        style={style}\n                        initial={playing && !reduce ? { clipPath: \"inset(0 100% 0 0 round 8px)\" } : false}\n                        animate={{ clipPath: \"inset(0 0% 0 0 round 8px)\" }}\n                        transition={{ duration, delay, ease: isFirst && isLast ? EASE : isLast ? \"easeOut\" : \"linear\" }}\n                      />\n                    );\n                  }\n                }\n                return (\n                  <div key={row} role=\"row\" className=\"relative grid grid-cols-7\">\n                    {bandNode}\n                    {week.map((date) => {\n                      const outside = !isSameMonth(date, shown);\n                      if (outside) return <div key={dayKey(date)} role=\"gridcell\" aria-hidden=\"true\" className=\"h-9\" />;\n                      const isBlocked = blocked(date);\n                      const isToday = isSameDay(date, today);\n                      const isEndpoint = isSameDay(date, draft.from) || isSameDay(date, draft.to) || (!!preview && isSameDay(date, hovered));\n                      const solid = isSameDay(date, draft.from) || isSameDay(date, draft.to);\n                      const inCommitted = !!committed && date >= committed.from && date <= committed.to;\n                      return (\n                        <div key={dayKey(date)} role=\"gridcell\" aria-selected={inCommitted} className=\"relative z-[1] flex h-9 items-center justify-center\">\n                          <button\n                            type=\"button\"\n                            tabIndex={isSameDay(date, focusTarget) ? 0 : -1}\n                            aria-label={dayFormat.format(date)}\n                            aria-current={isToday ? \"date\" : undefined}\n                            aria-disabled={isBlocked || undefined}\n                            onClick={() => select(date)}\n                            onPointerEnter={() => setHovered(date)}\n                            onFocus={() => setFocused(date)}\n                            className={cx(\n                              \"relative flex size-9 items-center justify-center rounded-lg text-sm tabular-nums\",\n                              \"transition-[background-color,color,box-shadow] duration-150 ease-out motion-reduce:transition-none\",\n                              \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-1 focus-visible:outline-sky-500\",\n                              solid\n                                ? \"bg-zinc-950 font-medium text-white dark:bg-white dark:text-black\"\n                                : isBlocked\n                                  ? \"cursor-not-allowed text-zinc-400 line-through decoration-zinc-950/25 dark:text-zinc-600 dark:decoration-white/25\"\n                                  : cx(\n                                      span && date >= span.from && date <= span.to ? \"text-zinc-950 dark:text-white\" : \"text-zinc-700 dark:text-zinc-300\",\n                                      isEndpoint && \"shadow-[inset_0_0_0_1px_rgb(9_9_11/0.25)] dark:shadow-[inset_0_0_0_1px_rgb(255_255_255/0.3)]\",\n                                      \"hover:bg-zinc-950/[0.05] hover:text-zinc-950 dark:hover:bg-white/[0.08] dark:hover:text-white\",\n                                    ),\n                              isToday && !solid && \"font-semibold\",\n                            )}\n                          >\n                            {date.getDate()}\n                            {isToday ? <span aria-hidden=\"true\" className={cx(\"absolute bottom-1.5 size-1 rounded-full\", solid ? \"bg-white dark:bg-black\" : \"bg-sky-500\")} /> : null}\n                          </button>\n                        </div>\n                      );\n                    })}\n                  </div>\n                );\n              })}\n            </div>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n\nfunction NavButton({ label, disabled, onClick, className, children }: { label: string; disabled?: boolean; onClick: () => void; className?: string; children: ReactNode }) {\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      disabled={disabled}\n      onClick={onClick}\n      className={cx(\n        \"inline-flex size-8 items-center justify-center rounded-lg text-zinc-600 dark:text-zinc-400\",\n        \"transition-[background-color,color,scale] duration-150 ease-out active:duration-100 motion-safe:active:scale-[0.94] motion-reduce:transition-none\",\n        \"hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n        \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-0 focus-visible:outline-sky-500\",\n        \"disabled:pointer-events-none disabled:opacity-35\",\n        className,\n      )}\n    >\n      <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-4\">\n        {children}\n      </svg>\n    </button>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { addDays, startOfDay } from \"@/components/shaken/ui/calendar\";\nimport { DateRangePicker } from \"@/components/shaken/ui/date-range-picker\";\n\n// Usage exports can only go back 90 days; weekends are frozen for the maintenance window.\nconst today = startOfDay(new Date());\n\nexport default function DateRangePickerExample() {\n  return (\n    <div className=\"flex flex-wrap items-end justify-center gap-6\">\n      <div className=\"grid gap-1.5\">\n        <label htmlFor=\"export-range\" className=\"text-sm font-medium text-zinc-950 dark:text-white\">\n          Export usage for\n        </label>\n        <DateRangePicker\n          id=\"export-range\"\n          defaultValue={{ from: addDays(today, -6), to: today }}\n          minDate={addDays(today, -90)}\n          maxDate={today}\n        />\n      </div>\n      <div className=\"grid gap-1.5\">\n        <label htmlFor=\"maintenance-window\" className=\"text-sm font-medium text-zinc-950 dark:text-white\">\n          Maintenance window\n        </label>\n        <DateRangePicker\n          id=\"maintenance-window\"\n          withTime\n          presets={[]}\n          minDate={today}\n          isDateDisabled={(date) => date.getDay() === 0 || date.getDay() === 6}\n          defaultTimes={{ start: \"22:00\", end: \"23:30\" }}\n          placeholder=\"Schedule downtime\"\n        />\n      </div>\n    </div>\n  );\n}\n"
  }
}
