Date Range Picker¶
Two date boxes, from and to, each with the date field's calendar icon inside, under a row of preset pills: Today, Last 7 days, Last 30 days, and Custom. The pills are Pill Group pills on the pressed group core, the boxes come from the Field Adornments, and the range checks through the validation core.
Decision¶
| When | Use |
|---|---|
| Picking a range of days, such as for a report or a history | Date Range Picker. |
A Filtered List filter of kind daterange |
Date Range Picker. The Filtered List uses it for this filter. |
| One day | A date input, which Stolon adorns. |
| Times within a day | Time Range Field. |
Usage¶
import { createDateRangePicker } from './configurationpage?name=myplugin_stolon.js';
var range = createDateRangePicker({ onChange: function (value) { loadHistory(value.from, value.to); } });
view.querySelector('#rangeHost').appendChild(range.element);
Classes: stolon-date-range, stolon-date-range-presets, stolon-date-range-row, stolon-date-range-from, stolon-date-range-to. The handle is { element, from, to, getValue, setValue, getPreset, isValid, setSize, destroy }, and getValue() returns { from, to } as 'YYYY-MM-DD', with '' for an open side.
States and Modifiers¶
- A preset fills both dates, counting back from today. A second click on it clears them, and typing dates presses the matching preset, or Custom.
presetsreplaces the pills with[{ value, label, days }], wheredayscounts back from today and nodaysis Custom.[]hides the row. The default list isDATE_RANGE_PRESETS.getPreset()returns the pressed preset's value, ornull.setValuepresses the matching preset and does not callonChange.- An end before the start shows "End must be on or after the start.".
requiredrequires both dates, and it,min,max, andvalidate({ from, to })check through the core. todaysets the day the presets count from, the local date by default.- The labels default to "From", "To", and "Range" for the preset group.
fromLabel,toLabel, andpresetsLabelreplace them. dateKey(value)reads any date as its local day, andshiftDays(day, n)moves a day.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
DATE_RANGE_PRESETS¶
var DATE_RANGE_PRESETS: DateRangePreset[]
The presets a date range picker shows by default.
dateKey¶
function dateKey(value: unknown): string
Reads a date as the local day it falls on, as 'YYYY-MM-DD'. A 'YYYY-MM-DD' text stays as it is, and a Date, a time in milliseconds, or an ISO text with a time reads in the local time zone.
shiftDays¶
function shiftDays(day: string, days: number): string
Moves a day by a number of days, such as '2026-03-01' back one to '2026-02-28'.
createDateRangePicker¶
function createDateRangePicker(options?: DateRangePickerOptions): DateRangePickerHandle
Two date boxes, from and to, each with the date field's calendar icon inside, under a row of preset pills on the pressed group: Today, Last 7 days, Last 30 days, and Custom by default. A preset fills both dates, a second click on it clears them, and typing dates presses the matching preset, or Custom. An end before the start is an error through the validation core.
| Option | Type | What it does |
|---|---|---|
value |
Partial<DateRangeValue> | null |
{ from, to } as 'YYYY-MM-DD' [optional] |
presets |
DateRangePreset[] | null |
array of { value, label, days }, where days counts back from today and no days is Custom, or [] for none (default Today, Last 7 days, Last 30 days, and Custom) |
today |
string |
the day presets count back from, as 'YYYY-MM-DD' (default the local date) |
min |
string |
the earliest day allowed [optional] |
max |
string |
the latest day allowed [optional] |
required |
boolean |
true requires both dates (default false) |
fromLabel |
string |
aria-label of the from box (default 'From') |
toLabel |
string |
aria-label of the to box (default 'To') |
presetsLabel |
string |
aria-label of the preset group (default 'Range') |
endBeforeStartText |
string |
message for an end before the start (default 'End must be on or after the start.') |
size |
'small' | 'medium' | 'large' |
'small', 'medium', or 'large' for its fields (default 'medium') |
validate |
(value: DateRangeValue): string | null | undefined |
function({ from, to }) returning an error sentence, or an empty value when valid [optional] |
onChange |
(value: DateRangeValue): void |
function({ from, to }) after each change [optional] |
| Handle member | Type |
|---|---|
from |
HTMLInputElement |
to |
HTMLInputElement |
getValue |
(): DateRangeValue |
setValue |
(next?: Partial<DateRangeValue> | null): void |
getPreset |
(): string | null |
isValid |
(): boolean |
setSize |
(size?: 'small' | 'medium' | 'large'): void |
destroy |
(): void |
| Type | What it is |
|---|---|
DateRangeValue |
A range of days, each as 'YYYY-MM-DD', or '' while open on that side. |
DateRangePreset |
One preset pill. days sets the range to that many days ending today, so 1 is today, and no days is Custom, which leaves the dates to the reader. |
| Class | What it looks like |
|---|---|
stolon-date-range |
Preset pills over a from and a to date box, each with the calendar icon inside, and the range's message under them |
Example¶
Example Code¶
<!-- title: Date Range Picker -->
<div class="stolon-field"><label>History</label><div id="history"></div></div>
<div class="stolon-field" style="margin-top: 16px;"><label>Report</label><div id="report"></div></div>
<div class="stolon-field" style="margin-top: 16px;"><label>Activity</label><div id="list"></div></div>
<script type="module">
const base = await window.__baseReady;
const note = document.createElement('div');
note.className = 'stolon-status-text';
const history = base.createDateRangePicker({ onChange: (v) => { note.textContent = JSON.stringify(v); } });
document.getElementById('history').appendChild(history.element);
document.getElementById('history').appendChild(note);
const report = base.createDateRangePicker({ value: { from: '2026-03-20', to: '2026-03-01' }, presets: [] });
document.getElementById('report').appendChild(report.element);
report.isValid();
const day = (n) => { const d = new Date(); d.setDate(d.getDate() - n); return d.toISOString(); };
const list = base.createFilteredList({
items: [0, 2, 5, 12, 40].map((n, i) => ({ id: i, name: 'Synced ' + n + ' days ago', at: day(n) })),
render: (item) => item.name,
filters: [{ name: 'at', label: 'Synced', kind: 'daterange' }]
});
document.getElementById('list').appendChild(list.element);
</script>