Date range compare
A period and what it is compared to: previous period, previous year, or a custom one.
import { DateRangeCompare, dashboardCompareRanges } from "@forgeron/ui";Nov 1 → Nov 30vs Oct 2 → Oct 31
{
"current": {
"from": "2026-11-01",
"to": "2026-11-30"
},
"previous": {
"from": "2026-10-02",
"to": "2026-10-31"
}
}import { DateRangeCompare, dashboardCompareRanges, type DashboardPeriod } from "@forgeron/ui";
import { useState } from "react";
export default function Default() {
const [period, setPeriod] = useState<DashboardPeriod>({
range: { from: "2026-11-01", to: "2026-11-30" },
compare: "previous-period",
});
const { current, previous } = dashboardCompareRanges(period);
return (
<div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
<DateRangeCompare today="2026-11-18" value={period} onChange={setPeriod} />
<pre style={{ margin: 0, font: "12px/18px var(--font-mono)", color: "var(--ink-muted)" }}>
{JSON.stringify({ current, previous }, null, 2)}
</pre>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
value / defaultValue | { range, compare, custom? } | — | compare: none, previous-period, previous-year or custom. dashboardCompareRanges(value) gives the two ranges. |
onChange | (value, ranges) => void | — | The period and { current, previous, days }. |
compareOptions | DashboardCompare[] | all four | What can be compared with. |
label | string | "Period" | Names the picker. |
today / presets / min / max | as DateRangePicker | — | Passed through. |
className | string | — | Extra classes. |