Tally UI
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

PropTypeDefaultDescription
mode'single' | 'range'RequiredSelects the value and callback types below
valueStoreDay | null (single) or DayRange | null (range)RequiredCurrent selection; null means no selection
onChange(day: StoreDay) => void (single) or (range: DayRange) => void (range)RequiredReceives the selection after each enabled day press
todayStoreDayRequiredDay to mark as today, supplied in the store's time zone
minStoreDay—Earliest selectable day; disables navigation before its month
maxStoreDay—Latest selectable day; disables navigation after its month
weekStartsOn0 | 1 | 2 | 3 | 4 | 5 | 61First weekday, from Sunday (0) to Saturday (6)
initialMonthstringSelection's start month, otherwise today's monthMonth shown on mount, formatted yyyy-MM
localestring'en-GB'BCP 47 tag for month, weekday and accessible day labels
testIDstring'calendar'Identifies the grid; the parts are <testID>-prev, -next, -title and -weekdays, and each day is <testID>-day-yyyy-MM-dd
classNamestring—Additional classes for the outer view

Selection modes

ModeWhat a press reports
singleThe pressed day as a StoreDay.
rangeThe 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.