Date Range Compare
1 variantA 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>
);
}
Source code is locked
Get access to install premium components and view the full source.
Open dashboardInstall
API Reference
Every prop is optional unless marked required. Data, copy, and colors default to the sample content.
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`.
stringDefault
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
fromRequiredValue in the comparison range.
numbertoRequiredValue in the selected range.
numberclassNameExtra classes for the pill.
string
CompareControl9 props
compareRequiredWhether comparison is on.
booleancompareModeRequiredWhat the range is compared against.
"previous-period" | "previous-year"rangeRequiredThe selected range; each comparison option shows the range it would compare against.
CompareDateRangelocaleRequiredBCP 47 locale for the comparison ranges.
stringcurrentYearYear of "today" as `YYYY`; ranges in other years show their year.
stringlabelsRequiredCopy for the switch, menu and range text.
Pick<DateRangeCompareLabels, "compare" | "compareMode" | "previousPeriod" | "previousYear" | "versus">onCompareChangeRequiredCalled when the switch flips.
(compare: boolean) => voidonCompareModeChangeRequiredCalled 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`.
stringDefault
2026-11-28minEarliest selectable day, `YYYY-MM-DD`.
stringlocaleBCP 47 locale for dates.
stringDefault
en-USlabelsCopy overrides; anything left out uses the English defaults.
Partial<DateRangeCompareLabels>classNameExtra classes for the bar.
string
KpiCard7 props
kpiRequiredThe KPI's label, format and colors.
KpiDefinitionsnapshotRequiredValues and trends for the selected and comparison ranges.
KpiSnapshotcompareRequiredWhether the change pill and comparison line show.
booleandrawKeyRequiredChanges with the range, so the sparkline draws in again.
stringformattersRequiredFormatter for each KPI format.
KpiFormattersindexRequiredPosition in the row, for the mount stagger.
numberclassNameExtra classes for the card.
string
KpiSparkline6 props
valuesRequiredSelected range trend, oldest first.
readonly number[]previousValuesRequiredComparison range trend on the same x positions as `values`.
readonly number[]showPreviousRequiredWhether to draw the dashed comparison line behind the trend.
booleandrawKeyRequiredChanges whenever the range changes, so the line draws in again.
stringstrokeClassNameRequiredStroke class for the trend line, such as `stroke-sky-500`.
stringclassNameExtra classes for the svg; its size comes from here.
string
RangeCalendar7 props
rangeRequiredApplied range shown on the trigger and selected when the calendar opens.
CompareDateRangemaxRequiredLatest selectable day, usually today, `YYYY-MM-DD`.
stringminEarliest selectable day, `YYYY-MM-DD`.
stringlocaleRequiredBCP 47 locale for dates.
stringlabelsRequiredCopy for the calendar and its buttons.
Pick<DateRangeCompareLabels, "calendar" | "previousMonth" | "nextMonth" | "day" | "days">onRangeChangeRequiredCalled with a complete range picked in the calendar.
(range: CompareDateRange) => voidclassNameExtra classes for the trigger.
string
useDateRangeValue3 props
valueControlled value.
DateRangeCompareValuedefaultValueRequiredStarting value when uncontrolled.
DateRangeCompareValueonChangeCalled with the next value whenever any part of it changes.
((value: DateRangeCompareValue) => void)
Types6 types
The object types these props take, field by field.
CompareRangePreset3 fields
idRequiredStable id stored in the value, such as `30d`. Never `custom`.
stringlabelRequiredTab label, such as "30d".
stringdaysRequiredDays covered, ending on `today`. 1 means today only.
number
DateRangeCompareValue4 fields
presetRequiredSelected preset id, or `custom` after picking dates in the calendar.
stringrangeRequiredSelected range.
CompareDateRangecompareRequiredWhether the comparison range is shown.
booleancompareModeRequiredWhat the selected range is compared against.
CompareMode
KpiDefinition8 fields
idRequiredStable id.
stringlabelRequiredCard label, such as "Visitors".
stringformatRequiredWhich formatter shows the value.
KpiFormataggregateRequired`sum` adds the days up (visitors, revenue); `average` averages them (rates, durations).
"sum" | "average"baseRequiredTypical value for one day.
numbertrendRequiredDaily growth as a fraction, such as 0.002 for 0.2% a day.
numbernoiseRequiredHow far a day can drift from its trend line, as a fraction of it.
numberstrokeClassNameRequiredSparkline stroke class, such as `stroke-sky-500`.
string
DateRangeCompareLabels13 fields
presetsRequiredAccessible name of the preset tabs.
stringcustomRequiredTab label for a range picked in the calendar.
stringcalendarRequiredAccessible name of the calendar.
stringcompareRequiredLabel beside the compare switch.
stringpreviousPeriodRequiredOption label for the previous period.
stringpreviousYearRequiredOption label for the same dates a year earlier.
stringcompareModeRequiredAccessible name of the comparison mode menu.
stringversusRequiredPrefix for the comparison range text, such as "vs".
stringdayRequiredUnit after a one-day count on the range trigger.
stringdaysRequiredUnit after a count of several days on the range trigger.
stringpreviousMonthRequiredPrevious month button.
stringnextMonthRequiredNext month button.
stringkpisRequiredAccessible name of the KPI row.
string
CompareDateRange2 fields
fromRequiredFirst day of the range, `YYYY-MM-DD`.
stringtoRequiredLast day of the range, `YYYY-MM-DD`.
string
KpiSnapshot5 fields
idRequiredThe KPI it belongs to.
stringvalueRequiredValue for the selected range.
numberpreviousRequiredValue for the comparison range.
numberseriesRequiredBucketed trend for the selected range, oldest first.
number[]previousSeriesRequiredBucketed trend for the comparison range, the same length as `series`.
number[]