beUI Pro

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

インストール

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

API リファレンス

必須と記された props 以外はすべて省略できます。データ、文言、色はサンプルの内容が既定値です。

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

    既定値 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
  • from必須

    Value in the comparison range.

    number
  • to必須

    Value in the selected range.

    number
  • className

    Extra classes for the pill.

    string
CompareControl9 個の props
  • compare必須

    Whether comparison is on.

    boolean
  • compareMode必須

    What the range is compared against.

    "previous-period" | "previous-year"
  • range必須

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

    CompareDateRange
  • locale必須

    BCP 47 locale for the comparison ranges.

    string
  • currentYear

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

    string
  • labels必須

    Copy for the switch, menu and range text.

    Pick<DateRangeCompareLabels, "compare" | "compareMode" | "previousPeriod" | "previousYear" | "versus">
  • onCompareChange必須

    Called when the switch flips.

    (compare: boolean) => void
  • onCompareModeChange必須

    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

    既定値 2026-11-28

  • min

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

    string
  • locale

    BCP 47 locale for dates.

    string

    既定値 en-US

  • labels

    Copy overrides; anything left out uses the English defaults.

    Partial<DateRangeCompareLabels>
  • className

    Extra classes for the bar.

    string
KpiCard7 個の props
  • kpi必須

    The KPI's label, format and colors.

    KpiDefinition
  • snapshot必須

    Values and trends for the selected and comparison ranges.

    KpiSnapshot
  • compare必須

    Whether the change pill and comparison line show.

    boolean
  • drawKey必須

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

    string
  • formatters必須

    Formatter for each KPI format.

    KpiFormatters
  • index必須

    Position in the row, for the mount stagger.

    number
  • className

    Extra 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.

    boolean
  • drawKey必須

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

    string
  • strokeClassName必須

    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
  • range必須

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

    CompareDateRange
  • max必須

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

    string
  • min

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

    string
  • locale必須

    BCP 47 locale for dates.

    string
  • labels必須

    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) => void
  • className

    Extra classes for the trigger.

    string
useDateRangeValue3 個の props
  • value

    Controlled value.

    DateRangeCompareValue
  • defaultValue必須

    Starting value when uncontrolled.

    DateRangeCompareValue
  • onChange

    Called 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`.

    string
  • label必須

    Tab label, such as "30d".

    string
  • days必須

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

    number
DateRangeCompareValue4 個のフィールド
  • preset必須

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

    string
  • range必須

    Selected range.

    CompareDateRange
  • compare必須

    Whether the comparison range is shown.

    boolean
  • compareMode必須

    What the selected range is compared against.

    CompareMode
KpiDefinition8 個のフィールド
  • id必須

    Stable id.

    string
  • label必須

    Card label, such as "Visitors".

    string
  • format必須

    Which formatter shows the value.

    KpiFormat
  • aggregate必須

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

    "sum" | "average"
  • base必須

    Typical value for one day.

    number
  • trend必須

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

    number
  • noise必須

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

    number
  • strokeClassName必須

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

    string
DateRangeCompareLabels13 個のフィールド
  • presets必須

    Accessible name of the preset tabs.

    string
  • custom必須

    Tab label for a range picked in the calendar.

    string
  • calendar必須

    Accessible name of the calendar.

    string
  • compare必須

    Label beside the compare switch.

    string
  • previousPeriod必須

    Option label for the previous period.

    string
  • previousYear必須

    Option label for the same dates a year earlier.

    string
  • compareMode必須

    Accessible name of the comparison mode menu.

    string
  • versus必須

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

    string
  • day必須

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

    string
  • days必須

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

    string
  • previousMonth必須

    Previous month button.

    string
  • nextMonth必須

    Next month button.

    string
  • kpis必須

    Accessible name of the KPI row.

    string
CompareDateRange2 個のフィールド
  • from必須

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

    string
  • to必須

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

    string
KpiSnapshot5 個のフィールド
  • id必須

    The KPI it belongs to.

    string
  • value必須

    Value for the selected range.

    number
  • previous必須

    Value for the comparison range.

    number
  • series必須

    Bucketed trend for the selected range, oldest first.

    number[]
  • previousSeries必須

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

    number[]