Date Range Picker

Pick a start and an end on two months, or a preset such as Last 7 days, with an optional comparison period.

Growth

Period
Signups2,116+2.5% vs the period before
Active teams2,098-0.5% vs the period before
Issues closed2,080-0.5% vs the period before

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/date-range-picker

Usage

import { DateRange } from "./ui/uicontext/components/dates/DateMath.ts"import { DateRangePicker } from "./ui/uicontext/components/DateRangePicker.ts"
const Message = UiSchema.TaggedEnum({ PickedPeriod: { value: DateRange, compare: Schema.Boolean } })export const Period = (h: Html.H<typeof Message.Type>, period: DateRange | null, compare: boolean, today: string) =>	DateRangePicker(h, {		props: { label: "Period", value: period, today, offerCompare: true, compare },		onEmit: { Picked: ({ value, compare: against }) => Message.PickedPeriod({ value, compare: against !== null }) },	})

API reference

Props

DateRangePicker props
NameTypeDescription
valuerequiredDateRange | nullThe period, both days included, or null for none
todayrequiredIsoDateToday in the reader's time zone, from the app: presets end here
localestringThe reader's locale, for dates, month names and the week's first day
labelrequiredstringThe visible label, which names the button and the popover
hideLabelboolean—
descriptionstring—
errorstring | nullThe app's message about the range
placeholderstringWhat the button says with no range
minIsoDate—
maxIsoDate—
unavailableUnavailableDates—
firstDayOfWeekInt—
presetsRangePresetId[]The presets offered, in order; all of them when left out, none with []
offerComparebooleanOffer "Compare with the previous period"
comparebooleanThe comparison is on
idstring—
disabledboolean—

Events

DateRangePicker events
EventPayloadDescription
Picked{ value: DateRange; preset: RangePresetId | null; compare: DateRange | null }A range was applied: store value, and pass compare !== null back as compare; preset is the preset it came from, and compare the period to compare with

Agent actions

What agents can do with DateRangePicker
ActionDescription
ChoseRangeApply a period: its first and last day as ISO days (see presets for the usual ones)

Source