# Animated Date Picker for UI SDK (/docs/components/date-picker)

A field that opens a calendar unfolding from it, with the selected day gliding to its new place.

```tsx title="example.tsx"
import {
  CalendarGrid,
  CalendarHeader,
  CalendarHeading,
  CalendarNext,
  CalendarPrevious,
  DatePicker,
  DatePickerContent,
  DatePickerField,
  DatePickerHint,
  DatePickerInput,
  DatePickerPreset,
  DatePickerTrigger,
} from "@/components/keyframery/date-picker"

const iso = (date: Date) =>
  `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`

function daysFromToday(days: number) {
  const date = new Date()
  date.setDate(date.getDate() + days)
  return iso(date)
}

/* The next Friday, or the one after if today is Friday. */
function nextFriday() {
  const date = new Date()
  date.setDate(date.getDate() + (((5 - date.getDay() + 7) % 7) || 7))
  return iso(date)
}

const day = (offset: number) =>
  `[data-slot="date-picker-content"] [data-slot="calendar-day"][data-value="${daysFromToday(offset)}"]`

export default function DatePickerDemo() {
  return (
    <div className="flex h-[440px] w-[320px] flex-col">
      <div className="mb-4">
        <h3 className="text-[15px] font-semibold tracking-tight">The Old Bakery, Rye</h3>
        <p className="mt-1 text-[13px] text-muted-foreground">Double room · €118 a night</p>
      </div>
      <label htmlFor="check-in" className="mb-1.5 text-[13px] font-medium">
        Check-in
      </label>
      <DatePicker defaultValue={daysFromToday(3)} min={daysFromToday(0)} unavailable={[daysFromToday(9), daysFromToday(10)]}>
        <DatePickerField>
          <DatePickerInput id="check-in" />
          <DatePickerTrigger />
        </DatePickerField>
        <DatePickerHint>{(state) => `From 3 pm · like ${state.example}`}</DatePickerHint>
        <DatePickerContent align="start">
          <CalendarHeader>
            <CalendarPrevious />
            <CalendarHeading />
            <CalendarNext />
          </CalendarHeader>
          <CalendarGrid />
          <div className="flex gap-1 border-t border-border pt-2">
            <DatePickerPreset value={daysFromToday(0)}>Tonight</DatePickerPreset>
            <DatePickerPreset value={daysFromToday(1)}>Tomorrow</DatePickerPreset>
            <DatePickerPreset value={nextFriday()}>Friday</DatePickerPreset>
          </div>
        </DatePickerContent>
      </DatePicker>
    </div>
  )
}
```

## Installation [#installation]

```bash
npx shadcn@latest add @keyframery/date-picker
```

This adds `components/keyframery/date-picker.tsx` and its primitive, `components/keyframery/primitives/date-picker.tsx`, to your project, and installs `@ui-sdk/react`. The motion tokens are added to your global CSS the first time you install a component.

## Usage [#usage]

```tsx
import {
  CalendarDay,
  CalendarGrid,
  CalendarHeader,
  CalendarHeading,
  CalendarMonthSelect,
  CalendarNext,
  CalendarPrevious,
  CalendarWeekday,
  CalendarWeekdays,
  CalendarWeeks,
  CalendarYearSelect,
  DatePicker,
  DatePickerClear,
  DatePickerContent,
  DatePickerField,
  DatePickerHint,
  DatePickerInput,
  DatePickerPreset,
  DatePickerTrigger,
} from "@/components/keyframery/date-picker"
```

The parts and props are the same as UI SDK's Date Picker. For every prop, see the [UI SDK date picker reference](https://ui-sdk.dev/docs/components/date-picker).

**Next.js with cacheComponents**

The date picker reads today's date while it renders. With `cacheComponents` turned on, render it inside `<Suspense>` after `await connection()`. [See the fix](/docs/troubleshooting#nextjs-stops-with-unstable-value-datenow).

## What moves [#what-moves]

| Move          | What you see                                          |
| ------------- | ----------------------------------------------------- |
| **Unfold**    | The calendar unfolds from the field.                  |
| **Glide**     | Inside, the selected-day key glides to its new place. |
| **Direction** | Months slide in from the side you turned to.          |

Timing and springiness follow the [motion style](/docs/motion-styles) you set, so this component moves like the rest of your app.

## Swap the import [#swap-the-import]

Already using UI SDK's date picker with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.

```tsx
// Before
import { … } from "@ui-sdk/react/date-picker"

// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/date-picker"
```

## Parts [#parts]

The finished component exports 19 parts:

`CalendarDay`, `CalendarGrid`, `CalendarHeader`, `CalendarHeading`, `CalendarMonthSelect`, `CalendarNext`, `CalendarPrevious`, `CalendarWeekday`, `CalendarWeekdays`, `CalendarWeeks`, `CalendarYearSelect`, `DatePicker`, `DatePickerClear`, `DatePickerContent`, `DatePickerField`, `DatePickerHint`, `DatePickerInput`, `DatePickerPreset`, `DatePickerTrigger`

## Accessibility [#accessibility]

Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. With reduced motion turned on, nothing in the date picker moves: changes happen at once or with a short fade. More in [Accessibility](/docs/accessibility).

## Source [#source]

The code that lands in your project. It is yours to change.

**components/keyframery/date-picker.tsx**

```tsx
"use client"

/* Styled date picker: the animated primitive plus the Keyframery look. */

import * as React from "react"

import {
  CalendarDay as CalendarDayPrimitive,
  CalendarGrid as CalendarGridPrimitive,
  CalendarHeading as CalendarHeadingPrimitive,
  CalendarMonthSelect as CalendarMonthSelectPrimitive,
  CalendarNext as CalendarNextPrimitive,
  CalendarPrevious as CalendarPreviousPrimitive,
  CalendarWeekday as CalendarWeekdayPrimitive,
  CalendarWeekdays as CalendarWeekdaysPrimitive,
  CalendarWeeks as CalendarWeeksPrimitive,
  CalendarYearSelect as CalendarYearSelectPrimitive,
  DatePicker as DatePickerPrimitive,
  DatePickerClear as DatePickerClearPrimitive,
  DatePickerContent as DatePickerContentPrimitive,
  DatePickerHint as DatePickerHintPrimitive,
  DatePickerInput as DatePickerInputPrimitive,
  DatePickerPreset as DatePickerPresetPrimitive,
  DatePickerTrigger as DatePickerTriggerPrimitive,
  createDatePickerController,
} from "@/components/keyframery/primitives/date-picker"
import { cn } from "@/lib/utils"

/* What the popup needs from the root: how many months show, and the field box to line up with. */
const PickerContext = React.createContext<{
  months: number
  field: HTMLElement | null
  setField: (element: HTMLElement | null) => void
} | null>(null)

/* The field look, as in Input: one hairline variable that hover, focus and invalid change. */
const fieldBox =
  "rounded-[10px] bg-background text-[13px] " +
  "[--field-line:rgb(0_0_0/0.09)] dark:[--field-line:rgb(255_255_255/0.1)] " +
  "shadow-[0_0_0_1px_var(--field-line),0_1px_2px_rgb(0_0_0/0.05)] dark:shadow-[0_0_0_1px_var(--field-line)] " +
  "transition-[box-shadow,background-color] duration-[calc(150ms*var(--kf-speed,1))] ease-house motion-reduce:transition-none! " +
  "hover:[--field-line:rgb(0_0_0/0.16)] dark:hover:[--field-line:rgb(255_255_255/0.18)]"

/* A small key: the month buttons. The primitive springs them back after a press. */
const stepKey = cn(
  "inline-flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-[9px] bg-background text-muted-foreground outline-none select-none [&_svg]:size-4",
  "shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_1px_1px_rgb(0_0_0/0.05),0_3px_6px_-2px_rgb(0_0_0/0.1)]",
  "dark:bg-accent dark:shadow-[0_0_0_1px_rgb(255_255_255/0.07),inset_0_1px_0_rgb(255_255_255/0.08),0_2px_6px_-1px_rgb(0_0_0/0.6)]",
  "hover:text-foreground active:shadow-[0_0_0_1px_rgb(0_0_0/0.08),0_1px_1px_rgb(0_0_0/0.04)]",
  "dark:active:shadow-[0_0_0_1px_rgb(255_255_255/0.07),inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.6)]",
  "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-popover",
  "data-disabled:pointer-events-none data-disabled:opacity-40",
)

/* The native month and year selects, as compact fields. */
const selectField = cn(
  "h-7 cursor-pointer appearance-none rounded-[8px] bg-background px-2 text-[13px] font-medium text-foreground outline-none",
  "shadow-[0_0_0_1px_rgb(0_0_0/0.09),0_1px_2px_rgb(0_0_0/0.05)] hover:shadow-[0_0_0_1px_rgb(0_0_0/0.16),0_1px_2px_rgb(0_0_0/0.05)]",
  "dark:shadow-[0_0_0_1px_rgb(255_255_255/0.1)] dark:hover:shadow-[0_0_0_1px_rgb(255_255_255/0.16)]",
  "transition-shadow duration-[calc(150ms*var(--kf-speed,1))] focus-visible:shadow-[0_0_0_1px_var(--ring)] focus-visible:ring-[3px] focus-visible:ring-ring/25",
  "dark:focus-visible:shadow-[0_0_0_1px_var(--ring)]",
  "data-disabled:pointer-events-none data-disabled:opacity-40 motion-reduce:transition-none!",
)

function ChevronLeftIcon() {
  return (
    <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
      <path d="M9.5 3.5 5 8l4.5 4.5" />
    </svg>
  )
}

function ChevronRightIcon() {
  return (
    <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
      <path d="M6.5 3.5 11 8l-4.5 4.5" />
    </svg>
  )
}

function CalendarIcon() {
  return (
    <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
      <rect x="2.5" y="3.5" width="11" height="10" rx="2" />
      <path d="M2.5 6.75h11M5.5 2v2.5M10.5 2v2.5" />
    </svg>
  )
}

function XIcon() {
  return (
    <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
      <path d="m4.5 4.5 7 7m0-7-7 7" />
    </svg>
  )
}

/* The root. The popup lines up with the field box, so the root shares it with the popup. */
function DatePicker({
  className,
  children,
  months = 1,
  ...props
}: React.ComponentProps<typeof DatePickerPrimitive>) {
  const [field, setField] = React.useState<HTMLElement | null>(null)
  const count = Math.max(1, Math.floor(months) || 1)
  return (
    <PickerContext.Provider value={{ months: count, field, setField }}>
      <DatePickerPrimitive
        className={cn("group/picker flex w-full flex-col gap-1.5", className)}
        months={months}
        {...props}
      >
        {children ?? (
          <>
            <DatePickerField>
              <DatePickerInput />
              {props.mode === "range" && (
                <>
                  <span aria-hidden className="px-1 text-muted-foreground/70">–</span>
                  <DatePickerInput end />
                </>
              )}
              <DatePickerTrigger />
            </DatePickerField>
            <DatePickerContent />
          </>
        )}
      </DatePickerPrimitive>
    </PickerContext.Provider>
  )
}

/* The field: the typed date and the calendar key sit inside one box, and the ring
   follows the input's focus or the open calendar. The popup lines up with this box. */
function DatePickerField({ className, ...props }: React.ComponentProps<"div">) {
  const picker = React.useContext(PickerContext)
  return (
    <div
      ref={picker?.setField}
      data-slot="date-picker-field"
      className={cn(
        fieldBox,
        "flex h-9 w-full min-w-0 cursor-text items-center gap-1 pr-1 pl-3 text-muted-foreground",
        "has-[input:focus-visible]:ring-[3px] has-[input:focus-visible]:ring-ring/25 has-[input:focus-visible]:[--field-line:var(--ring)] dark:has-[input:focus-visible]:[--field-line:var(--ring)]",
        "group-data-open/picker:[--field-line:var(--ring)] dark:group-data-open/picker:[--field-line:var(--ring)] group-data-open/picker:ring-[3px] group-data-open/picker:ring-ring/25",
        "group-data-invalid/picker:ring-destructive/25! group-data-invalid/picker:[--field-line:var(--destructive)]!",
        "group-data-disabled/picker:cursor-not-allowed group-data-disabled/picker:bg-muted group-data-disabled/picker:[--field-line:rgb(0_0_0/0.06)] dark:group-data-disabled/picker:[--field-line:rgb(255_255_255/0.06)]",
        "group-data-readonly/picker:bg-muted/50",
        className,
      )}
      {...props}
    />
  )
}

function DatePickerInput({
  className,
  ...props
}: React.ComponentProps<typeof DatePickerInputPrimitive>) {
  return (
    <DatePickerInputPrimitive
      className={cn(
        "h-full w-full min-w-0 flex-1 bg-transparent text-[13px] text-foreground tabular-nums outline-none placeholder:text-muted-foreground/70",
        "data-disabled:cursor-not-allowed data-disabled:text-muted-foreground",
        className,
      )}
      {...props}
    />
  )
}

/* The calendar key at the end of the field. It stays lit while the calendar is open. */
function DatePickerTrigger({
  className,
  children,
  ...props
}: React.ComponentProps<typeof DatePickerTriggerPrimitive>) {
  return (
    <DatePickerTriggerPrimitive
      className={cn(
        "grid size-7 shrink-0 cursor-pointer place-items-center rounded-[7px] text-muted-foreground outline-none [&_svg]:size-4",
        "transition-[color,background-color,scale] duration-[calc(200ms*var(--kf-speed,1))]",
        "hover:bg-foreground/[0.06] hover:text-foreground",
        "data-open:bg-accent data-open:text-foreground",
        "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
        "data-disabled:pointer-events-none data-disabled:opacity-50",
        className,
      )}
      {...props}
    >
      {children ?? <CalendarIcon />}
    </DatePickerTriggerPrimitive>
  )
}

function DatePickerHint({
  className,
  ...props
}: React.ComponentProps<typeof DatePickerHintPrimitive>) {
  return (
    <DatePickerHintPrimitive
      className={cn(
        "px-0.5 text-[12px] text-muted-foreground tabular-nums group-data-invalid/picker:text-destructive",
        className,
      )}
      {...props}
    />
  )
}

/* Clears the date. It shrinks away while there's nothing to clear. */
function DatePickerClear({
  className,
  children,
  ...props
}: React.ComponentProps<typeof DatePickerClearPrimitive>) {
  return (
    <DatePickerClearPrimitive
      className={cn(
        "grid size-6 shrink-0 cursor-pointer place-items-center rounded-[7px] text-muted-foreground outline-none [&_svg]:size-3.5",
        "transition-[color,background-color,opacity,scale] duration-[calc(150ms*var(--kf-speed,1))] ease-house",
        "hover:bg-foreground/[0.06] hover:text-foreground active:scale-[0.9]",
        "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
        "data-empty:pointer-events-none data-empty:scale-75 data-empty:opacity-0",
        "data-disabled:pointer-events-none data-disabled:opacity-0 motion-reduce:transition-none!",
        className,
      )}
      {...props}
    >
      {children ?? <XIcon />}
    </DatePickerClearPrimitive>
  )
}

/* A shortcut like "This weekend". The chosen one reads as a pressed key. */
function DatePickerPreset({
  className,
  ...props
}: React.ComponentProps<typeof DatePickerPresetPrimitive>) {
  return (
    <DatePickerPresetPrimitive
      className={cn(
        "inline-flex h-7 cursor-pointer items-center rounded-[8px] px-2.5 text-[12px] leading-none font-medium whitespace-nowrap text-muted-foreground outline-none select-none",
        "transition-[color,background-color,box-shadow,scale] duration-[calc(200ms*var(--kf-speed,1))]",
        "hover:bg-foreground/[0.05] hover:text-foreground",
        "data-selected:bg-background data-selected:text-foreground data-selected:shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_1px_1px_rgb(0_0_0/0.05),0_3px_6px_-2px_rgb(0_0_0/0.1)]",
        "dark:data-selected:bg-accent dark:data-selected:shadow-[0_0_0_1px_rgb(255_255_255/0.07),inset_0_1px_0_rgb(255_255_255/0.08),0_2px_6px_-1px_rgb(0_0_0/0.6)]",
        "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-popover",
        "data-disabled:pointer-events-none data-disabled:opacity-40",
        className,
      )}
      {...props}
    />
  )
}

/* The sheet. The primitive unfolds it out of the field. Without children it lays out a styled calendar. */
function DatePickerContent({
  className,
  children,
  sideOffset = 6,
  collisionPadding = 12,
  anchor,
  ...props
}: React.ComponentProps<typeof DatePickerContentPrimitive>) {
  const picker = React.useContext(PickerContext)
  const months = picker?.months ?? 1
  return (
    <DatePickerContentPrimitive
      sideOffset={sideOffset}
      collisionPadding={collisionPadding}
      anchor={anchor ?? picker?.field ?? undefined}
      className={cn(
        "z-50 flex w-max flex-col gap-2 rounded-[14px] bg-popover p-3 text-popover-foreground outline-none",
        "shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_2px_6px_-2px_rgb(0_0_0/0.08),0_12px_32px_-8px_rgb(0_0_0/0.18)]",
        "dark:shadow-[0_0_0_1px_rgb(255_255_255/0.08),0_12px_32px_-8px_rgb(0_0_0/0.7)]",
        /* As a sheet on small touch screens: full width, square at the bottom edge. */
        "data-[presentation=sheet]:w-full data-[presentation=sheet]:items-center data-[presentation=sheet]:rounded-b-none data-[presentation=sheet]:pb-6",
        className,
      )}
      {...props}
    >
      {children ?? (
        <>
          <CalendarHeader>
            <CalendarPrevious />
            <CalendarHeading />
            <CalendarNext />
          </CalendarHeader>
          <div className="flex gap-4">
            {Array.from({ length: months }, (_, offset) => (
              <CalendarGrid key={offset} offset={offset} />
            ))}
          </div>
        </>
      )}
    </DatePickerContentPrimitive>
  )
}

/* The calendar parts, as Calendar styles them, for inside the popup. */

/* The row above the grid. The heading sits first, the month keys after it. */
function CalendarHeader({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="calendar-header"
      className={cn("flex h-7 items-center gap-1.5", className)}
      {...props}
    />
  )
}

function CalendarHeading({
  className,
  ...props
}: React.ComponentProps<typeof CalendarHeadingPrimitive>) {
  return (
    <CalendarHeadingPrimitive
      className={cn(
        "order-first mr-auto pl-1.5 text-[15px] font-semibold tracking-tight tabular-nums",
        className,
      )}
      {...props}
    />
  )
}

function CalendarPrevious({
  className,
  children,
  ...props
}: React.ComponentProps<typeof CalendarPreviousPrimitive>) {
  return (
    <CalendarPreviousPrimitive className={cn(stepKey, className)} {...props}>
      {children ?? <ChevronLeftIcon />}
    </CalendarPreviousPrimitive>
  )
}

function CalendarNext({
  className,
  children,
  ...props
}: React.ComponentProps<typeof CalendarNextPrimitive>) {
  return (
    <CalendarNextPrimitive className={cn(stepKey, className)} {...props}>
      {children ?? <ChevronRightIcon />}
    </CalendarNextPrimitive>
  )
}

function CalendarMonthSelect({
  className,
  ...props
}: React.ComponentProps<typeof CalendarMonthSelectPrimitive>) {
  return <CalendarMonthSelectPrimitive className={cn(selectField, className)} {...props} />
}

function CalendarYearSelect({
  className,
  ...props
}: React.ComponentProps<typeof CalendarYearSelectPrimitive>) {
  return (
    <CalendarYearSelectPrimitive
      className={cn(selectField, "tabular-nums", className)}
      {...props}
    />
  )
}

/* One month. The primitive draws the chosen day's key here, as `before:` (the date or a range's
   start) and `after:` (a range's end), and glides it between days. This gives it the primary key look. */
const chosenKey = cn(
  "before:rounded-[9px] before:bg-primary after:rounded-[9px] after:bg-primary",
  "before:shadow-[inset_0_1px_0_rgb(255_255_255/0.14),0_1px_2px_rgb(0_0_0/0.25)] after:shadow-[inset_0_1px_0_rgb(255_255_255/0.14),0_1px_2px_rgb(0_0_0/0.25)]",
  "dark:before:shadow-[inset_0_1px_0_rgb(255_255_255/0.7),0_1px_2px_rgb(0_0_0/0.5)] dark:after:shadow-[inset_0_1px_0_rgb(255_255_255/0.7),0_1px_2px_rgb(0_0_0/0.5)]",
)

function CalendarGrid({
  className,
  children,
  ...props
}: React.ComponentProps<typeof CalendarGridPrimitive>) {
  return (
    <CalendarGridPrimitive
      className={cn(
        "border-separate border-spacing-x-0 border-spacing-y-0.5 data-disabled:opacity-50",
        chosenKey,
        className,
      )}
      {...props}
    >
      {children ?? (
        <>
          <CalendarWeekdays />
          <CalendarWeeks />
        </>
      )}
    </CalendarGridPrimitive>
  )
}

function CalendarWeekdays({
  children,
  ...props
}: React.ComponentProps<typeof CalendarWeekdaysPrimitive>) {
  return (
    <CalendarWeekdaysPrimitive {...props}>
      {children ?? ((index) => <CalendarWeekday index={index} />)}
    </CalendarWeekdaysPrimitive>
  )
}

function CalendarWeekday({
  className,
  ...props
}: React.ComponentProps<typeof CalendarWeekdayPrimitive>) {
  return (
    <CalendarWeekdayPrimitive
      className={cn(
        "h-7 w-8 p-0 text-center text-[11px] font-medium text-muted-foreground",
        className,
      )}
      {...props}
    />
  )
}

function CalendarWeeks({
  className,
  children,
  ...props
}: React.ComponentProps<typeof CalendarWeeksPrimitive>) {
  return (
    <CalendarWeeksPrimitive
      className={className}
      {...props}
    >
      {children ?? ((cell) => <CalendarDay value={cell.date} />)}
    </CalendarWeeksPrimitive>
  )
}

/* A day. The chosen key is drawn under it by the grid, so a chosen day only turns its number
   to the key's text colour. A range is a soft band between the two keys, rounded where a week wraps. */
function CalendarDay({
  className,
  ...props
}: React.ComponentProps<typeof CalendarDayPrimitive>) {
  return (
    <CalendarDayPrimitive
      className={cn(
        "relative size-8 cursor-pointer rounded-[9px] p-0 text-center align-middle text-[13px] leading-none font-medium text-foreground tabular-nums outline-none select-none",
        "transition-[color,background-color,scale] duration-[calc(200ms*var(--kf-speed,1))]",
        "not-data-selected:not-data-range-start:not-data-range-end:hover:bg-foreground/[0.06]",
        "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring",
        /* Chosen: the number sits on the primary key. */
        "data-selected:not-data-range-middle:text-primary-foreground data-range-start:text-primary-foreground data-range-end:text-primary-foreground",
        /* Today: a small dot under the number. */
        "data-today:font-semibold data-today:after:absolute data-today:after:bottom-[3px] data-today:after:left-1/2 data-today:after:size-1 data-today:after:-translate-x-1/2 data-today:after:rounded-full data-today:after:bg-foreground",
        "data-selected:not-data-range-middle:after:bg-primary-foreground data-range-start:after:bg-primary-foreground data-range-end:after:bg-primary-foreground",
        /* A range: the band between the keys. */
        "data-range-middle:rounded-none data-range-middle:bg-accent data-range-middle:text-accent-foreground data-range-middle:first:rounded-l-[9px] data-range-middle:last:rounded-r-[9px]",
        "data-preview:not-data-range-start:not-data-range-end:rounded-none data-preview:not-data-range-start:not-data-range-end:bg-accent/70 data-preview:first:rounded-l-[9px] data-preview:last:rounded-r-[9px]",
        "data-outside:text-muted-foreground/55",
        "data-disabled:cursor-default data-disabled:text-muted-foreground/45 data-disabled:hover:bg-transparent",
        "data-unavailable:line-through",
        "motion-reduce:transition-none!",
        className,
      )}
      {...props}
    />
  )
}

export {
  CalendarDay,
  CalendarGrid,
  CalendarHeader,
  CalendarHeading,
  CalendarMonthSelect,
  CalendarNext,
  CalendarPrevious,
  CalendarWeekday,
  CalendarWeekdays,
  CalendarWeeks,
  CalendarYearSelect,
  DatePicker,
  DatePickerClear,
  DatePickerContent,
  DatePickerField,
  DatePickerHint,
  DatePickerInput,
  DatePickerPreset,
  DatePickerTrigger,
  createDatePickerController,
}
```

**components/keyframery/primitives/date-picker.tsx**

```tsx
"use client"

/* Animated drop-in for `@ui-sdk/react/date-picker`: same parts, same props. Swap the import and keep your code.
   This file adds motion only. Colours, radii, shadows and spacing stay yours.

   - Unfold: the calendar pops out of the field from the point the doc gives, on a spring.
   - Inside it, as the animated calendar: the chosen day's key glides between days (style it with
     `before:` and `after:` on CalendarGrid), and a new month comes in from the side it was reached from.
   - Press: the trigger, the month buttons, the days and the presets give under the pointer. */

import {
  CalendarDay as CalendarDayPart,
  CalendarGrid as CalendarGridPart,
  CalendarHeading,
  CalendarNext as CalendarNextPart,
  CalendarPrevious as CalendarPreviousPart,
  CalendarWeekdays,
  CalendarWeeks as CalendarWeeksPart,
  DatePicker as DatePickerRoot,
  DatePickerContent as DatePickerContentPart,
  DatePickerInput,
  DatePickerPreset as DatePickerPresetPart,
  DatePickerTrigger as DatePickerTriggerPart,
} from "@ui-sdk/react/date-picker"
import * as React from "react"

import { cn } from "@/lib/utils"

export * from "@ui-sdk/react/date-picker"

/* What the popup needs from the root: which way the months last turned, and how many show. */
const PickerContext = React.createContext<{
  shown: React.RefObject<string | null>
  direction: "next" | "previous" | "none"
  months: number
} | null>(null)

/* Notes which way the months turn. Opening or closing starts fresh, so a reopened calendar
   doesn't slide. */
function DatePicker({
  children,
  onMonthChange,
  onOpenChange,
  ...props
}: React.ComponentProps<typeof DatePickerRoot>) {
  const shown = React.useRef<string | null>(null)
  const [direction, setDirection] = React.useState<"next" | "previous" | "none">("none")
  const months = Math.max(1, Math.floor(props.months ?? 1) || 1)
  return (
    <PickerContext.Provider value={{ shown, direction, months }}>
      <DatePickerRoot
        onMonthChange={(month, details) => {
          setDirection(shown.current && month < shown.current ? "previous" : "next")
          onMonthChange?.(month, details)
        }}
        onOpenChange={(open, details) => {
          setDirection("none")
          onOpenChange?.(open, details)
        }}
        {...props}
      >
        {children ?? (
          <>
            <DatePickerInput />
            {props.mode === "range" && <DatePickerInput end />}
            <DatePickerTrigger />
            <DatePickerContent />
          </>
        )}
      </DatePickerRoot>
    </PickerContext.Provider>
  )
}

function DatePickerTrigger({ className, ...props }: React.ComponentProps<typeof DatePickerTriggerPart>) {
  return (
    <DatePickerTriggerPart
      className={cn(
        "transition-[scale] duration-[calc(200ms*var(--kf-speed,1))] ease-pop active:scale-[0.9] data-disabled:active:scale-100 motion-reduce:transition-none!",
        className,
      )}
      {...props}
    />
  )
}

function DatePickerPreset({ className, ...props }: React.ComponentProps<typeof DatePickerPresetPart>) {
  return (
    <DatePickerPresetPart
      className={cn(
        "transition-[scale] duration-[calc(200ms*var(--kf-speed,1))] ease-pop active:scale-[0.96] data-disabled:active:scale-100 motion-reduce:transition-none!",
        className,
      )}
      {...props}
    />
  )
}

/* Unfold: from 0.86 and a 6px blur, 8px toward the field, growing from the point the doc gives;
   in on a spring, out quickly to 0.96. Without children it lays out a calendar. */
function DatePickerContent({
  className,
  children,
  ...props
}: React.ComponentProps<typeof DatePickerContentPart>) {
  const picker = React.useContext(PickerContext)
  const months = picker?.months ?? 1
  return (
    <DatePickerContentPart
      data-direction={picker?.direction ?? "none"}
      className={cn(
        "group/picker-content origin-(--transform-origin)",
        "transition-[opacity,scale,translate,filter] duration-[calc(380ms*var(--kf-speed,1))] ease-spring",
        "data-starting-style:scale-[0.86] data-starting-style:opacity-0 data-starting-style:blur-[6px]",
        "data-ending-style:scale-[0.96] data-ending-style:opacity-0 data-ending-style:blur-[6px] data-ending-style:duration-[calc(150ms*var(--kf-speed,1))] data-ending-style:ease-house",
        "data-[side=bottom]:data-starting-style:-translate-y-2 data-[side=top]:data-starting-style:translate-y-2",
        "data-[side=left]:data-starting-style:translate-x-2 data-[side=right]:data-starting-style:-translate-x-2",
        "motion-reduce:transition-none!",
        className,
      )}
      {...props}
    >
      {children ?? (
        <>
          <CalendarPrevious />
          <CalendarHeading />
          <CalendarNext />
          {Array.from({ length: months }, (_, offset) => (
            <CalendarGrid key={offset} offset={offset} />
          ))}
        </>
      )}
    </DatePickerContentPart>
  )
}

/* The calendar parts, animated as in the calendar primitive. */

const pressable =
  "transition-[scale] duration-[calc(200ms*var(--kf-speed,1))] ease-pop active:scale-[0.92] data-disabled:active:scale-100 motion-reduce:transition-none!"

function CalendarPrevious({ className, ...props }: React.ComponentProps<typeof CalendarPreviousPart>) {
  return <CalendarPreviousPart className={cn(pressable, className)} {...props} />
}

function CalendarNext({ className, ...props }: React.ComponentProps<typeof CalendarNextPart>) {
  return <CalendarNextPart className={cn(pressable, className)} {...props} />
}

/* One month. Its rows are keyed by the month, so a new month arrives as new rows.
   The keys: neutral surfaces that follow the text colour until you give them your own. They glide
   on a spring, and fade in late when a month that holds the chosen day arrives, so they land
   after the weeks have slid in. In "multiple" mode there is no single key to glide. */
function CalendarGrid({
  className,
  children,
  offset = 0,
  ...props
}: React.ComponentProps<typeof CalendarGridPart>) {
  const shown = React.useContext(PickerContext)?.shown ?? null
  return (
    <CalendarGridPart
      offset={offset}
      className={cn(
        "relative isolate [anchor-scope:--kf-day-a,--kf-day-b]",
        "before:pointer-events-none before:absolute before:-z-10 before:opacity-0 before:content-[''] before:[position-anchor:--kf-day-a]",
        "before:bg-[color-mix(in_oklch,currentColor_9%,transparent)]",
        "before:top-[anchor(top)] before:right-[anchor(right)] before:bottom-[anchor(bottom)] before:left-[anchor(left)]",
        "before:[transition:top_calc(300ms*var(--kf-speed,1))_var(--ease-spring),right_calc(300ms*var(--kf-speed,1))_var(--ease-spring),bottom_calc(300ms*var(--kf-speed,1))_var(--ease-spring),left_calc(300ms*var(--kf-speed,1))_var(--ease-spring),opacity_calc(220ms*var(--kf-speed,1))_var(--ease-house)_calc(180ms*var(--kf-speed,1))]",
        "motion-reduce:before:[transition:none]!",
        "after:pointer-events-none after:absolute after:-z-10 after:opacity-0 after:content-[''] after:[position-anchor:--kf-day-b]",
        "after:bg-[color-mix(in_oklch,currentColor_9%,transparent)]",
        "after:top-[anchor(top)] after:right-[anchor(right)] after:bottom-[anchor(bottom)] after:left-[anchor(left)]",
        "after:[transition:top_calc(300ms*var(--kf-speed,1))_var(--ease-spring),right_calc(300ms*var(--kf-speed,1))_var(--ease-spring),bottom_calc(300ms*var(--kf-speed,1))_var(--ease-spring),left_calc(300ms*var(--kf-speed,1))_var(--ease-spring),opacity_calc(220ms*var(--kf-speed,1))_var(--ease-house)_calc(180ms*var(--kf-speed,1))]",
        "motion-reduce:after:[transition:none]!",
        "has-[[data-slot=calendar-day][data-selected]:not([data-range-middle]),[data-slot=calendar-day][data-range-start]]:before:opacity-100",
        "has-[[data-slot=calendar-day][data-range-end]]:after:opacity-100",
        className,
      )}
      {...props}
    >
      {(grid) => {
        if (shown && offset === 0) shown.current = grid.month
        return (
          <React.Fragment key={grid.month}>
            {typeof children === "function"
              ? children(grid)
              : (children ?? (
                  <>
                    <CalendarWeekdays />
                    <CalendarWeeks />
                  </>
                ))}
          </React.Fragment>
        )
      }}
    </CalendarGridPart>
  )
}

/* Direction: the new weeks come 28px from the side the months turned to, blurred, on a spring. */
function CalendarWeeks({
  className,
  children,
  ...props
}: React.ComponentProps<typeof CalendarWeeksPart>) {
  return (
    <CalendarWeeksPart
      className={cn(
        "transition-[opacity,filter,translate] duration-[calc(460ms*var(--kf-speed,1))] ease-spring",
        "starting:opacity-0 starting:blur-[6px]",
        "group-data-[direction=none]/picker-content:starting:opacity-100 group-data-[direction=none]/picker-content:starting:blur-none",
        "group-data-[direction=next]/picker-content:starting:translate-x-7 group-data-[direction=previous]/picker-content:starting:-translate-x-7",
        "motion-reduce:transition-none!",
        className,
      )}
      {...props}
    >
      {children ?? ((cell) => <CalendarDay value={cell.date} />)}
    </CalendarWeeksPart>
  )
}

/* Names itself as the anchor the grid's keys follow, and gives under the pointer. */
function CalendarDay({ className, ...props }: React.ComponentProps<typeof CalendarDayPart>) {
  return (
    <CalendarDayPart
      className={cn(
        "data-selected:not-data-range-middle:not-data-range-end:[anchor-name:--kf-day-a] data-range-start:[anchor-name:--kf-day-a]",
        "data-range-end:[anchor-name:--kf-day-b] data-range-start:data-range-end:[anchor-name:--kf-day-a,--kf-day-b]",
        "transition-[scale] duration-[calc(200ms*var(--kf-speed,1))] ease-pop active:scale-[0.9] data-disabled:active:scale-100 motion-reduce:transition-none!",
        className,
      )}
      {...props}
    />
  )
}

export {
  CalendarDay,
  CalendarGrid,
  CalendarNext,
  CalendarPrevious,
  CalendarWeeks,
  DatePicker,
  DatePickerContent,
  DatePickerPreset,
  DatePickerTrigger,
}
```

## Questions

### How does the animated Date Picker for UI SDK move?

Unfold: The calendar unfolds from the field. Glide: Inside, the selected-day key glides to its new place. Direction: Months slide in from the side you turned to.

### Do I need Motion or Framer Motion for the animated Date Picker?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

### Can I keep my own styling and only take the motion?

Yes. Import from `@/components/keyframery/primitives/date-picker` instead. It has the same parts and props as `@ui-sdk/react/date-picker` and adds motion only.

### What happens to the Date Picker when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.
