Date Picker

Calendar in a Popover with a trigger that reads like an Input. Every Calendar capability passes through — range, presets, times, multiple months — so there is one date implementation, not two.

src/components/ui/date-picker.tsx

About

From the component's own source, where it was written.

The same three treatments Input and Select offer.

Install

npx astralyx-ui add date-picker

Usage

import { DatePicker } from '@/components/ui/date-picker'

<DatePicker value={date} onValueChange={setDate} />

<DatePicker
  mode="range"
  presets={defaultPresets()}
  onValueChange={setRange}
/>

Composer

Change the props and the source below follows.

Props
tsx
<DatePicker
  size="md"
  locale="en-GB"
  onValueChange={setValue}
/>

Examples

Single and range

With a time

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

DatePicker

Extends Omit<ComponentProps<'button'>, 'value' | 'defaultValue' | 'onSelect' | 'mode'>.

PropTypeDefaultDescription
placeholderstring——
localestring——
fromDateDate—Bounds and an arbitrary per-day rule. Named disabledDate here so it does not collide with the trigger's own disabled.
toDateDate—Bounds and an arbitrary per-day rule. Named disabledDate here so it does not collide with the trigger's own disabled.
disabledboolean——
disabledDate(date: Date) => boolean—Bounds and an arbitrary per-day rule. Named disabledDate here so it does not collide with the trigger's own disabled.
sizekeyof typeof fieldSize'md'Same steps as Input, so the two align in a form row.
variant'default' | 'secondary' | 'ghost' | 'default' | 'secondary' | 'ghost'—Matches Input and Select, so a form can be uniform.
errorboolean——
numberOfMonthsnumber—Forwarded to the Calendar inside.
weekStartsOnWeekStart——
captionLayout'label' | 'dropdown' | 'label' | 'dropdown'—Forwarded to the Calendar inside.
showTimeboolean—Forwarded to the Calendar inside.
timeStepnumber——
footerReactNode——
closeOnSelectboolean!showTimeA range waits for both ends. With showTime the popover stays open, since closing on the day would give no chance to set the hour.
classNamestring——
mode'single' | 'range''single'Range mode defaults to two months and formats the trigger as "from – to".
valueDate | DateRange—Controlled and uncontrolled.
defaultValueDate | DateRange—Controlled and uncontrolled.
onValueChange(date: Date) => void | (range: DateRange) => void—Fires on every pick, including the first half of a range.
presetsCalendarPreset[]—Forwarded to the Calendar inside.