Skip to content
buttery

v1.0.0

Source on GitHub

Version 1.0.0

DateRangeBar

The period a report covers: a range with presets or two dates, the interval its charts group by, and what it's compared with.

import { DateRangeBar } from "@butteryui/react";

Demo

When to use it

Use it for

  • Above an overview's metric cards and charts, to set the period they all show
  • A report page that fetches its data for a range and a comparison

Not for

  • Picking one date in a form: use a TextField with type="date"
  • Filtering a table by date: use a FilterPill

Examples

Default period

With no props it keeps its own value, starting on the last 7 days, daily, against the previous period.

Overview metrics

An overview's period over its metric cards: a new range changes their numbers, and No comparison drops the change.

Revenue

$3,180.00

+12.4%

vs previous period

Orders

71

+6.1%

vs previous period

Overview period

The period an overview shows, kept in state and turned into the query that fetches its numbers.

Fetching /api/overview?range=last-4-weeks&interval=weekly&compare=previous-period

Spanish labels

The bar in Spanish, with its own words for every part.

Variants and states

Presets, an interval and a comparison

Open the range for presets or two dates of your own; under 640px of room the comparison moves to its own row.

A custom range

Props

DateRangeBar

PropTypeDefaultDescription
valueDateRangeValueWhat it's set to, when you control it.
defaultValueDateRangeValueWhat it starts at. Defaults to the last 7 days, daily, against the previous period.
onValueChange((value: DateRangeValue) => void)Called with everything it's set to whenever one part changes.
labelstring"Period"Names the group. Defaults to "Period".
labelsPartial<DateRangeBarLabels>Its words, for another language or your own names.
formatRange((range: CustomDateRange) => string)Writes a custom range on the range select. Defaults to the short month and days, such as "Oct 1 – 14".

It also takes Omit<ComponentPropsWithRef<"div">, "defaultValue">.

DateRangeValue

Everything a `DateRangeBar` is set to, for fetching a report's data.

FieldTypeDefaultDescription
range

required

"today" | "last-7-days" | "last-4-weeks" | "last-3-months" | "last-12-months" | "month-to-date" | "year-to-date" | "custom"The range: a preset ending today, or "custom".
customCustomDateRangeThe dates of a "custom" range.
interval

required

"daily" | "weekly" | "monthly"How the charts group their points.
comparison

required

"previous-period" | "previous-year" | "none"What the period is compared with.

DateRangeBarLabels

The words a `DateRangeBar` shows and announces.

FieldTypeDefaultDescription
range

required

stringNames the range select.
interval

required

stringNames the interval select.
comparison

required

stringNames the comparison select.
comparedTo

required

stringThe caption before the comparison select.
customRange

required

stringNames the custom range fields under the range list.
start

required

stringLabels the first date field.
end

required

stringLabels the last date field.
presets

required

Readonly<Record<DateRangePreset, string>>Each range's name in the list.
intervals

required

Readonly<Record<DateInterval, string>>Each interval's name in the list.
comparisons

required

Readonly<Record<DateComparison, string>>Each comparison's name in the list.

CustomDateRange

Two dates as ISO strings, such as `"2026-10-01"`, the end on or after the start.

FieldTypeDefaultDescription
start

required

stringThe first day, as YYYY-MM-DD.
end

required

stringThe last day, as YYYY-MM-DD.

Accessibility

A group named Period holding three selects, each named by what it sets and its current choice. The range list ends with two date fields for a custom range, which Tab reaches from the list. The "compared to" caption is hidden from screen readers, since the comparison select says it.

KeysWhat they do
Enter, Space, ArrowDown or ArrowUpOpens the focused select's list, with focus on its choice
ArrowDown, ArrowUp, Home or EndMoves through the list's options
A letterMoves to the option that starts with it
Enter or SpaceChooses the option and closes the list, focus back on the select
TabMoves from the range's list to its two date fields and back
EscapeCloses the list and puts focus back on the select

Motion

It doesn't move.

With reduced motion: Nothing changes.

Layout

It fills the width it's given, asking for 640px in a row: three 28px outline selects (--bt-h-sm) 8 apart, the comparison after its caption. Under 640px of its own width the range and the interval share a row in equal halves over the comparison.

See it in the roastery demo's overview.