{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-time-picker",
  "type": "registry:ui",
  "title": "Date time picker",
  "description": "React date and time picker in one popover: a calendar and a scrollable time list, 5 to 30 minute steps, past times disabled and a 12 or 24 hour clock.",
  "author": "MiniDev UI <https://ui.minidev.pro>",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ui.minidev.pro/r/button.json",
    "https://ui.minidev.pro/r/calendar.json",
    "https://ui.minidev.pro/r/popover.json",
    "utils"
  ],
  "files": [
    {
      "path": "registry/ui/date-time-picker.tsx",
      "type": "registry:ui",
      "target": "components/ui/date-time-picker.tsx",
      "content": "\"use client\"\nimport * as React from \"react\"\nimport { CalendarClockIcon } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/components/ui/button\"\nimport { Calendar } from \"@/components/ui/calendar\"\nimport { Popover, PopoverContent, PopoverTrigger } from \"@/components/ui/popover\"\n\n/**\n * DateTimePicker — one field for a date and a time: a calendar and a time list in a popover, with past times disabled on today.\n *\n * Use it for meetings, scheduled sends, deploy windows and deadlines, anywhere a single moment matters. The value is a `Date`\n * (or `null` when empty). Pass `min={new Date()}` to block past days and the past slots of today; slots are `minuteStep`\n * minutes apart. The trigger shows the value through `Intl.DateTimeFormat` (medium date, short time), and the time list follows\n * the locale's 12 or 24 hour clock unless `hour12` is set. Pass `name` to submit it with a form as an ISO string. For a date\n * alone use Calendar or DatePicker; for a time alone use TimePicker.\n *\n * @example\n * const [when, setWhen] = React.useState<Date | null>(null)\n * <DateTimePicker value={when} onValueChange={setWhen} min={new Date()} minuteStep={30} timeZoneLabel=\"Europe/Berlin\" aria-label=\"Send at\" />\n */\n\ntype DateTimePickerProps = {\n  /** Controlled value, or `null` for empty. */\n  value?: Date | null\n  /** Starting value when uncontrolled. */\n  defaultValue?: Date | null\n  /** Fires with the new Date, or `null` after Clear. */\n  onValueChange?: (value: Date | null) => void\n  /** Minutes between time slots. */\n  minuteStep?: 5 | 15 | 30\n  /** Force a 12 or 24 hour clock. Defaults to the locale's clock. */\n  hour12?: boolean\n  /** Earliest moment. Days before it and earlier slots on its day are disabled. */\n  min?: Date\n  /** Latest moment. Days after it and later slots on its day are disabled. */\n  max?: Date\n  /** Disable the trigger. */\n  disabled?: boolean\n  /** Trigger text while empty. */\n  placeholder?: string\n  /** Time zone note in the popover footer, such as \"Times in Europe/Berlin\". */\n  timeZoneLabel?: string\n  /** BCP 47 locale for the trigger, the calendar and the time labels. */\n  locale?: string\n  /** First column of the calendar week: 0 is Sunday, 1 is Monday. */\n  weekStartsOn?: 0 | 1\n  /** Form field name. Submits the value as an ISO 8601 string in UTC, or \"\" when empty. */\n  name?: string\n  /** Id for a `<label htmlFor>` or FormField. */\n  id?: string\n  className?: string\n  /** What the moment is for, such as \"Send at\". The value is appended to it. */\n  \"aria-label\"?: string\n}\n\nconst at = (d: Date, mins: number) => new Date(d.getFullYear(), d.getMonth(), d.getDate(), Math.floor(mins / 60), mins % 60)\nconst minsOf = (d: Date) => d.getHours() * 60 + d.getMinutes()\nconst noSubscribe = () => () => {}\n\nfunction DateTimePicker({\n  value,\n  defaultValue = null,\n  onValueChange,\n  minuteStep = 15,\n  hour12,\n  min,\n  max,\n  disabled = false,\n  placeholder = \"Pick a date and time\",\n  timeZoneLabel,\n  locale = \"en-US\",\n  weekStartsOn = 0,\n  name,\n  id,\n  className,\n  \"aria-label\": ariaLabel,\n}: DateTimePickerProps) {\n  const [inner, setInner] = React.useState(defaultValue)\n  const [open, setOpen] = React.useState(false)\n  // Read the clock when the popover opens, not during render, so server and client agree.\n  const [now, setNow] = React.useState<Date | null>(null)\n  const [active, setActive] = React.useState(0)\n  const list = React.useRef<HTMLDivElement>(null)\n  const typed = React.useRef({ text: \"\", at: 0 })\n  const listId = React.useId()\n  const current = value !== undefined ? value : inner\n  // False on the server and during hydration: the server's time zone may differ from the browser's, so the\n  // trigger text and the hidden input are only filled in the browser.\n  const hydrated = React.useSyncExternalStore(noSubscribe, () => true, () => false)\n\n  const fmt = React.useMemo(() => {\n    const h12 = hour12 ?? [\"h11\", \"h12\"].includes(new Intl.DateTimeFormat(locale, { hour: \"numeric\" }).resolvedOptions().hourCycle ?? \"\")\n    return {\n      trigger: new Intl.DateTimeFormat(locale, { dateStyle: \"medium\", timeStyle: \"short\", hour12: h12 }),\n      slot: new Intl.DateTimeFormat(locale, { hour: \"numeric\", minute: \"2-digit\", hour12: h12 }),\n    }\n  }, [locale, hour12])\n\n  const base = current ?? now\n  const slots = React.useMemo(() => Array.from({ length: 1440 / minuteStep }, (_, i) => i * minuteStep), [minuteStep])\n  const outOfRange = (d: Date) => (min ? d < min : false) || (max ? d > max : false)\n  const slotOff = (mins: number) => !base || outOfRange(at(base, mins))\n  const labels = React.useMemo(() => slots.map((m) => fmt.slot.format(at(new Date(2026, 0, 1), m))), [slots, fmt])\n  const selected = current ? slots.indexOf(minsOf(current)) : -1\n\n  const commit = (next: Date | null) => {\n    if (value === undefined) setInner(next)\n    onValueChange?.(next)\n  }\n  const scrollTo = (i: number, center = false) => {\n    const el = list.current?.children[i] as HTMLElement | undefined\n    const box = list.current\n    if (!el || !box) return\n    if (center) box.scrollTop = el.offsetTop - box.clientHeight / 2 + el.offsetHeight / 2\n    else if (el.offsetTop < box.scrollTop) box.scrollTop = el.offsetTop\n    else if (el.offsetTop + el.offsetHeight > box.scrollTop + box.clientHeight) box.scrollTop = el.offsetTop + el.offsetHeight - box.clientHeight\n  }\n  const go = (i: number) => {\n    setActive(i)\n    scrollTo(i)\n  }\n\n  // Centre the selected slot (or 9:00, or the first free one) each time the popover opens.\n  React.useEffect(() => {\n    if (!open) return\n    const id = requestAnimationFrame(() => scrollTo(active, true))\n    return () => cancelAnimationFrame(id)\n    // eslint-disable-next-line react-hooks/exhaustive-deps -- only on open\n  }, [open])\n\n  const onOpenChange = (o: boolean) => {\n    setOpen(o)\n    if (!o) return\n    const n = new Date()\n    setNow(n)\n    const b = current ?? n\n    const free = (m: number) => !outOfRange(at(b, m))\n    setActive(selected >= 0 ? selected : Math.max(0, slots.findIndex((m) => m >= 540 && free(m)), slots.findIndex(free)))\n  }\n  const pickDay = (d: Date) => {\n    let next = at(d, current ? minsOf(current) : 540)\n    if (outOfRange(next)) {\n      const m = slots.find((s) => !outOfRange(at(d, s)))\n      if (m === undefined) return\n      next = at(d, m)\n    }\n    commit(next)\n    setActive(slots.indexOf(minsOf(next)))\n  }\n  const pickTime = (i: number) => {\n    if (!base || slotOff(slots[i])) return\n    commit(at(base, slots[i]))\n    setOpen(false)\n  }\n  const onListKey = (e: React.KeyboardEvent) => {\n    const free = slots.map((_, i) => i).filter((i) => !slotOff(slots[i]))\n    const pos = free.findIndex((i) => i >= active)\n    const to: Record<string, number | undefined> = {\n      ArrowDown: free[free[pos] === active ? pos + 1 : pos],\n      ArrowUp: free[(pos === -1 ? free.length : pos) - 1],\n      Home: free[0],\n      End: free[free.length - 1],\n    }\n    if (e.key in to) {\n      e.preventDefault()\n      if (to[e.key] !== undefined) go(to[e.key]!)\n    } else if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault()\n      pickTime(active)\n    } else if (e.key.length === 1 && /\\w/.test(e.key) && !e.metaKey && !e.ctrlKey) {\n      // Type-ahead: \"9\" jumps to 9:00, \"93\" to 9:30, \"14\" to 14:00. Keys typed within 600ms add up.\n      const t = Date.now()\n      typed.current = { text: (t - typed.current.at < 600 ? typed.current.text : \"\") + e.key.toLowerCase(), at: t }\n      const want = typed.current.text\n      const hit = free.find((i) => [labels[i], labels[i].replace(/^0/, \"\")].some((l) => l.toLowerCase().replace(\":\", \"\").startsWith(want.replace(\":\", \"\"))))\n      if (hit !== undefined) go(hit)\n    }\n  }\n\n  const text = current && hydrated ? fmt.trigger.format(current) : null\n  const nowSlot = now ? slots.find((m) => m >= minsOf(now)) : undefined\n  const nowValue = now && nowSlot !== undefined ? at(now, nowSlot) : null\n\n  return (\n    <div data-slot=\"date-time-picker\" className={cn(\"inline-flex\", className)}>\n      {name ? <input type=\"hidden\" name={name} value={current && hydrated ? current.toISOString() : \"\"} /> : null}\n      <Popover open={open} onOpenChange={onOpenChange}>\n        <PopoverTrigger\n          id={id}\n          disabled={disabled}\n          aria-label={ariaLabel ? `${ariaLabel}: ${text ?? placeholder}` : undefined}\n          render={<Button variant=\"outline\" className=\"w-full min-w-60 justify-start font-normal tabular-nums\" />}\n        >\n          <CalendarClockIcon aria-hidden />\n          <span className={cn(\"truncate\", !text && \"text-fg-subtle\", current && !hydrated && \"invisible\")}>{text ?? placeholder}</span>\n        </PopoverTrigger>\n        <PopoverContent\n          align=\"start\"\n          className=\"w-auto max-w-[calc(100vw-2rem)] p-3\"\n          initialFocus={() => list.current?.closest(\"[data-slot=popover-content]\")?.querySelector<HTMLElement>(\"[data-day][tabindex='0']\") ?? true}\n        >\n          <div className=\"flex flex-col gap-3 sm:flex-row\">\n            <Calendar\n              value={current}\n              onValueChange={pickDay}\n              min={min}\n              max={max}\n              locale={locale}\n              weekStartsOn={weekStartsOn}\n              className=\"p-0\"\n            />\n            <div className=\"flex min-w-0 flex-col gap-2 border-t border-border pt-3 sm:w-28 sm:border-t-0 sm:border-l sm:pt-0 sm:pl-3\">\n              <div id={`${listId}-label`} className=\"flex h-8 items-center text-xs font-medium text-fg-muted\">Time</div>\n              <div\n                ref={list}\n                role=\"listbox\"\n                tabIndex={0}\n                aria-labelledby={`${listId}-label`}\n                aria-activedescendant={`${listId}-${active}`}\n                onKeyDown={onListKey}\n                className=\"group/list relative h-40 overflow-y-auto rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-accent sm:h-71\"\n              >\n                {slots.map((m, i) => {\n                  const off = slotOff(m)\n                  const on = i === selected\n                  return (\n                    <div\n                      key={m}\n                      id={`${listId}-${i}`}\n                      role=\"option\"\n                      aria-selected={on}\n                      aria-disabled={off || undefined}\n                      data-active={i === active || undefined}\n                      onClick={() => pickTime(i)}\n                      onPointerMove={() => !off && i !== active && setActive(i)}\n                      className={cn(\n                        \"flex h-8 cursor-pointer items-center rounded-md px-2.5 text-[0.8125rem] tabular-nums select-none transition-[background-color,color] duration-[70ms] ease-hairline\",\n                        on ? \"bg-accent font-medium text-on-accent\" : \"text-fg hover:bg-sunken group-focus/list:data-active:bg-sunken\",\n                        off && \"cursor-not-allowed text-fg-subtle opacity-50 hover:bg-transparent\"\n                      )}\n                    >\n                      {labels[i]}\n                    </div>\n                  )\n                })}\n              </div>\n            </div>\n          </div>\n          <div className=\"flex items-center gap-2 border-t border-border pt-2.5\">\n            <span className=\"min-w-0 flex-1 truncate text-xs text-fg-subtle\">{timeZoneLabel}</span>\n            <Button variant=\"ghost\" size=\"sm\" disabled={!current} onClick={() => commit(null)}>\n              Clear\n            </Button>\n            <Button\n              variant=\"outline\"\n              size=\"sm\"\n              disabled={!nowValue || outOfRange(nowValue)}\n              onClick={() => {\n                if (!nowValue) return\n                commit(nowValue)\n                setOpen(false)\n              }}\n            >\n              Now\n            </Button>\n          </div>\n        </PopoverContent>\n      </Popover>\n    </div>\n  )\n}\n\nexport { DateTimePicker }\nexport type { DateTimePickerProps }\n"
    }
  ],
  "categories": [
    "forms"
  ],
  "docs": "import { DateTimePicker } from \"@/components/ui/date-time-picker\"\nNeeds the MiniDev tokens stylesheet (https://ui.minidev.pro/r/styles.css) imported after Tailwind.\nDocs: https://ui.minidev.pro/docs/date-time-picker · Markdown for agents: https://ui.minidev.pro/docs/date-time-picker.md",
  "meta": {
    "tier": "free",
    "kind": "ui",
    "category": "forms",
    "import": "@/components/ui/date-time-picker",
    "npmImport": "minidev-ui-kit/ui/date-time-picker",
    "exports": [
      "DateTimePicker"
    ],
    "related": [
      "calendar",
      "date-picker",
      "time-picker"
    ],
    "docsUrl": "https://ui.minidev.pro/docs/date-time-picker",
    "markdownUrl": "https://ui.minidev.pro/docs/date-time-picker.md",
    "keywords": [
      "shadcn datetime picker",
      "react date time picker",
      "datetime picker tailwind"
    ]
  }
}
