All components
xs
sm
md
lg
xl
Date Picker
Date input with calendar trigger, month navigation, and a selectable day grid.
March 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
1234567891011121314151617181920212223242526272829303132import { 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>Sizes
March 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
March 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
March 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
March 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
March 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
Install
1npx stylexblocks add date-pickerSource
components/ui/ui-sdk/date-picker.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020import * 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 spanconst 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>;