---
title: "Date Picker · UI SDK — StyleX Blocks"
description: "Date input with calendar trigger, month navigation, and a selectable day grid."
url: "https://stylexblocks.com/components/ui-sdk/date-picker/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Date Picker

Date input with calendar trigger, month navigation, and a selectable day grid.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/date-picker.md), [Base UI](https://stylexblocks.com/components/base-ui/date-picker.md)
- Category: Form
- Sizes: xs, sm, md, lg, xl
- HTML page: https://stylexblocks.com/components/ui-sdk/date-picker/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add date-picker
```

Equivalent: `npx shadcn add @stylexblocks/date-picker`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/date-picker.json

## Usage

```tsx
import { DatePicker } from "#components/ui/ui-sdk/date-picker.tsx";

export function Example() {
  return (
    // ISO string values; the input accepts a typed date (Enter or blur
    // commits it). Content renders the month navigation and day grid —
    // drop `inline` to open it as a top-layer popup from the Trigger.
    <DatePicker.Root inline defaultValue="2026-03-18" locale="en-US" size="md">
      <DatePicker.Label>Delivery date</DatePicker.Label>
      <DatePicker.Control>
        <DatePicker.Input />
        <DatePicker.IndicatorGroup>
          <DatePicker.Trigger />
        </DatePicker.IndicatorGroup>
      </DatePicker.Control>
      <DatePicker.Content />
    </DatePicker.Root>
  );
}

// controlled: <DatePicker.Root value={date} onValueChange={(value) => setDate(value)}>
// range: <DatePicker.Root mode="range"> with <DatePicker.Input /> + <DatePicker.Input end />
// limits: <DatePicker.Root min="2026-03-01" unavailable={{ weekday: [0, 6] }}>
// custom grid: <DatePicker.Content>
//   <DatePicker.View>
//     <DatePicker.ViewControl>…</DatePicker.ViewControl>
//     <DatePicker.Table>
//       <DatePicker.TableHead>{(i) => <DatePicker.TableHeader index={i} />}</DatePicker.TableHead>
//       <DatePicker.TableBody>{(cell) => <DatePicker.Day value={cell.date} />}</DatePicker.TableBody>
//     </DatePicker.Table>
//   </DatePicker.View>
// </DatePicker.Content>
```

## Source

`components/ui/ui-sdk/date-picker.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createContext, useContext, useId, useMemo } from "react";
import { renderElement, mergeProps, type PartProps } from "@ui-sdk/react/primitive";
import {
  CalendarDay,
  CalendarGrid,
  CalendarHeading,
  CalendarMonthSelect,
  CalendarNext,
  CalendarPrevious,
  CalendarWeekday,
  CalendarWeekdays,
  CalendarWeeks,
  CalendarYearSelect,
  createDatePickerController,
  DatePicker as UiSdkDatePicker,
  DatePickerClear,
  DatePickerContent,
  DatePickerHint,
  DatePickerInput,
  DatePickerTrigger,
} from "@ui-sdk/react/date-picker";
import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  resolveSlotStyles,
  type SlotRecipeVariants,
} from "#lib/recipe-props.ts";
import { semanticShadows } from "@stylexblocks/ui/semantic-tokens/shadows.stylex.ts";
import {
  datePickerTriggerIconVars,
  datePickerPrevTriggerIconVars,
  datePickerNextTriggerIconVars,
  datePickerClearTriggerIconVars,
} from '@stylexblocks/ui/slot-recipes/date-picker.stylex.ts'

import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'


const datePickerRoot = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._1_5,
    width: sizes.full,
    '--datepicker-indicators-offset': sizes._3,
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
  },
})

const datePickerRootSizes = stylex.create({
  xs: {
    '--datepicker-input-height': sizes._6,
    '--datepicker-input-px': sizes._2,
    '--datepicker-indicators-offset': sizes._2,
  },
  sm: {
    '--datepicker-input-height': sizes._7,
    '--datepicker-input-px': sizes._2_5,
    '--datepicker-indicators-offset': sizes._2_5,
  },
  md: {
    '--datepicker-input-height': sizes._8,
    '--datepicker-input-px': sizes._3,
  },
  lg: {
    '--datepicker-input-height': sizes._10,
    '--datepicker-input-px': sizes._4_5,
  },
  xl: {
    '--datepicker-input-height': sizes._12,
    '--datepicker-input-px': sizes._6,
  },
})

const datePickerLabel = stylex.create({
  base: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    fontWeight: fontWeights.medium,
  },
})

const datePickerIndicatorGroup = stylex.create({
  base: {
    position: 'absolute',
    insetInlineEnd: 'var(--datepicker-indicators-offset)',
    top: '50%',
    transform: 'translateY(-50%)',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    gap: spacing._1,
  },
})

const datePickerIndicatorGroupVariants = stylex.create({
  flushed: {
    insetInlineEnd: 0,
  },
})

const datePickerControl = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    gap: spacing._2,
    width: sizes.full,
    position: 'relative',
  },
})

const datePickerInput = stylex.create({
  base: {
    flex: 1,
    minWidth: 0,
    height: 'var(--datepicker-input-height)',
    '--input-height': 'var(--datepicker-input-height)',
    paddingInline: 'var(--datepicker-input-px)',
    paddingInlineEnd: `calc(var(--datepicker-indicators-offset) + ${sizes._6})`,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    backgroundColor: 'transparent',
    borderRadius: semanticRadii.controlMd,
    outline: 'none',
    appearance: 'none',
    color: semanticColors.fg,
    '--focus-color': colorPalette.focusRing,
    '--error-color': semanticColors.borderError,
    '--focus-ring-color': {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
    borderColor: {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
  },
})

const datePickerInputVariants = stylex.create({
  outline: {
    backgroundColor: 'transparent',
    borderWidth: '1px',
    borderColor: {
      default: semanticColors.border,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    '--focus-ring-color': {
      default: 'var(--focus-color)',
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
  },
  subtle: {
    borderWidth: '1px',
    borderColor: {
      default: 'transparent',
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
    backgroundColor: semanticColors.bgMuted,
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    '--focus-ring-color': {
      default: 'var(--focus-color)',
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
  },
  flushed: {
    backgroundColor: 'transparent',
    borderBottomWidth: '1px',
    borderBottomColor: semanticColors.border,
    borderRadius: 0,
    paddingInline: 0,
    borderColor: {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
      ':focus-visible': {
        default: 'var(--focus-color)',
        ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
      },
    },
    boxShadow: {
      default: null,
      ':focus-visible': {
        default: '0px 1px 0px 0px var(--focus-color)',
        ':is([data-invalid], [aria-invalid="true"])':
          '0px 1px 0px 0px var(--error-color)',
      },
    },
  },
})

const datePickerTrigger = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    width: sizes._6,
    height: sizes._6,
    borderRadius: semanticRadii.controlSm,
    color: {
      default: semanticColors.fgMuted,
      ':hover': semanticColors.fg,
    },
    outline: 'none',
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    focusRingWidth: '2px',
    [datePickerTriggerIconVars.width]: sizes._4,
    [datePickerTriggerIconVars.height]: sizes._4,
  },
})

const datePickerTriggerIcon = stylex.create({
  base: {
    width: datePickerTriggerIconVars.width,
    height: datePickerTriggerIconVars.height,
  },
})

const datePickerContent = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._3,
    padding: spacing._3,
    minWidth: '18rem',
    color: semanticColors.fg,
    '--date-picker-z-index': zIndices.layer3,
    zIndex: 'calc(var(--date-picker-z-index) + var(--layer-index, 0))',
    outline: 'none',
  },
})

const datePickerView = stylex.create({
  base: {
    display: 'flex',
    flexDirection: 'column',
    gap: spacing._3,
  },
})

const datePickerViewSizes = stylex.create({
  xs: {
    '--table-cell-size': sizes._8,
    '--datepicker-nav-trigger-size': sizes._7,
    '--datepicker-select-height': sizes._8,
  },
  sm: {
    '--table-cell-size': sizes._9,
    '--datepicker-nav-trigger-size': sizes._8,
    '--datepicker-select-height': sizes._9,
  },
  md: {
    '--table-cell-size': sizes._10,
    '--datepicker-nav-trigger-size': sizes._8,
    '--datepicker-select-height': sizes._10,
  },
  lg: {
    '--table-cell-size': sizes._10,
    '--datepicker-nav-trigger-size': sizes._9,
    '--datepicker-select-height': sizes._10,
  },
  xl: {
    '--table-cell-size': sizes._10,
    '--datepicker-nav-trigger-size': sizes._9,
    '--datepicker-select-height': sizes._10,
  },
})

const datePickerViewControl = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'space-between',
    gap: spacing._2,
    height: 'var(--datepicker-nav-trigger-size)',
  },
})

const datePickerViewTrigger = stylex.create({
  base: {
    display: 'inline-flex',
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    gap: spacing._1,
    paddingBlock: spacing._1_5,
    paddingInline: spacing._2,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    fontWeight: fontWeights.semibold,
    borderRadius: semanticRadii.controlMd,
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    focusRingWidth: '2px',
    backgroundColor: {
      default: null,
      ':hover': colorPalette.subtle,
    },
  },
})

const datePickerPrevTrigger = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    width: 'var(--datepicker-nav-trigger-size)',
    height: 'var(--datepicker-nav-trigger-size)',
    borderRadius: semanticRadii.controlMd,
    color: semanticColors.fg,
    boxShadow: {
      default: null,
      ':focus-visible': '0 0 0 2px var(--colors-color-palette-focus-ring)',
    },
    focusRingWidth: '2px',
    backgroundColor: {
      default: null,
      ':hover': colorPalette.subtle,
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    [datePickerPrevTriggerIconVars.width]: sizes._4,
    [datePickerPrevTriggerIconVars.height]: sizes._4,
  },
})

const datePickerPrevTriggerIcon = stylex.create({
  base: {
    width: datePickerPrevTriggerIconVars.width,
    height: datePickerPrevTriggerIconVars.height,
  },
})

const datePickerNextTrigger = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    width: 'var(--datepicker-nav-trigger-size)',
    height: 'var(--datepicker-nav-trigger-size)',
    borderRadius: semanticRadii.controlMd,
    color: semanticColors.fg,
    boxShadow: {
      default: null,
      ':focus-visible': '0 0 0 2px var(--colors-color-palette-focus-ring)',
    },
    focusRingWidth: '2px',
    backgroundColor: {
      default: null,
      ':hover': colorPalette.subtle,
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    [datePickerNextTriggerIconVars.width]: sizes._4,
    [datePickerNextTriggerIconVars.height]: sizes._4,
  },
})

const datePickerNextTriggerIcon = stylex.create({
  base: {
    width: datePickerNextTriggerIconVars.width,
    height: datePickerNextTriggerIconVars.height,
  },
})

const datePickerRangeText = stylex.create({
  base: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    fontWeight: fontWeights.semibold,
  },
})

const datePickerTable = stylex.create({
  base: {
    borderCollapse: 'separate',
    borderSpacing: 0,
  },
})

const datePickerTableHeader = stylex.create({
  base: {
    width: 'var(--table-cell-size)',
    paddingBlock: spacing._2,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    fontWeight: fontWeights.medium,
    color: semanticColors.fgMuted,
    textAlign: 'center',
    textTransform: 'uppercase',
  },
})

const datePickerTableCell = stylex.create({
  base: {
    paddingBlock: spacing._0_5,
  },
})

const datePickerTableCellTrigger = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    minWidth: 'var(--table-cell-size)',
    minHeight: 'var(--table-cell-size)',
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    borderRadius: semanticRadii.controlMd,
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    focusRingWidth: '2px',
    focusRingOffset: '0px',
    cursor: 'default',
    position: 'relative',
    backgroundColor: {
      default: null,
      ':hover': colorPalette.subtle,
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.4,
    },
  },
})

const datePickerTableCellTriggerHideOutsideDays = stylex.create({
  true: {},
})

const datePickerMonthSelect = stylex.create({
  base: {
    height: 'var(--datepicker-select-height)',
    paddingInlineStart: spacing._2,
    paddingInlineEnd: spacing._8,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    borderWidth: '1px',
    borderRadius: semanticRadii.controlMd,
    outline: 'none',
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    appearance: 'none',
    fieldSizing: 'content',
    backgroundImage:
      "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E\")",
    backgroundRepeat: 'no-repeat',
    backgroundPosition: 'right 0.375rem center',
    backgroundSize: '1.25em',
  },
})

const datePickerYearSelect = stylex.create({
  base: {
    height: 'var(--datepicker-select-height)',
    paddingInlineStart: spacing._2,
    paddingInlineEnd: spacing._8,
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    borderWidth: '1px',
    borderRadius: semanticRadii.controlMd,
    outline: 'none',
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    appearance: 'none',
    fieldSizing: 'content',
    backgroundImage:
      "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E\")",
    backgroundRepeat: 'no-repeat',
    backgroundPosition: 'right 0.375rem center',
    backgroundSize: '1.25em',
  },
})

const datePickerClearTrigger = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    width: sizes._6,
    height: sizes._6,
    flexShrink: 0,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    borderRadius: semanticRadii.controlMd,
    color: {
      default: semanticColors.fgMuted,
      ':hover': semanticColors.fg,
    },
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    [datePickerClearTriggerIconVars.width]: sizes._4,
    [datePickerClearTriggerIconVars.height]: sizes._4,
  },
})

const datePickerClearTriggerIcon = stylex.create({
  base: {
    width: datePickerClearTriggerIconVars.width,
    height: datePickerClearTriggerIconVars.height,
  },
})

export type DatePickerSize = keyof typeof datePickerRootSizes

export type DatePickerHideOutsideDays =
  keyof typeof datePickerTableCellTriggerHideOutsideDays

export type DatePickerVariant = keyof typeof datePickerIndicatorGroupVariants

const datePickerRecipe = defineSlotRecipe({
  slots: {
    root: { styles: datePickerRoot, sizes: datePickerRootSizes },
    label: { styles: datePickerLabel },
    indicatorGroup: {
      styles: datePickerIndicatorGroup,
      variants: datePickerIndicatorGroupVariants,
    },
    control: { styles: datePickerControl },
    input: { styles: datePickerInput, variants: datePickerInputVariants },
    trigger: { styles: datePickerTrigger },
    content: { styles: datePickerContent },
    view: { styles: datePickerView, sizes: datePickerViewSizes },
    viewControl: { styles: datePickerViewControl },
    viewTrigger: { styles: datePickerViewTrigger },
    prevTrigger: { styles: datePickerPrevTrigger },
    nextTrigger: { styles: datePickerNextTrigger },
    rangeText: { styles: datePickerRangeText },
    table: { styles: datePickerTable },
    tableHeader: { styles: datePickerTableHeader },
    tableCell: { styles: datePickerTableCell },
    tableCellTrigger: { styles: datePickerTableCellTrigger },
    monthSelect: { styles: datePickerMonthSelect },
    yearSelect: { styles: datePickerYearSelect },
    clearTrigger: { styles: datePickerClearTrigger },
  },
  defaultVariants: { size: "md", variant: "outline" },
});

const chrome = stylex.create({
  btnReset: {
    appearance: "none",
    backgroundColor: "transparent",
    borderWidth: 0,
    borderStyle: "none",
    padding: 0,
    margin: 0,
    fontFamily: "inherit",
    fontSize: "inherit",
    color: "inherit",
    cursor: "pointer",
    textAlign: "inherit",
  },
  panel: {
    backgroundColor: semanticColors.bgPanel,
    borderRadius: semanticRadii.panel,
    boxShadow: semanticShadows.overlay,
  },
  // UI SDK's Content is a top-layer popover that keeps the browser's own
  // popover border, so the panel clears it and only lays out while open
  popover: {
    display: {
      default: null,
      ":popover-open": "flex",
    },
    borderWidth: 0,
    borderStyle: "none",
    margin: 0,
  },
  heading: { margin: 0 },
  // the cells' vertical rhythm: the recipe pads the td around a button;
  // UI SDK's day IS the td, so the table spaces the rows instead
  table: { borderSpacing: `0 ${spacing._0_5}` },
  // UI SDK's CalendarDay is the focusable gridcell itself (no inner
  // button): it wears the cell-trigger look as a table cell, and the
  // selected day uses `data-selected` (Ark: data-selected on the trigger)
  day: {
    display: "table-cell",
    textAlign: "center",
    verticalAlign: "middle",
    width: "var(--table-cell-size)",
    height: "var(--table-cell-size)",
    paddingBlock: 0,
    cursor: {
      default: "pointer",
      ":is([data-disabled], [data-unavailable])": "not-allowed",
    },
    backgroundColor: {
      default: null,
      ":hover": colorPalette.subtle,
      ":is([data-selected])": semanticColors.indigoSolid,
      ":is([data-selected]):hover": semanticColors.indigoSolid,
    },
    color: {
      default: null,
      ":is([data-outside])": semanticColors.fgMuted,
      ":is([data-selected])": semanticColors.indigoContrast,
    },
    opacity: {
      default: null,
      ":is([data-outside])": 0.5,
      ":is([data-disabled], [data-unavailable])": 0.4,
    },
    textDecoration: {
      default: null,
      ":is([data-unavailable])": "line-through",
    },
  },
});

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

function ChevronLeftIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="M10 4 6 8l4 4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

function ChevronRightIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="m6 4 4 4-4 4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

function CloseIcon(props: React.ComponentProps<"svg">) {
  return (
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true" {...props}>
      <path d="m4 4 8 8m0-8-8 8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
    </svg>
  );
}

interface PickerLayout {
  inline: boolean;
  inputId: string;
}

const PickerLayoutContext = createContext<PickerLayout>({ inline: false, inputId: "" });

const { withProvider, withContext } = createSlotRecipeContext(datePickerRecipe);

export type DatePickerVariantProps = Partial<SlotRecipeVariants<typeof datePickerRecipe>> & {
  hideOutsideDays?: boolean;
  inline?: boolean;
};

type RootNodeProps = React.ComponentProps<typeof UiSdkDatePicker> & {
  /** Leave the days of the neighbouring months out of the grid (default). */
  hideOutsideDays?: boolean;
  /** Render Content in place, always visible, instead of as a popup. */
  inline?: boolean;
};

function RootNode({
  hideOutsideDays = true,
  inline = false,
  weekdayFormat = "narrow",
  ...rest
}: RootNodeProps) {
  const inputId = useId();
  const layout = useMemo(() => ({ inline, inputId }), [inline, inputId]);
  return (
    <PickerLayoutContext.Provider value={layout}>
      <UiSdkDatePicker
        showOutsideDays={!hideOutsideDays}
        weekdayFormat={weekdayFormat}
        {...rest}
      />
    </PickerLayoutContext.Provider>
  );
}

/** A native label tied to the (start) input. */
function LabelNode(props: React.ComponentProps<"label">) {
  const { inputId } = useContext(PickerLayoutContext);
  return <label htmlFor={inputId} {...props} />;
}

function InputNode(props: React.ComponentProps<typeof DatePickerInput>) {
  const { inputId } = useContext(PickerLayoutContext);
  return <DatePickerInput id={props.end ? undefined : inputId} {...props} />;
}

const StyledTrigger = withContext(
  DatePickerTrigger,
  (v) => [chrome.btnReset, ...resolveSlotStyles(datePickerRecipe.slots.trigger, v)],
  "DatePickerTrigger",
);

function Trigger(props: React.ComponentProps<typeof StyledTrigger>) {
  const { children, ...rest } = props;
  return (
    <StyledTrigger {...rest}>
      {children ?? <CalendarIcon {...stylex.props(datePickerTriggerIcon.base)} />}
    </StyledTrigger>
  );
}
Trigger.displayName = "DatePickerTrigger";

const StyledClearTrigger = withContext(
  DatePickerClear,
  (v) => [chrome.btnReset, ...resolveSlotStyles(datePickerRecipe.slots.clearTrigger, v)],
  "DatePickerClearTrigger",
);

function ClearTrigger(props: React.ComponentProps<typeof StyledClearTrigger>) {
  const { children, ...rest } = props;
  return (
    <StyledClearTrigger aria-label="Clear date" {...rest}>
      {children ?? <CloseIcon {...stylex.props(datePickerClearTriggerIcon.base)} />}
    </StyledClearTrigger>
  );
}
ClearTrigger.displayName = "DatePickerClearTrigger";

const StyledPrevTrigger = withContext(
  CalendarPrevious,
  (v) => [chrome.btnReset, ...resolveSlotStyles(datePickerRecipe.slots.prevTrigger, v)],
  "DatePickerPrevTrigger",
);

function PrevTrigger(props: React.ComponentProps<typeof StyledPrevTrigger>) {
  const { children, ...rest } = props;
  return (
    <StyledPrevTrigger aria-label="Previous month" {...rest}>
      {children ?? <ChevronLeftIcon {...stylex.props(datePickerPrevTriggerIcon.base)} />}
    </StyledPrevTrigger>
  );
}
PrevTrigger.displayName = "DatePickerPrevTrigger";

const StyledNextTrigger = withContext(
  CalendarNext,
  (v) => [chrome.btnReset, ...resolveSlotStyles(datePickerRecipe.slots.nextTrigger, v)],
  "DatePickerNextTrigger",
);

function NextTrigger(props: React.ComponentProps<typeof StyledNextTrigger>) {
  const { children, ...rest } = props;
  return (
    <StyledNextTrigger aria-label="Next month" {...rest}>
      {children ?? <ChevronRightIcon {...stylex.props(datePickerNextTriggerIcon.base)} />}
    </StyledNextTrigger>
  );
}
NextTrigger.displayName = "DatePickerNextTrigger";

const View = withContext("div", "view", "DatePickerView");
const ViewControl = withContext("div", "viewControl", "DatePickerViewControl");
// UI SDK has no month/year views to switch to: the heading sits in a span
const ViewTrigger = withContext("span", "viewTrigger", "DatePickerViewTrigger");
const RangeText = withContext(
  CalendarHeading,
  (v) => [...resolveSlotStyles(datePickerRecipe.slots.rangeText, v), chrome.heading],
  "DatePickerRangeText",
);
const Table = withContext(
  CalendarGrid,
  (v) => [...resolveSlotStyles(datePickerRecipe.slots.table, v), chrome.table],
  "DatePickerTable",
);
const TableHeader = withContext(CalendarWeekday, "tableHeader", "DatePickerTableHeader");
const Day = withContext(
  CalendarDay,
  (v) => [
    chrome.btnReset,
    ...resolveSlotStyles(datePickerRecipe.slots.tableCellTrigger, v),
    chrome.day,
  ],
  "DatePickerDay",
);

/** The default month view: navigation row and day grid, as in the other engines. */
function DefaultCalendar() {
  return (
    <View>
      <ViewControl>
        <PrevTrigger />
        <ViewTrigger>
          <RangeText />
        </ViewTrigger>
        <NextTrigger />
      </ViewControl>
      <Table>
        <CalendarWeekdays>{(index) => <TableHeader index={index} />}</CalendarWeekdays>
        <CalendarWeeks>{(cell) => <Day value={cell.date} />}</CalendarWeeks>
      </Table>
    </View>
  );
}

function InlineContent({ render, children, ...rest }: PartProps<"div">) {
  return renderElement(
    "div",
    mergeProps({ children: children ?? <DefaultCalendar /> }, rest),
    render as never,
    {},
  );
}

const StyledPopupContent = withContext(
  DatePickerContent,
  (v) => [...resolveSlotStyles(datePickerRecipe.slots.content, v), chrome.panel, chrome.popover],
  "DatePickerContent",
);
const StyledInlineContent = withContext(
  InlineContent,
  (v) => [...resolveSlotStyles(datePickerRecipe.slots.content, v), chrome.panel],
  "DatePickerContent",
);

/**
 * Content — the calendar panel. A top-layer popup anchored to the input
 * (opened by Trigger, closed on pick), or in place with `<Root inline>`.
 * Renders the month navigation and day grid when given no children.
 */
function Content(props: React.ComponentProps<typeof StyledPopupContent>) {
  const { inline } = useContext(PickerLayoutContext);
  const { children, ...rest } = props;
  if (inline) {
    return (
      <StyledInlineContent {...(rest as React.ComponentProps<typeof StyledInlineContent>)}>
        {children as React.ReactNode}
      </StyledInlineContent>
    );
  }
  return (
    <StyledPopupContent sideOffset={4} {...rest}>
      {children ?? <DefaultCalendar />}
    </StyledPopupContent>
  );
}
Content.displayName = "DatePickerContent";

/**
 * DatePicker — UI SDK's date-picker primitive (a typed date field plus its
 * Calendar) wearing the date-picker slot recipe. Values are ISO strings like
 * `"2026-03-18"` (`[start, end]` with `mode="range"`); the Input accepts a
 * typed date in the locale's format and commits it on Enter or blur.
 * `<DatePicker.Root size>` resolves the recipe once; every part inherits it
 * through context. Content renders the month navigation and day grid by
 * default, as a popup or in place with `inline`. The calendar parts (View,
 * ViewControl, Prev/NextTrigger, RangeText, Table, TableHead/TableHeader,
 * TableBody/Day) compose a custom month view; the grid renders its own
 * rows, so there are no TableRow / TableCell parts.
 */
export const DatePicker = {
  Root: withProvider(RootNode, "root", "DatePickerRoot"),
  Label: withContext(LabelNode, "label", "DatePickerLabel"),
  Control: withContext("div", "control", "DatePickerControl"),
  Input: withContext(InputNode, "input", "DatePickerInput"),
  /** Describes the expected format, like "mm/dd/yyyy". */
  Hint: DatePickerHint,
  Trigger,
  ClearTrigger,
  IndicatorGroup: withContext("div", "indicatorGroup", "DatePickerIndicatorGroup"),
  Content,
  View,
  ViewControl,
  ViewTrigger,
  RangeText,
  PrevTrigger,
  NextTrigger,
  Table,
  /** Header row; children are a function of each column index. */
  TableHead: CalendarWeekdays,
  TableHeader,
  /** Week rows; children are a function of each cell (`cell.date`). */
  TableBody: CalendarWeeks,
  Day,
  MonthSelect: withContext(CalendarMonthSelect, "monthSelect", "DatePickerMonthSelect"),
  YearSelect: withContext(CalendarYearSelect, "yearSelect", "DatePickerYearSelect"),
};

export { createDatePickerController };

export type DatePickerRootProps = React.ComponentProps<typeof DatePicker.Root>;
```
