UI
Calendar
Calendar displays a month grid for selecting a single store day or an inclusive date range.
Import
import { Calendar } from '@tallyui/components';Usage
import { useState } from 'react';
import type { DayRange, StoreDay } from '@tallyui/pos';
function ReportDates({ today }: { today: StoreDay }) {
const [range, setRange] = useState<DayRange | null>(null);
return <Calendar mode="range" today={today} max={today} value={range} onChange={setRange} />;
}StoreDay is a yyyy-MM-dd string, not a JavaScript Date. A DayRange has two store days: from and to. Pass the selection reported by onChange back as value to show it in the grid. The month shown is set once, on mount: a later change to value does not move it.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
mode | 'single' | 'range' | Required | Selects the value and callback types below |
value | StoreDay | null (single) or DayRange | null (range) | Required | Current selection; null means no selection |
onChange | (day: StoreDay) => void (single) or (range: DayRange) => void (range) | Required | Receives the selection after each enabled day press |
today | StoreDay | Required | Day to mark as today, supplied in the store's time zone |
min | StoreDay | — | Earliest selectable day; disables navigation before its month |
max | StoreDay | — | Latest selectable day; disables navigation after its month |
weekStartsOn | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 1 | First weekday, from Sunday (0) to Saturday (6) |
initialMonth | string | Selection's start month, otherwise today's month | Month shown on mount, formatted yyyy-MM |
locale | string | 'en-GB' | BCP 47 tag for month, weekday and accessible day labels |
testID | string | 'calendar' | Identifies the grid; the parts are <testID>-prev, -next, -title and -weekdays, and each day is <testID>-day-yyyy-MM-dd |
className | string | — | Additional classes for the outer view |
Selection modes
| Mode | What a press reports |
|---|---|
single | The pressed day as a StoreDay. |
range | The first press reports a one-day range. The second reports both endpoints, earlier day first, even if the user picks backwards. The next press starts a new range. |