Blocks / Date range compare

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";
/01 → Default

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
PropTypeDefaultDescription
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 }.
compareOptionsDashboardCompare[]all fourWhat can be compared with.
labelstring"Period"Names the picker.
today / presets / min / maxas DateRangePicker—Passed through.
classNamestring—Extra classes.