All components outlinesubtleflushedxssmmdlgxlValue: incomplete
Date Input
Segmented date field with keyboard-editable month, day and year in locale order.
3182026
123456789101112131415161718192021222324import { DateInput, parseDate } from "#components/ui/ark-ui/date-input.tsx";import { indigoPalette } from "@stylexblocks/ui/themes/palettes.ts";
export function Example() { return ( // variant/size resolve once on Root; SegmentGroup renders the // locale-ordered month / day / year segments by default <DateInput.Root locale="en-US" defaultValue={[parseDate("2026-03-18")]} variant="outline" size="md" palette={indigoPalette} > <DateInput.Label>Start date</DateInput.Label> <DateInput.Control> <DateInput.SegmentGroup /> </DateInput.Control> <DateInput.HiddenInput name="start" /> </DateInput.Root> );}
// controlled: <DateInput.Root value={value} onValueChange={(d) => setValue(d.value)}>Variants
3182026
3182026
3182026
Sizes
3182026
3182026
3182026
3182026
3182026
Controlled
The value is set only once every segment is filled. Tab or ArrowLeft/Right moves between segments, ArrowUp/Down steps the focused one, typed digits fill it and jump ahead, Backspace clears.
mmddyyyy
Locale order
Segment order and separators follow the locale: German shows day, month, year separated by dots.
1832026
Install
1npx stylexblocks add date-inputSource
components/ui/ark-ui/date-input.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271import { DateInput as ArkDateInput, useDateInputContext,} from "@ark-ui/react/date-input";import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";import { defineSlotRecipe } from "#lib/recipe-props.ts";import * as stylex from "@stylexjs/stylex";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'
const dateInputRoot = stylex.create({ base: { display: 'flex', flexDirection: 'column', gap: spacing._1_5, width: '100%', },})
const dateInputLabel = stylex.create({ base: { fontSize: fontSizes.sm, lineHeight: lineHeights.sm, fontWeight: fontWeights.medium, alignSelf: 'flex-start', userSelect: 'none', opacity: { default: null, ':is([data-disabled])': 0.5, }, },})
/** The input-shaped box the segments sit in; mirrors the `input` recipe. */const dateInputControl = stylex.create({ base: { display: 'flex', alignItems: 'center', width: '100%', minWidth: 0, position: 'relative', height: 'var(--input-height)', cursor: { default: 'text', ':is([data-disabled])': 'not-allowed', }, color: semanticColors.fg, opacity: { default: null, ':is([data-disabled])': 0.5, }, '--focus-color': colorPalette.focusRing, '--error-color': semanticColors.borderError, borderColor: { default: null, ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)', }, },})
const dateInputControlSizes = stylex.create({ xs: { borderRadius: semanticRadii.control, paddingInline: spacing._2, '--input-height': sizes.controlXs, fontSize: fontSizes.xs, lineHeight: lineHeights.xs, }, sm: { borderRadius: semanticRadii.control, paddingInline: spacing._2_5, '--input-height': sizes.controlSm, fontSize: fontSizes.sm, lineHeight: lineHeights.sm, }, md: { borderRadius: semanticRadii.control, paddingInline: spacing._3, '--input-height': sizes.controlMd, fontSize: fontSizes.sm, lineHeight: lineHeights.sm, }, lg: { borderRadius: semanticRadii.control, paddingInline: spacing._4_5, '--input-height': sizes.controlLg, fontSize: fontSizes.md, lineHeight: lineHeights.md, }, xl: { borderRadius: semanticRadii.control, paddingInline: spacing._6, '--input-height': sizes.controlXl, fontSize: fontSizes.md, lineHeight: lineHeights.md, },})
const dateInputControlVariants = stylex.create({ outline: { backgroundColor: semanticColors.bg, borderWidth: '1px', borderStyle: 'solid', borderColor: { default: semanticColors.border, ':hover': semanticColors.borderEmphasized, ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)', }, outlineWidth: { default: null, ':focus-within': 'var(--focus-ring-width, 1px)', }, outlineOffset: { default: null, ':focus-within': '0px', }, outlineStyle: { default: null, ':focus-within': 'solid', }, outlineColor: { default: null, ':focus-within': 'var(--focus-color)', }, }, subtle: { backgroundColor: semanticColors.bgMuted, borderWidth: '1px', borderStyle: 'solid', borderColor: { default: 'transparent', ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)', }, outlineWidth: { default: null, ':focus-within': 'var(--focus-ring-width, 1px)', }, outlineOffset: { default: null, ':focus-within': '0px', }, outlineStyle: { default: null, ':focus-within': 'solid', }, outlineColor: { default: null, ':focus-within': 'var(--focus-color)', }, }, flushed: { backgroundColor: 'transparent', borderRadius: 0, paddingInline: 0, borderBottomWidth: '1px', borderBottomStyle: 'solid', borderBottomColor: { default: semanticColors.border, ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)', ':focus-within': 'var(--focus-color)', }, boxShadow: { default: null, ':focus-within': '0px 1px 0px 0px var(--focus-color)', }, },})
const dateInputSegmentGroup = stylex.create({ base: { display: 'inline-flex', alignItems: 'center', whiteSpace: 'nowrap', fontVariantNumeric: 'tabular-nums', },})
const dateInputSegment = stylex.create({ base: { display: 'inline-block', paddingInline: '1px', borderRadius: semanticRadii.l1, outline: 'none', textAlign: 'end', caretColor: 'transparent', userSelect: 'none', fontVariantNumeric: 'tabular-nums', color: { default: semanticColors.fg, ':is([data-placeholder-shown]):not(:focus)': semanticColors.fgMuted, ':is([data-type="literal"])': semanticColors.fgMuted, ':focus': colorPalette.contrast, }, backgroundColor: { default: null, ':focus': colorPalette.solid, }, },})
export type DateInputSize = keyof typeof dateInputControlSizes
export type DateInputVariant = keyof typeof dateInputControlVariants
const dateInputRecipe = defineSlotRecipe({ slots: { root: { styles: dateInputRoot }, label: { styles: dateInputLabel }, control: { styles: dateInputControl, sizes: dateInputControlSizes, variants: dateInputControlVariants, }, segmentGroup: { styles: dateInputSegmentGroup }, segment: { styles: dateInputSegment }, }, defaultVariants: { size: "md", variant: "outline" },});
const { withProvider, withContext } = createSlotRecipeContext(dateInputRecipe);
const Segment = withContext(ArkDateInput.Segment, "segment", "DateInputSegment");
/** Renders the machine's locale-ordered segments when given no children. */function SegmentGroupNode({ children, ...props}: React.ComponentProps<typeof ArkDateInput.SegmentGroup>) { const api = useDateInputContext(); return ( <ArkDateInput.SegmentGroup {...props}> {children ?? api .getSegments({ index: props.index }) .map((segment, i) => <Segment key={i} segment={segment} />)} </ArkDateInput.SegmentGroup> );}
/** * DateInput — Ark UI's date-input machine: a segmented date field * (month / day / year spinbuttons in locale order; arrows increment, typed * digits auto-advance, Backspace clears) wearing the date-input slot recipe. * `<DateInput.Root variant size>` resolves the recipe once; every part * inherits it through context. Control is the input-shaped box; SegmentGroup * renders the segments by default. Values are `@internationalized/date` * `DateValue`s — build them with the re-exported `parseDate`. */export const DateInput = { Root: withProvider(ArkDateInput.Root, "root", "DateInputRoot"), Label: withContext(ArkDateInput.Label, "label", "DateInputLabel"), Control: withContext(ArkDateInput.Control, "control", "DateInputControl"), SegmentGroup: withContext(SegmentGroupNode, "segmentGroup", "DateInputSegmentGroup"), Segment, HiddenInput: ArkDateInput.HiddenInput, Context: ArkDateInput.Context,};
export { parseDate } from "@ark-ui/react/date-picker";export type { DateInputDateValue as DateValue } from "@ark-ui/react/date-input";
export type DateInputRootProps = React.ComponentProps<typeof DateInput.Root>;export type DateInputControlProps = React.ComponentProps<typeof DateInput.Control>;export type DateInputSegmentProps = React.ComponentProps<typeof DateInput.Segment>;