Date Range Compare

1 variant

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>
  );
}

Install

$ bunx --bun shadcn add @beui-pro/date-range-compare-kpis

API Reference

Every prop is optional unless marked required. Data, copy, and colors default to the sample content.

DateRangeCompare12 props
  • kpis

    KPI cards in display order; four fit the row.

    KpiDefinition[]
  • getKpiData

    Computes each KPI for a range and its comparison range. Defaults to deterministic sample data.

    KpiDataFunction
  • formatters

    Formatters for each KPI format; any left out keep their defaults (USD for currency).

    Partial<KpiFormatters>
  • value

    Controlled value: preset, range, compare switch and compare mode.

    DateRangeCompareValue
  • defaultValue

    Starting value when uncontrolled. Defaults to the 30d preset with compare on.

    DateRangeCompareValue
  • onChange

    Called with the whole next value whenever any part changes.

    ((value: DateRangeCompareValue) => void)
  • presets

    Quick ranges shown as tabs, before the Custom tab.

    CompareRangePreset[]
  • today

    The day presets end on and the last selectable day, `YYYY-MM-DD`.

    string

    Default 2026-11-28

  • min

    Earliest selectable day, `YYYY-MM-DD`.

    string
  • locale

    BCP 47 locale for dates.

    string
  • labels

    Copy overrides; anything left out uses the English defaults.

    Partial<DateRangeCompareLabels>
  • className

    Extra classes for the bar.

    string
ChangePill3 props
  • fromRequired

    Value in the comparison range.

    number
  • toRequired

    Value in the selected range.

    number
  • className

    Extra classes for the pill.

    string
CompareControl9 props
  • compareRequired

    Whether comparison is on.

    boolean
  • compareModeRequired

    What the range is compared against.

    "previous-period" | "previous-year"
  • rangeRequired

    The selected range; each comparison option shows the range it would compare against.

    CompareDateRange
  • localeRequired

    BCP 47 locale for the comparison ranges.

    string
  • currentYear

    Year of "today" as `YYYY`; ranges in other years show their year.

    string
  • labelsRequired

    Copy for the switch, menu and range text.

    Pick<DateRangeCompareLabels, "compare" | "compareMode" | "previousPeriod" | "previousYear" | "versus">
  • onCompareChangeRequired

    Called when the switch flips.

    (compare: boolean) => void
  • onCompareModeChangeRequired

    Called when a comparison mode is chosen.

    (mode: CompareMode) => void
  • className

    Extra classes for the group.

    string
DateRangeBar9 props
  • value

    Controlled value: preset, range, compare switch and compare mode.

    DateRangeCompareValue
  • defaultValue

    Starting value when uncontrolled. Defaults to the 30d preset with compare on.

    DateRangeCompareValue
  • onChange

    Called with the whole next value whenever any part changes.

    ((value: DateRangeCompareValue) => void)
  • presets

    Quick ranges shown as tabs, before the Custom tab.

    CompareRangePreset[]
  • today

    The day presets end on and the last selectable day, `YYYY-MM-DD`.

    string

    Default 2026-11-28

  • min

    Earliest selectable day, `YYYY-MM-DD`.

    string
  • locale

    BCP 47 locale for dates.

    string

    Default en-US

  • labels

    Copy overrides; anything left out uses the English defaults.

    Partial<DateRangeCompareLabels>
  • className

    Extra classes for the bar.

    string
KpiCard7 props
  • kpiRequired

    The KPI's label, format and colors.

    KpiDefinition
  • snapshotRequired

    Values and trends for the selected and comparison ranges.

    KpiSnapshot
  • compareRequired

    Whether the change pill and comparison line show.

    boolean
  • drawKeyRequired

    Changes with the range, so the sparkline draws in again.

    string
  • formattersRequired

    Formatter for each KPI format.

    KpiFormatters
  • indexRequired

    Position in the row, for the mount stagger.

    number
  • className

    Extra classes for the card.

    string
KpiSparkline6 props
  • valuesRequired

    Selected range trend, oldest first.

    readonly number[]
  • previousValuesRequired

    Comparison range trend on the same x positions as `values`.

    readonly number[]
  • showPreviousRequired

    Whether to draw the dashed comparison line behind the trend.

    boolean
  • drawKeyRequired

    Changes whenever the range changes, so the line draws in again.

    string
  • strokeClassNameRequired

    Stroke class for the trend line, such as `stroke-sky-500`.

    string
  • className

    Extra classes for the svg; its size comes from here.

    string
RangeCalendar7 props
  • rangeRequired

    Applied range shown on the trigger and selected when the calendar opens.

    CompareDateRange
  • maxRequired

    Latest selectable day, usually today, `YYYY-MM-DD`.

    string
  • min

    Earliest selectable day, `YYYY-MM-DD`.

    string
  • localeRequired

    BCP 47 locale for dates.

    string
  • labelsRequired

    Copy for the calendar and its buttons.

    Pick<DateRangeCompareLabels, "calendar" | "previousMonth" | "nextMonth" | "day" | "days">
  • onRangeChangeRequired

    Called with a complete range picked in the calendar.

    (range: CompareDateRange) => void
  • className

    Extra classes for the trigger.

    string
useDateRangeValue3 props
  • value

    Controlled value.

    DateRangeCompareValue
  • defaultValueRequired

    Starting value when uncontrolled.

    DateRangeCompareValue
  • onChange

    Called 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
  • idRequired

    Stable id stored in the value, such as `30d`. Never `custom`.

    string
  • labelRequired

    Tab label, such as "30d".

    string
  • daysRequired

    Days covered, ending on `today`. 1 means today only.

    number
DateRangeCompareValue4 fields
  • presetRequired

    Selected preset id, or `custom` after picking dates in the calendar.

    string
  • rangeRequired

    Selected range.

    CompareDateRange
  • compareRequired

    Whether the comparison range is shown.

    boolean
  • compareModeRequired

    What the selected range is compared against.

    CompareMode
KpiDefinition8 fields
  • idRequired

    Stable id.

    string
  • labelRequired

    Card label, such as "Visitors".

    string
  • formatRequired

    Which formatter shows the value.

    KpiFormat
  • aggregateRequired

    `sum` adds the days up (visitors, revenue); `average` averages them (rates, durations).

    "sum" | "average"
  • baseRequired

    Typical value for one day.

    number
  • trendRequired

    Daily growth as a fraction, such as 0.002 for 0.2% a day.

    number
  • noiseRequired

    How far a day can drift from its trend line, as a fraction of it.

    number
  • strokeClassNameRequired

    Sparkline stroke class, such as `stroke-sky-500`.

    string
DateRangeCompareLabels13 fields
  • presetsRequired

    Accessible name of the preset tabs.

    string
  • customRequired

    Tab label for a range picked in the calendar.

    string
  • calendarRequired

    Accessible name of the calendar.

    string
  • compareRequired

    Label beside the compare switch.

    string
  • previousPeriodRequired

    Option label for the previous period.

    string
  • previousYearRequired

    Option label for the same dates a year earlier.

    string
  • compareModeRequired

    Accessible name of the comparison mode menu.

    string
  • versusRequired

    Prefix for the comparison range text, such as "vs".

    string
  • dayRequired

    Unit after a one-day count on the range trigger.

    string
  • daysRequired

    Unit after a count of several days on the range trigger.

    string
  • previousMonthRequired

    Previous month button.

    string
  • nextMonthRequired

    Next month button.

    string
  • kpisRequired

    Accessible name of the KPI row.

    string
CompareDateRange2 fields
  • fromRequired

    First day of the range, `YYYY-MM-DD`.

    string
  • toRequired

    Last day of the range, `YYYY-MM-DD`.

    string
KpiSnapshot5 fields
  • idRequired

    The KPI it belongs to.

    string
  • valueRequired

    Value for the selected range.

    number
  • previousRequired

    Value for the comparison range.

    number
  • seriesRequired

    Bucketed trend for the selected range, oldest first.

    number[]
  • previousSeriesRequired

    Bucketed trend for the comparison range, the same length as `series`.

    number[]