DatePicker
A date field with its own calendar, built from scratch.
import { DatePicker } from '@/design-system';Examples
'use client';
import { useState } from 'react';
import { DatePicker, Field } from '@/design-system';
export default function DatePickerBasic() {
const [date, setDate] = useState('');
return (
<div className="grid gap-4 sm:grid-cols-2">
<Field label="Date" hint={date ? `Value: ${date}` : 'Nothing chosen.'}>
<DatePicker value={date} onChange={setDate} />
</Field>
<Field label="Within a range">
<DatePicker
defaultValue="2027-03-15"
min="2027-03-10"
max="2027-04-20"
/>
</Field>
</div>
);
}How it works
- Values are
YYYY-MM-DDstrings. Dates are shown in US English, with weeks starting on Sunday. A date cannot be typed. - In the calendar, arrows move by a day or a week, Home and End to the ends of the week, and Page Up and Page Down by a month (with Shift, a year). Enter chooses and Escape closes.
- The popup opens below when it fits, otherwise on the side with more room. It stays inside the window, scrolls when too tall, and follows the control while the page scrolls or resizes.
- It is drawn above everything, including inside a
Dialog, and keeps the theme around it. It uses the browser’s popover support. - With a
name, a hidden input sends the value with a form. It has norequiredprop, so check the value yourself.
Props
DatePicker takes only these props.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | The chosen date, when you keep the state. |
defaultValue | string | '' | The starting date. |
onChange | (value: string) => void | — | Called with the chosen date. |
min | string | — | The first date that can be chosen. |
max | string | — | The last date that can be chosen. |
name | string | — | Sends the value with a form. |
placeholder | string | 'Choose a date' | Shown while no date is chosen. |
disabled | boolean | false | Stops it being used. |
id | string | from Field | The id of the control. |
aria-label | string | — | A name, when it is used without a Field. |
className | string | — | Extra classes, for spacing or width. |
Tokens
| Token | Default | Sets |
|---|---|---|
--field-radius | --radius-control | Corner radius of the closed control |
--field-background | --surface | Fill |
--field-border | --border | Border colour |
--field-font-size | 0.875rem | Text size |
--popup-radius | --radius-control | Corner radius of the popup |
--popup-background | --surface | Popup fill |
--popup-border | --border | Popup border |
--popup-shadow | a soft shadow | Popup shadow |
--day-radius | --radius-control | Corner radius of a day |