Period selector
A date range picker whose period, kept in the page URL, drives every widget that names its scope.
PeriodSelector is the date range control of a dashboard. Place one on the page; every chart, card, list and table bound to its id through periodScope reads its route again when the range or the comparison changes. It draws a preset dropdown (or inline pills), an optional custom range, a comparison control, and optionally the resolved range as text.
PeriodSelectorUsage
import { PeriodSelector } from "@antelopejs/interface-dms/base/period-selector";
static period = PeriodSelector({ id: "sales", defaultPreset: "last-30-days" });
static revenue = KpiCard({ title: "Revenue", fetchUrl: "/api/sales/revenue", periodScope: "sales" });
On each change, the selector adds preset, from / to and comparison to every scoped widget's request. A route reads them with @Period() from @antelopejs/interface-dms/period-request: Period filtering shows how.
Options
| Option | Type | Default | Description |
|---|---|---|---|
presetLabels Content | Record<string, string> | – | |
comparisonLabels Content | Record<string, string> | – | |
align Appearance | "left" | "center" | "right" | – | |
size Appearance | "xs" | "sm" | "md" | "lg" | "xl" | – | |
showRangeLabel Appearance | boolean | – | |
rangeLabel Appearance | "absolute" | "relative" | – | Relative says how long ago the period starts, rather than its dates. |
comparisonControl Appearance | "menu" | "toggle" | "hidden" | – | How the comparisons are offered. |
variant Appearance | "default" | "segmented" | – | Segmented shows the periods as buttons side by side. |
defaultPreset Behavior | "last-hour" | "last-24h" | "today" | "yesterday" | "last-7-days" | "last-30-days" | … | – | |
defaultComparison Behavior | "none" | "previous-period" | "previous-year" | "custom" | – | |
presets Behavior | "last-hour" | "last-24h" | "today" | "yesterday" | "last-7-days" | "last-30-days" | …[] | – | The periods people can pick from. |
comparisons Behavior | "none" | "previous-period" | "previous-year" | "custom"[] | – | |
maxDays Behavior | number | – | The longest custom range the user can pick, in days. |
PeriodPreset is one of last-hour, last-24h, today, yesterday, last-7-days, last-30-days, last-90-days, this-month, last-month, this-quarter, last-quarter, ytd, last-year, all, custom. PeriodComparison is none, previous-period, previous-year or custom.
The period lives in the URL
Every selector writes its period into the page URL, keyed by its id: ?sales.period=last-7-days&sales.compare=previous-period, or ?sales.from=2026-10-01&sales.to=2026-10-31 for a custom range. A link or a reload opens the same period, the server renders it, and the default never flashes. A change replaces the history entry, so Back leaves the page. Without a period in the URL, the selector starts from the user's last choice on that page, then from defaultPreset.
Recipes
Several scopes on one page
Give each selector a distinct id and point disjoint widget groups at each. Their URL keys never collide.
Pills for a metrics page
variant: "segmented" turns a short preset list into inline pills: one click per range instead of open-then-pick. Keep the list to a handful; the custom range stays in its popover calendar. Each pill reads its preset's short code in the reader's language: 1H, 24H, 1D (today), -1D (yesterday), 7D, 30D, 90D, MTD, -1M, QTD, -1Q, YTD, -1Y, ALL in English, 1 h, 24 h, Auj., Hier, 7 j, 30 j, 90 j, Mois, M-1, Trim., T-1, Année, A-1, Tout in French. A code is never a bare letter: "A" says nothing to a reader who has not been told it means the year. They are translated under dms.period.short_presets.<preset>, so an app adds a language's codes beside its preset names; presetLabels replaces one. Screen readers hear each pill's full name ("Last 24 hours"), not its code. In a page toolbar the custom pill is its calendar icon alone, the window beside it writing the chosen range.
In a PageToolbar the selector takes the toolbar's size unless it sets its own, and the window written beside it scales with it.
All time
Offer all in presets for an "All time" choice. The bound widgets receive preset=all and no from / to; the route reads it as no time filter.
A range of the user's own
Add custom to presets. The popover's start and end fields and its calendar then take a range at any time: picking two days, or typing a date in a field, selects the custom range, and picking a preset fills both fields with its window. The comparison follows the range on screen. A field takes a date as soon as it is complete, so a day typed on its way to another (2 before 20, the year 202 before 2026) never moves the other bound: a day before the other bound, or one that makes the range longer than maxDays, stays in its field until focus leaves it or the user applies, and only then moves the other bound.
A relative label
rangeLabel: "relative" writes a window that reaches now from its start, in the reader's locale: "since 11:52", "since yesterday 11:52", "since Mon 11:52".
One remembered period across a module
rememberKey: "api" on the selector of each page of a module makes them share the remembered choice, so the period follows the user from page to page.
A compact comparison
A menu's trigger names the window it compares with (vs 16 – 17 Oct ▾, days only, the option's name in its tooltip), and the range label then leaves its "vs …" part out, so the comparison is said once. A selector offering a single comparison draws one inline toggle instead of a menu. comparisonControl: "toggle" asks for it among several, and comparisonControl: "hidden" draws nothing and keeps the comparison on.
Cap a custom range
maxDays: 31 keeps a custom range to 31 days, both ends included. Presets and a range put in the URL by a link are not limited, so the route still enforces its own limit.
Pitfalls
- A widget only follows a selector whose
idequals itsperiodScope. The defaultidispage. - Without
custominpresets, the popover still shows the start and end of the selected preset and its calendar, but they are read-only: the user picks presets only. presetLabelsandcomparisonLabelsrelabel the menus; use$keys so they translate.
