Date Range Compare
1 バリエーションA dashboard date-range bar with presets, a range calendar, and a compare switch that drives a row of KPI cards.
Range and KPIs
Preset tabs, a two-month range calendar, and a compare switch drive a row of KPI cards. Values roll, change pills pop in when compare is on, and each sparkline redraws with a dashed previous-period line.
Visitors
129,483up1%Revenue
$144,673down1%Conversion
4.20%down2%Avg session
1m 56sdown2%
"use client";
import { DateRangeCompare } from "@/components/premium/date-range-compare";
export function DateRangeCompareKpisPreview() {
return (
<div className="w-full px-4 py-10">
<DateRangeCompare />
</div>
);
}
インストール
API リファレンス
必須と記された props 以外はすべて省略できます。データ、文言、色はサンプルの内容が既定値です。
DateRangeCompare12 個の props
kpisKPI cards in display order; four fit the row.
KpiDefinition[]getKpiDataComputes each KPI for a range and its comparison range. Defaults to deterministic sample data.
KpiDataFunctionformattersFormatters for each KPI format; any left out keep their defaults (USD for currency).
Partial<KpiFormatters>valueControlled value: preset, range, compare switch and compare mode.
DateRangeCompareValuedefaultValueStarting value when uncontrolled. Defaults to the 30d preset with compare on.
DateRangeCompareValueonChangeCalled with the whole next value whenever any part changes.
((value: DateRangeCompareValue) => void)presetsQuick ranges shown as tabs, before the Custom tab.
CompareRangePreset[]todayThe day presets end on and the last selectable day, `YYYY-MM-DD`.
string既定値
2026-11-28minEarliest selectable day, `YYYY-MM-DD`.
stringlocaleBCP 47 locale for dates.
stringlabelsCopy overrides; anything left out uses the English defaults.
Partial<DateRangeCompareLabels>classNameExtra classes for the bar.
string
ChangePill3 個の props
from必須Value in the comparison range.
numberto必須Value in the selected range.
numberclassNameExtra classes for the pill.
string
CompareControl9 個の props
compare必須Whether comparison is on.
booleancompareMode必須What the range is compared against.
"previous-period" | "previous-year"range必須The selected range; each comparison option shows the range it would compare against.
CompareDateRangelocale必須BCP 47 locale for the comparison ranges.
stringcurrentYearYear of "today" as `YYYY`; ranges in other years show their year.
stringlabels必須Copy for the switch, menu and range text.
Pick<DateRangeCompareLabels, "compare" | "compareMode" | "previousPeriod" | "previousYear" | "versus">onCompareChange必須Called when the switch flips.
(compare: boolean) => voidonCompareModeChange必須Called when a comparison mode is chosen.
(mode: CompareMode) => voidclassNameExtra classes for the group.
string
DateRangeBar9 個の props
valueControlled value: preset, range, compare switch and compare mode.
DateRangeCompareValuedefaultValueStarting value when uncontrolled. Defaults to the 30d preset with compare on.
DateRangeCompareValueonChangeCalled with the whole next value whenever any part changes.
((value: DateRangeCompareValue) => void)presetsQuick ranges shown as tabs, before the Custom tab.
CompareRangePreset[]todayThe day presets end on and the last selectable day, `YYYY-MM-DD`.
string既定値
2026-11-28minEarliest selectable day, `YYYY-MM-DD`.
stringlocaleBCP 47 locale for dates.
string既定値
en-USlabelsCopy overrides; anything left out uses the English defaults.
Partial<DateRangeCompareLabels>classNameExtra classes for the bar.
string
KpiCard7 個の props
kpi必須The KPI's label, format and colors.
KpiDefinitionsnapshot必須Values and trends for the selected and comparison ranges.
KpiSnapshotcompare必須Whether the change pill and comparison line show.
booleandrawKey必須Changes with the range, so the sparkline draws in again.
stringformatters必須Formatter for each KPI format.
KpiFormattersindex必須Position in the row, for the mount stagger.
numberclassNameExtra classes for the card.
string
KpiSparkline6 個の props
values必須Selected range trend, oldest first.
readonly number[]previousValues必須Comparison range trend on the same x positions as `values`.
readonly number[]showPrevious必須Whether to draw the dashed comparison line behind the trend.
booleandrawKey必須Changes whenever the range changes, so the line draws in again.
stringstrokeClassName必須Stroke class for the trend line, such as `stroke-sky-500`.
stringclassNameExtra classes for the svg; its size comes from here.
string
RangeCalendar7 個の props
range必須Applied range shown on the trigger and selected when the calendar opens.
CompareDateRangemax必須Latest selectable day, usually today, `YYYY-MM-DD`.
stringminEarliest selectable day, `YYYY-MM-DD`.
stringlocale必須BCP 47 locale for dates.
stringlabels必須Copy for the calendar and its buttons.
Pick<DateRangeCompareLabels, "calendar" | "previousMonth" | "nextMonth" | "day" | "days">onRangeChange必須Called with a complete range picked in the calendar.
(range: CompareDateRange) => voidclassNameExtra classes for the trigger.
string
useDateRangeValue3 個の props
valueControlled value.
DateRangeCompareValuedefaultValue必須Starting value when uncontrolled.
DateRangeCompareValueonChangeCalled with the next value whenever any part of it changes.
((value: DateRangeCompareValue) => void)
型6 個の型
これらの props が受け取るオブジェクト型とそのフィールド。
CompareRangePreset3 個のフィールド
id必須Stable id stored in the value, such as `30d`. Never `custom`.
stringlabel必須Tab label, such as "30d".
stringdays必須Days covered, ending on `today`. 1 means today only.
number
DateRangeCompareValue4 個のフィールド
preset必須Selected preset id, or `custom` after picking dates in the calendar.
stringrange必須Selected range.
CompareDateRangecompare必須Whether the comparison range is shown.
booleancompareMode必須What the selected range is compared against.
CompareMode
KpiDefinition8 個のフィールド
id必須Stable id.
stringlabel必須Card label, such as "Visitors".
stringformat必須Which formatter shows the value.
KpiFormataggregate必須`sum` adds the days up (visitors, revenue); `average` averages them (rates, durations).
"sum" | "average"base必須Typical value for one day.
numbertrend必須Daily growth as a fraction, such as 0.002 for 0.2% a day.
numbernoise必須How far a day can drift from its trend line, as a fraction of it.
numberstrokeClassName必須Sparkline stroke class, such as `stroke-sky-500`.
string
DateRangeCompareLabels13 個のフィールド
presets必須Accessible name of the preset tabs.
stringcustom必須Tab label for a range picked in the calendar.
stringcalendar必須Accessible name of the calendar.
stringcompare必須Label beside the compare switch.
stringpreviousPeriod必須Option label for the previous period.
stringpreviousYear必須Option label for the same dates a year earlier.
stringcompareMode必須Accessible name of the comparison mode menu.
stringversus必須Prefix for the comparison range text, such as "vs".
stringday必須Unit after a one-day count on the range trigger.
stringdays必須Unit after a count of several days on the range trigger.
stringpreviousMonth必須Previous month button.
stringnextMonth必須Next month button.
stringkpis必須Accessible name of the KPI row.
string
CompareDateRange2 個のフィールド
from必須First day of the range, `YYYY-MM-DD`.
stringto必須Last day of the range, `YYYY-MM-DD`.
string
KpiSnapshot5 個のフィールド
id必須The KPI it belongs to.
stringvalue必須Value for the selected range.
numberprevious必須Value for the comparison range.
numberseries必須Bucketed trend for the selected range, oldest first.
number[]previousSeries必須Bucketed trend for the comparison range, the same length as `series`.
number[]