{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date-picker",
  "title": "Date picker",
  "description": "ui-sdk's Date picker: a date typed in the page's language or picked from the Calendar in a popover, one day or a range in one box, with presets and a clear button. A range stays open until both ends are picked.",
  "dependencies": [
    "@ui-sdk/react"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/calendar.json",
    "https://kinoui.com/r/popover.json",
    "https://kinoui.com/r/input.json",
    "https://kinoui.com/r/input-group.json",
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/dates.json",
    "https://kinoui.com/r/field-control.json",
    "https://kinoui.com/r/highlight.json",
    "https://kinoui.com/r/popup.json",
    "https://kinoui.com/r/pill.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/roomy.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/date-picker.tsx",
      "content": "'use client'\n\nimport { Button } from '@/registry/components/kino/button'\nimport { CalendarMonths } from '@/registry/components/kino/calendar'\nimport {\n  focusControl,\n  InputInvalidIcon,\n  inputBoxClassName,\n  inputControlClassName,\n} from '@/registry/components/kino/input'\nimport {\n  InputGroupButton,\n  inputGroupPresence,\n} from '@/registry/components/kino/input-group'\nimport { PopoverBox, usePopoverContent } from '@/registry/components/kino/popover'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  CALENDAR_LABELS,\n  type CalendarLabels,\n  type CalendarLook,\n  CalendarLookContext,\n  type DayContent,\n} from '@/registry/lib/calendar-grid'\nimport {\n  boundDay,\n  type DateRange,\n  datePlaceholder,\n  formatDate,\n  formatDateRange,\n  useLocale,\n  useToday,\n  type Weekday,\n  weekStart,\n} from '@/registry/lib/dates'\nimport { useField } from '@/registry/lib/field-control'\nimport {\n  followPick,\n  followPointer,\n  highlightClassName,\n  itemMatching,\n  pickClassName,\n} from '@/registry/lib/highlight'\nimport {\n  pillBackdropClassName,\n  pillClassName,\n  pillItemClassName,\n  pillItemLayout,\n  pillRowClassName,\n  pillTrackClassName,\n} from '@/registry/lib/pill'\nimport { usePopupPresentationAt } from '@/registry/lib/popup'\nimport { markMounted, mergeRefs } from '@/registry/lib/refs'\nimport { useRoomy } from '@/registry/lib/roomy'\nimport {\n  DatePicker as DatePickerPrimitive,\n  DatePickerClear as DatePickerClearPrimitive,\n  DatePickerContent as DatePickerContentPrimitive,\n  DatePickerInput as DatePickerInputPrimitive,\n  DatePickerPreset as DatePickerPresetPrimitive,\n  type DatePickerState,\n  DatePickerTrigger as DatePickerTriggerPrimitive,\n  type DatePickerValue,\n  createDatePickerController,\n} from '@ui-sdk/react/date-picker'\nimport {\n  type ComponentProps,\n  createContext,\n  type ReactNode,\n  use,\n  useEffect,\n  useId,\n  useMemo,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * ui-sdk's Date picker in Kino's look: a date typed in the page's language\n * into a field, or picked from the Calendar in a popover that opens from the\n * field's calendar button. One day, or a range typed as two dates in one box\n * and picked as a range on the calendar. ui-sdk reads what is typed, holds\n * the value, sends it with a form and checks it; Kino draws the box, the\n * popover and the Calendar's months in it.\n */\n\n/** The names the picker's own parts take, in place of the English ones. */\ninterface DatePickerLabels {\n  /** The calendar button, before the date it holds; ui-sdk's \"Choose date\" when not given. */\n  open?: string\n  /** The clear button. */\n  clear: string\n  /** A range's last date, after the field's name. */\n  end: string\n}\n\nconst ENGLISH: DatePickerLabels = { clear: 'Clear', end: 'End date' }\n\ninterface DatePickerContextValue {\n  state: DatePickerState\n  locale: string\n  labels: DatePickerLabels\n  /** What the Calendar inside draws by, but for the parts the content sets. */\n  look: Omit<CalendarLook, 'showWeekNumbers' | 'dayContent' | 'labels'>\n  /** The field's box, where the popover hangs from. */\n  box: HTMLElement | null\n  setBox: (element: HTMLElement | null) => void\n}\n\nconst DatePickerContext = createContext<DatePickerContextValue | null>(null)\n\nfunction useDatePicker(part: string) {\n  const context = use(DatePickerContext)\n  if (!context) throw new Error(`${part} must be inside a DatePicker.`)\n  return context\n}\n\ntype DatePickerPrimitiveProps = ComponentProps<typeof DatePickerPrimitive>\n\n/** Why the value changed, as `onValueChange` hears it. */\ntype DatePickerChangeDetails = Parameters<\n  NonNullable<DatePickerPrimitiveProps['onValueChange']>\n>[1]\n\ninterface DatePickerSingle {\n  mode?: 'single'\n  /** The date, as `yyyy-mm-dd`. */\n  value?: string | null\n  defaultValue?: string | null\n  onValueChange?: (value: string | null, details: DatePickerChangeDetails) => void\n}\n\ninterface DatePickerRange {\n  mode: 'range'\n  /** The range, start first; null until both ends are in. */\n  value?: DateRange | null\n  defaultValue?: DateRange | null\n  onValueChange?: (value: DateRange | null, details: DatePickerChangeDetails) => void\n}\n\ntype DatePickerProps = Omit<\n  DatePickerPrimitiveProps,\n  | 'children'\n  | 'weekStartsOn'\n  | 'className'\n  | 'mode'\n  | 'value'\n  | 'defaultValue'\n  | 'onValueChange'\n> & {\n  /** The first day of the week, 0 for Sunday. The locale's by default. */\n  weekStartsOn?: Weekday\n  labels?: Partial<DatePickerLabels>\n  className?: string\n  children?: ReactNode\n} & (DatePickerSingle | DatePickerRange)\n\n/**\n * Holds the date, whether the calendar is open and what a form sends.\n * Several months show side by side on a screen wider than a phone and one on\n * a phone. `presentation` is a popover by default; `auto` opens a sheet from\n * the bottom edge on a small touch screen, as the Popover does.\n */\nfunction DatePicker({\n  locale: localeProp,\n  weekStartsOn,\n  months = 1,\n  fixedWeeks = true,\n  monthFormat = 'long',\n  min,\n  max,\n  today: todayProp,\n  timeZone,\n  presentation = 'popover',\n  controller: controllerProp,\n  labels,\n  className,\n  children,\n  value,\n  defaultValue,\n  onValueChange,\n  ...props\n}: DatePickerProps) {\n  const [own] = useState(createDatePickerController)\n  const controller = controllerProp ?? own\n  const locale = useLocale(localeProp)\n  const first = weekStartsOn ?? weekStart(locale)\n  const clock = useToday(timeZone)\n  const today = todayProp ?? clock\n  const bounds = useMemo(\n    () => ({ min: boundDay(min, 'start'), max: boundDay(max, 'end') }),\n    [min, max],\n  )\n  // Two months side by side don't fit a phone's width: it shows one.\n  const roomy = useRoomy()\n  const shown = roomy ? months : 1\n  const [box, setBox] = useState<HTMLElement | null>(null)\n  const words = useMemo(() => ({ ...ENGLISH, ...labels }), [labels])\n\n  return (\n    <DatePickerPrimitive\n      {...props}\n      value={value as DatePickerValue | undefined}\n      defaultValue={defaultValue as DatePickerValue | undefined}\n      onValueChange={onValueChange as DatePickerPrimitiveProps['onValueChange']}\n      controller={controller}\n      locale={locale}\n      weekStartsOn={first}\n      months={shown}\n      fixedWeeks={fixedWeeks}\n      monthFormat={monthFormat}\n      min={bounds.min}\n      max={bounds.max}\n      today={today ?? undefined}\n      timeZone={timeZone}\n      presentation={usePopupPresentationAt(presentation, box)}\n      className={className}\n    >\n      {(state) => (\n        <DatePickerContext\n          value={{\n            state,\n            locale,\n            labels: words,\n            look: {\n              mode: state.mode,\n              disabled: state.disabled,\n              locale,\n              weekStartsOn: first,\n              months: shown,\n              monthFormat,\n              full: null,\n              bounds,\n              today,\n              showMonth: (month) => controller.setMonth(month),\n            },\n            box,\n            setBox,\n          }}\n        >\n          {children}\n        </DatePickerContext>\n      )}\n    </DatePickerPrimitive>\n  )\n}\n\n/** The calendar button at the end of the field's box, named in `labels.open` with the date it holds when given. */\nfunction BoxTrigger() {\n  const { state, locale, labels } = useDatePicker('DatePickerInput')\n  const { value } = state\n  const written =\n    value === null\n      ? null\n      : typeof value === 'string'\n        ? formatDate(value, locale, { dateStyle: 'full' })\n        : formatDateRange(value[0], value[1], locale, { dateStyle: 'full' })\n  const named = labels.open && (written ? `${labels.open}, ${written}` : labels.open)\n  return (\n    <DatePickerTriggerPrimitive\n      data-date-picker-box-trigger=''\n      render={(own: ComponentProps<typeof InputGroupButton>) => (\n        <InputGroupButton\n          {...own}\n          aria-label={named || own['aria-label']}\n          size='icon-xs'\n          className='text-muted-foreground'\n        />\n      )}\n    >\n      <PickerIcon />\n    </DatePickerTriggerPrimitive>\n  )\n}\n\n/**\n * A range's two dates, each as wide as what it shows, so they read as one\n * pair from the box's start, and shrink together where there isn't room.\n * Where a field can't size to its text, they share the box and meet at the\n * dash. Their placeholders take the small text even on a phone, so both fit.\n */\nconst rangeDateClassName =\n  'w-0 supports-[field-sizing:content]:w-auto supports-[field-sizing:content]:flex-[0_1_auto] supports-[field-sizing:content]:[field-sizing:content]'\n\n/**\n * The field: ui-sdk's input in the box, reading the date typed in the\n * locale's order on Enter or blur, or a range's two inputs, with the\n * calendar button at its end. Children (a `DatePickerClear`) sit before the\n * button. `className` goes to the box, every other prop to the input, or a\n * range's first.\n */\nfunction DatePickerInput({\n  className,\n  children,\n  placeholder,\n  'aria-label': ariaLabel,\n  'aria-labelledby': ariaLabelledBy,\n  ...props\n}: Omit<ComponentProps<typeof DatePickerInputPrimitive>, 'className' | 'end'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const { state, locale, labels, setBox } = useDatePicker('DatePickerInput')\n  const range = state.mode === 'range'\n  const hint = placeholder ?? datePlaceholder(locale)\n  const endNameId = useId()\n  // The end isn't the Field's control, so it takes the Field's naming itself:\n  // its name, then \"End date\", its description and error, and its invalid state.\n  const field = useField()\n  const fieldProps = (field?.props({}) ?? {}) as {\n    'aria-labelledby'?: string\n    'aria-describedby'?: string\n    'aria-invalid'?: 'true'\n  }\n  const endNaming = {\n    ...(ariaLabel\n      ? { 'aria-label': `${ariaLabel}, ${labels.end}` }\n      : {\n          'aria-labelledby':\n            [ariaLabelledBy ?? fieldProps['aria-labelledby'], endNameId]\n              .filter(Boolean)\n              .join(' ') || undefined,\n        }),\n    'aria-describedby': props['aria-describedby'] ?? fieldProps['aria-describedby'],\n    'aria-invalid': state.invalid ? ('true' as const) : fieldProps['aria-invalid'],\n  }\n\n  return (\n    <div\n      ref={setBox}\n      data-date-picker-box=''\n      data-range={range ? '' : undefined}\n      onPointerDown={focusControl}\n      className={cn(inputBoxClassName, 'cursor-text', className)}\n    >\n      <DatePickerInputPrimitive\n        placeholder={hint}\n        aria-label={ariaLabel}\n        aria-labelledby={ariaLabelledBy}\n        className={cn(\n          inputControlClassName,\n          'tabular-nums',\n          range && [rangeDateClassName, 'pe-0 text-end placeholder:text-sm'],\n        )}\n        {...props}\n      />\n      {range && (\n        <>\n          <span aria-hidden className='shrink-0 px-1 text-muted-foreground'>\n            –\n          </span>\n          <span id={endNameId} hidden>\n            {labels.end}\n          </span>\n          <DatePickerInputPrimitive\n            end\n            placeholder={hint}\n            {...endNaming}\n            className={cn(\n              inputControlClassName,\n              rangeDateClassName,\n              'px-0 text-start tabular-nums placeholder:text-sm supports-[field-sizing:content]:grow',\n            )}\n          />\n        </>\n      )}\n      <span\n        data-date-picker-end=''\n        className='ms-auto flex shrink-0 items-center gap-0.5 pe-1.5'\n      >\n        <InputInvalidIcon className='pe-1' />\n        {children}\n        <BoxTrigger />\n      </span>\n    </div>\n  )\n}\n\n/**\n * A button that writes the date in words and opens the calendar, for a\n * date picked rather than typed. Children show while no date is picked.\n */\nfunction DatePickerTrigger({\n  className,\n  children,\n  format,\n  size = 'default',\n  'aria-label': ariaLabel,\n  ref,\n  ...props\n}: Omit<ComponentProps<typeof DatePickerTriggerPrimitive>, 'className' | 'children'> & {\n  className?: string\n  /** The button's size: `sm` sits in a row of small controls, such as a toolbar's. */\n  size?: 'default' | 'sm'\n  /** Shown while no date is picked, such as \"Pick a date\". */\n  children?: ReactNode\n  /** How the value is written, as `Intl.DateTimeFormat` takes it: 14 Nov 2026 by default, and 2–8 Nov 2026 for a range. */\n  format?: Omit<Intl.DateTimeFormatOptions, 'timeZone'>\n}) {\n  const picker = useDatePicker('DatePickerTrigger')\n  // Without a box, the button is where the popup hangs from and whose motion setting it follows.\n  const own = useMemo(() => mergeRefs(ref, picker.setBox), [ref, picker.setBox])\n  const { value } = picker.state\n  const style = format ?? { dateStyle: 'medium' }\n  const written =\n    value === null\n      ? null\n      : typeof value === 'string'\n        ? formatDate(value, picker.locale, style)\n        : formatDateRange(value[0], value[1], picker.locale, style)\n  return (\n    <DatePickerTriggerPrimitive\n      ref={own}\n      data-date-picker-trigger=''\n      data-placeholder={written ? undefined : ''}\n      // Named by what it shows, the date or its children, as a button's text names it:\n      // the label given here, even none, replaces ui-sdk's \"Choose date\".\n      render={(own: ComponentProps<typeof Button>) => (\n        <Button\n          {...own}\n          aria-label={ariaLabel}\n          variant='outline'\n          size={size}\n          className={cn(\n            'justify-start font-normal tabular-nums data-placeholder:text-muted-foreground',\n            className,\n          )}\n        />\n      )}\n      {...props}\n    >\n      <span data-icon='inline-start' className='flex'>\n        <PickerIcon />\n      </span>\n      {written ?? children}\n    </DatePickerTriggerPrimitive>\n  )\n}\n\n/** Clears the date, or a range's; shown once there is something to clear. Focus goes back to the field. */\nfunction DatePickerClear({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof DatePickerClearPrimitive>, 'className' | 'children'> & {\n  className?: string\n}) {\n  const picker = useDatePicker('DatePickerClear')\n  return (\n    <DatePickerClearPrimitive\n      data-date-picker-clear=''\n      aria-label={picker.labels.clear}\n      render={(clearProps, state) => (\n        <span\n          data-shown={state.empty || state.disabled ? undefined : ''}\n          className={cn(inputGroupPresence, 'flex')}\n        >\n          <InputGroupButton\n            {...(clearProps as ComponentProps<typeof InputGroupButton>)}\n            size='icon-xs'\n            className={cn('text-muted-foreground', className)}\n          />\n        </span>\n      )}\n      {...props}\n    >\n      <IconPlaceholder\n        lucide='XIcon'\n        tabler='IconX'\n        hugeicons='Cancel01Icon'\n        phosphor='XIcon'\n        remixicon='RiCloseLine'\n        aria-hidden\n      />\n    </DatePickerClearPrimitive>\n  )\n}\n\n/**\n * The popover the calendar opens in, from the field's start, on the\n * Popover's look. Focus goes to the picked day, or today, ready for the\n * arrow keys, and back to the field once it closes. Without children it\n * holds the Calendar's months; children sit side by side, such as presets\n * and then the Calendar's `CalendarMonths`.\n */\nfunction DatePickerContent({\n  className,\n  children,\n  showWeekNumbers = false,\n  dayContent,\n  labels,\n  ref,\n  ...props\n}: Omit<ComponentProps<typeof DatePickerContentPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n  /** Shows each week's number before its days. */\n  showWeekNumbers?: boolean\n  /** What each day shows, under its full date, which a screen reader hears first. */\n  dayContent?: DayContent\n  /** The Calendar's own words, as the Calendar's `labels` takes them. */\n  labels?: Partial<CalendarLabels>\n}) {\n  const picker = useDatePicker('DatePickerContent')\n  const content = usePopoverContent(ref)\n  const look: CalendarLook = {\n    ...picker.look,\n    labels: { ...CALENDAR_LABELS, ...labels },\n    showWeekNumbers,\n    dayContent,\n  }\n  return (\n    <DatePickerContentPrimitive\n      {...content.props}\n      side='bottom'\n      align='start'\n      anchor={picker.box ?? undefined}\n      {...props}\n    >\n      {({ presentation }) => (\n        <PopoverBox\n          presentation={presentation}\n          className={cn(\n            'w-auto flex-row flex-wrap items-start gap-(--surface-gap) max-sm:justify-center',\n            className,\n          )}\n        >\n          <CalendarLookContext value={look}>\n            {children ?? <CalendarMonths className='w-auto' />}\n          </CalendarLookContext>\n        </PopoverBox>\n      )}\n    </DatePickerContentPrimitive>\n  )\n}\n\n/** The pill's copy of the presets: inside it, a preset is only its label. */\nconst PresetCopyContext = createContext(false)\n\nconst PRESET = '[data-date-picker-preset]'\n\nconst presetLayout = cn(\n  pillItemLayout,\n  'h-auto min-h-[calc(var(--control-height)_-_6px)] justify-start py-1.5 text-start whitespace-normal',\n)\n\n/**\n * A column of presets beside the calendar, such as Today or Last 7 days,\n * drawn as a vertical Segmented control: the pill slides to the one the\n * value matches. On a phone, where they don't fit beside the calendar, they\n * sit above it as wide as it.\n */\nfunction DatePickerPresets({\n  className,\n  children,\n  'aria-label': ariaLabel = 'Presets',\n  ...props\n}: ComponentProps<'div'>) {\n  const areaRef = useRef<HTMLDivElement>(null)\n  const areaRefs = useMemo(() => mergeRefs(areaRef, markMounted), [])\n  const pillRef = useRef<HTMLSpanElement>(null)\n  const backdropRef = useRef<HTMLSpanElement>(null)\n  useEffect(() => {\n    const area = areaRef.current\n    if (!area || !pillRef.current || !backdropRef.current) return\n    const stopPick = followPick(area, pillRef.current, {\n      picked: () => area.querySelector<HTMLElement>(`${PRESET}[data-selected]`),\n      attributes: ['data-selected'],\n    })\n    const stopHover = followPointer(area, backdropRef.current, {\n      itemOf: itemMatching(area, PRESET),\n      focus: true,\n    })\n    return () => {\n      stopPick()\n      stopHover()\n    }\n  }, [])\n  return (\n    <div\n      role='group'\n      aria-label={ariaLabel}\n      data-date-picker-presets=''\n      className={cn(pillTrackClassName, 'w-fit max-w-full max-sm:w-full', className)}\n      {...props}\n    >\n      <div\n        ref={areaRefs}\n        className={cn('relative isolate flex flex-col', pillRowClassName)}\n      >\n        {children}\n        <span\n          ref={backdropRef}\n          aria-hidden\n          className={cn(highlightClassName, pillBackdropClassName)}\n        />\n        <span\n          ref={pillRef}\n          aria-hidden\n          inert\n          className={cn(pickClassName, pillClassName, 'z-10')}\n        >\n          <span className={cn('flex flex-col', pillRowClassName)}>\n            <PresetCopyContext value>{children}</PresetCopyContext>\n          </span>\n        </span>\n      </div>\n    </div>\n  )\n}\n\n/** One preset, ui-sdk's: a press sets its day, or its range as `[start, end]`, and closes the calendar. */\nfunction DatePickerPreset({\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof DatePickerPresetPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  if (use(PresetCopyContext)) {\n    return <span className={cn(presetLayout, className)}>{children}</span>\n  }\n  return (\n    <DatePickerPresetPrimitive\n      data-date-picker-preset=''\n      className={cn(\n        presetLayout,\n        pillItemClassName,\n        // Until the page runs and the pill is placed, the pick draws itself.\n        '[[data-date-picker-presets]_div:not([data-mounted])>&]:data-[selected]:bg-primary [[data-date-picker-presets]_div:not([data-mounted])>&]:data-[selected]:text-primary-foreground',\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </DatePickerPresetPrimitive>\n  )\n}\n\nfunction PickerIcon() {\n  return (\n    <IconPlaceholder\n      lucide='CalendarIcon'\n      tabler='IconCalendar'\n      hugeicons='Calendar01Icon'\n      phosphor='CalendarIcon'\n      remixicon='RiCalendarLine'\n      aria-hidden\n    />\n  )\n}\n\nexport {\n  DatePicker,\n  DatePickerClear,\n  DatePickerContent,\n  DatePickerInput,\n  DatePickerPreset,\n  DatePickerPresets,\n  DatePickerTrigger,\n}\nexport type { DatePickerChangeDetails, DatePickerLabels, DatePickerProps }\n",
      "type": "registry:component",
      "target": "@components/kino/date-picker.tsx"
    }
  ],
  "type": "registry:component"
}