Molecules · Date presets
Date presets
Named periods such as Last 7 days, one click each. The defaults: Today, Yesterday, Last 7 days, Last 30 days, This month, Last month, This year, or your own. An add-on: put it in a DateRangePicker's aside and it reads and sets the picker's range by itself, then closes it. On its own it is a list you give a value and an onSelect. Installs DateRangePicker and DatePicker with it.
- Best for
- Reports and logs, where people want the usual periods.
- Not for
- Exact dates: DateRangePicker alone.
This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).
Examples
Inside a DateRangePicker: no wiring
Code
tsx
<div className="w-full max-w-sm"> <DateRangePicker label="Activity" aside={<DatePresets />} /></div>On its own
2026-11-28 to 2026-12-04
Code
tsx
function OnItsOwn() { const [range, setRange] = useState<DateRange>(defaultPresets()[2].range) return ( <div className="flex flex-col gap-3"> <DatePresets value={range} onSelect={setRange} /> <span className="font-mono text-xs text-[var(--color-text-secondary)]"> {range.start} to {range.end} </span> </div> )}<OnItsOwn />Your own periods
Code
tsx
<div className="w-full max-w-sm"> <DateRangePicker label="Season" aside={ <DatePresets label="Seasons" presets={[ { label: 'Winter 2026', range: { start: '2026-01-01', end: '2026-03-31' } }, { label: 'Spring 2026', range: { start: '2026-04-01', end: '2026-06-30' } }, { label: 'Summer 2026', range: { start: '2026-07-01', end: '2026-09-30' } }, ]} /> } /></div>Anatomy
| Part | What it is |
|---|---|
| List | A group named "Presets". Each period is a button; the one matching the current range is pressed (aria-pressed) and takes the neutral selected look: a selected surface and a 2px signal bar at its start. |
Props
- presetsDatePreset[]Default defaultPresets()
- Each { label, range }. Make your own, or start from defaultPresets(today).
- value{ start: string; end: string }
- The current range. Inside a DateRangePicker it comes from the picker.
- onSelect(range: DateRange) => void
- A preset was chosen. Inside a DateRangePicker the picker also takes it and closes.
- labelstringDefault 'Presets'
- The list's accessible name.
- classNamestring
- Combined with the list's classes.
- refRef<HTMLDivElement>
- The list element.
- defaultPresets()(today?: string) => DatePreset[]
- The seven usual periods counted back from today ('YYYY-MM-DD'; defaults to the reader's today). Every one includes today.
Keyboard
| Keys | Result |
|---|---|
| Tab | Moves through the presets. |
| EnterSpace | Chooses the focused preset. |
Do and don't
Do
- Keep the list short, seven or fewer.
- Name periods the way your users say them: "This quarter" if they plan in quarters.
Don't
- Don't offer a preset nobody can pick, such as a future period when max is today.