# Calendar

Date selection, single-date popovers, and date-range popovers powered by DayPicker.

Use Calendar for an inline date grid, DatePicker for one date in a popover, and DateRangePicker for a start and end date. All three use the same selection values and calendar behavior.

<p className="zenos-recipe-source">
  Powered by <a href="https://daypicker.dev/">DayPicker</a> for date-grid behavior, keyboard
  navigation, and accessible labels. Zenos owns the public selection API, popup composition, and
  styling.
</p>

```bash
pnpm dlx @zentara-co/zenos-cli add calendar
npx @zentara-co/zenos-cli add calendar
yarn dlx @zentara-co/zenos-cli add calendar
bunx @zentara-co/zenos-cli add calendar
```

The command installs `@daypicker/react` and adds three consumer-owned files:

- `calendar.tsx` — inline calendar with single, multiple, and range selection.
- `date-picker.tsx` — shared picker state plus single-date Root, Trigger, and Content.
- `date-range-picker.tsx` — range state built on the same trigger and content parts.

Import these files through the path configured by your project:

```tsx
import { Calendar } from "./components/calendar";
import { DatePicker } from "./components/date-picker";
import { DateRangePicker } from "./components/date-range-picker";
```

## Calendar selection modes

Calendar supports `single`, `multiple`, and `range` modes. The mode narrows the value and callback types, so keep `value`, `defaultValue`, and `onValueChange` consistent with it.

### Single date

Use single selection for appointments, deadlines, and effective dates. Omitting `mode` also selects this behavior.

```tsx
import { useState } from "react";
import { Stack, Text } from "@zentara-co/zenos-ui";
import { Calendar } from "@docs/src/recipes/calendar/calendar";

function formatCalendarDate(date: Date | undefined) {
  return date?.toLocaleDateString(undefined, {
    day: "numeric",
    month: "short",
    year: "numeric",
  });
}

function CalendarSingleSelectionExample() {
  const [date, setDate] = useState<Date | undefined>(new Date(2026, 8, 15));

  return (
    <Stack gap="3" align="center">
      <Calendar
        mode="single"
        value={date}
        onValueChange={setDate}
        defaultMonth={new Date(2026, 8)}
        aria-label="Choose a review date"
      />
      <Text color="subtle" size="s">
        {date ? `Review on ${formatCalendarDate(date)}` : "No review date selected."}
      </Text>
    </Stack>
  );
}
```

### Multiple dates

Use multiple selection when dates are independent rather than a continuous interval, such as maintenance windows or attendance days.

```tsx
import { useState } from "react";
import { Stack, Text } from "@zentara-co/zenos-ui";
import { Calendar } from "@docs/src/recipes/calendar/calendar";

function CalendarMultipleSelectionExample() {
  const [dates, setDates] = useState<Date[] | undefined>([
    new Date(2026, 8, 8),
    new Date(2026, 8, 15),
  ]);

  return (
    <Stack gap="3" align="center">
      <Calendar
        mode="multiple"
        value={dates}
        onValueChange={setDates}
        defaultMonth={new Date(2026, 8)}
        aria-label="Choose maintenance dates"
      />
      <Text color="subtle" size="s">
        {dates?.length ? `${dates.length} maintenance dates selected.` : "No dates selected."}
      </Text>
    </Stack>
  );
}
```

### Date range

Range selection returns `{ from, to }`. During selection, `from` can exist before `to`; handle that partial state in labels and validation.

```tsx
import { useState } from "react";
import { Stack, Text } from "@zentara-co/zenos-ui";
import { Calendar, type DateRange } from "@docs/src/recipes/calendar/calendar";

function formatCalendarDate(date: Date | undefined) {
  return date?.toLocaleDateString(undefined, {
    day: "numeric",
    month: "short",
    year: "numeric",
  });
}

function formatCalendarRange(range: DateRange | undefined) {
  if (!range?.from) return undefined;
  const from = formatCalendarDate(range.from);
  const to = formatCalendarDate(range.to);
  return to ? `${from} – ${to}` : `From ${from}`;
}

function CalendarRangeSelectionExample() {
  const [range, setRange] = useState<DateRange | undefined>({
    from: new Date(2026, 8, 10),
    to: new Date(2026, 8, 16),
  });

  return (
    <Stack gap="3" align="center">
      <Calendar
        mode="range"
        value={range}
        onValueChange={setRange}
        defaultMonth={new Date(2026, 8)}
        aria-label="Choose a reporting period"
      />
      <Text color="subtle" size="s">
        {formatCalendarRange(range) ?? "No reporting period selected."}
      </Text>
    </Stack>
  );
}
```

## Availability and boundaries

Use `min` and `max` for inclusive selection boundaries. Add `disabled` for business rules inside that interval. It accepts one DayPicker matcher or an array of matchers, including dates, ranges, day-of-week objects, and predicate functions.

```tsx
import { useState } from "react";
import { Stack, Text } from "@zentara-co/zenos-ui";
import { Calendar } from "@docs/src/recipes/calendar/calendar";

function formatCalendarDate(date: Date | undefined) {
  return date?.toLocaleDateString(undefined, {
    day: "numeric",
    month: "short",
    year: "numeric",
  });
}

function CalendarConstraintsExample() {
  const today = new Date();
  const firstAvailableDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
  const lastAvailableDate = new Date(
    firstAvailableDate.getFullYear(),
    firstAvailableDate.getMonth(),
    firstAvailableDate.getDate() + 30,
  );
  const [date, setDate] = useState<Date>();

  return (
    <Stack gap="3" align="center">
      <Calendar
        value={date}
        onValueChange={setDate}
        defaultMonth={firstAvailableDate}
        min={firstAvailableDate}
        max={lastAvailableDate}
        disabled={(candidate) => candidate.getDay() === 0 || candidate.getDay() === 6}
        aria-label="Choose an onboarding date"
      />
      <Text color="subtle" size="s">
        {date
          ? `Onboarding starts ${formatCalendarDate(date)}.`
          : "Choose a weekday in the next 30 days."}
      </Text>
    </Stack>
  );
}
```

Keep unavailable dates visibly disabled instead of rejecting them only after submission. Put server-side availability behind a feature hook and pass the resolved matchers into Calendar.

## Controlled and uncontrolled state

Use `value` with `onValueChange` when the selection participates in form state, validation, or another component. Use `defaultValue` when Calendar can own the selection after initialization.

Visible-month state is separate from selected-value state. Control navigation with `month` and `onMonthChange`, or provide only `defaultMonth` for an uncontrolled initial month.

```tsx
const [month, setMonth] = useState(new Date(2026, 8));
const [date, setDate] = useState<Date>();

<Calendar value={date} onValueChange={setDate} month={month} onMonthChange={setMonth} />;
```

### Calendar API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| mode | 'single' \| 'multiple' \| 'range' | single | Selection model and value type. |
| value | Date \| Date[] \| DateRange \| undefined | — | Controlled selection for the active mode. |
| defaultValue | Date \| Date[] \| DateRange \| undefined | — | Initial selection when Calendar owns its state. |
| onValueChange | (value) => void | — | Runs when the selection changes; value follows mode. |
| disabled | Matcher \| Matcher[] | — | Dates unavailable for selection. |
| min / max | Date | — | Earliest and latest selectable dates, inclusive. |
| month / defaultMonth | Date | — | Controlled or initial visible month. |
| onMonthChange | (month: Date) => void | — | Runs after visible-month navigation. |
| numberOfMonths | number | 1 | Number of consecutive visible months. |
| locale / timeZone | Locale / string | — | DayPicker localization and IANA time zone configuration. |
| className / native div props | string / HTMLAttributes<HTMLDivElement> | — | Styles or labels the calendar wrapper. |

## DatePicker

```text
DatePicker.Root
├── DatePicker.Trigger
└── DatePicker.Content
    └── Calendar mode="single"
```

`DatePicker.Root` provides single-date state to its nested Calendar. Selecting a date closes an open picker and returns focus to the trigger. Use `open`, `defaultOpen`, and `onOpenChange` when popup visibility needs an external owner.

The trigger uses the same visual variants as Zenos Input and integrates with `Field.Root` for `id`, disabled, required, invalid, description, and error semantics.

```tsx
import { useState } from "react";
import { Stack, Text } from "@zentara-co/zenos-ui";
import { Calendar } from "@docs/src/recipes/calendar/calendar";
import { DatePicker } from "@docs/src/recipes/calendar/date-picker";

function CalendarDatePickerExample() {
  const [date, setDate] = useState<Date>();

  return (
    <Stack gap="3" align="center">
      <DatePicker.Root value={date} onValueChange={setDate}>
        <DatePicker.Trigger>
          {date ? date.toLocaleDateString() : "Schedule scan"}
        </DatePicker.Trigger>
        <DatePicker.Content>
          <Calendar mode="single" disabled={{ before: new Date() }} />
        </DatePicker.Content>
      </DatePicker.Root>
      <Text color="subtle" size="s">
        {date ? `Selected ${date.toLocaleDateString()}` : "Choose an available date."}
      </Text>
    </Stack>
  );
}
```

Use a controlled picker when another part of the screen needs the selected date. Calendar inherits the picker's value and callback when no local `value` or `defaultValue` is supplied.

```tsx
import { Field } from "@zentara-co/zenos-ui";

<Field.Root required>
  <Field.Label>Deployment date</Field.Label>
  <DatePicker.Root value={date} onValueChange={setDate}>
    <DatePicker.Trigger>
      {date ? date.toLocaleDateString() : "Choose deployment date"}
    </DatePicker.Trigger>
    <DatePicker.Content>
      <Calendar min={new Date()} />
    </DatePicker.Content>
  </DatePicker.Root>
  <Field.Description>Weekdays only.</Field.Description>
</Field.Root>;
```

## DateRangePicker

```text
DateRangePicker.Root
├── DateRangePicker.Trigger
└── DateRangePicker.Content
    └── Calendar mode="range"
```

The first selection keeps the popup open with a partial `{ from }` value. Selecting an end date completes the range, closes the popup, and returns focus to the trigger.

```tsx
import { useState } from "react";
import { Stack, Text } from "@zentara-co/zenos-ui";
import { Calendar, type DateRange } from "@docs/src/recipes/calendar/calendar";
import { DateRangePicker } from "@docs/src/recipes/calendar/date-range-picker";

function formatCalendarDate(date: Date | undefined) {
  return date?.toLocaleDateString(undefined, {
    day: "numeric",
    month: "short",
    year: "numeric",
  });
}

function formatCalendarRange(range: DateRange | undefined) {
  if (!range?.from) return undefined;
  const from = formatCalendarDate(range.from);
  const to = formatCalendarDate(range.to);
  return to ? `${from} – ${to}` : `From ${from}`;
}

function CalendarDateRangePickerExample() {
  const [range, setRange] = useState<DateRange>();

  return (
    <Stack gap="3" align="center">
      <DateRangePicker.Root value={range} onValueChange={setRange}>
        <DateRangePicker.Trigger>
          {formatCalendarRange(range) ?? "Choose reporting period"}
        </DateRangePicker.Trigger>
        <DateRangePicker.Content>
          <Calendar mode="range" numberOfMonths={2} />
        </DateRangePicker.Content>
      </DateRangePicker.Root>
      <Text color="subtle" size="s">
        The picker closes after both dates are selected.
      </Text>
    </Stack>
  );
}
```

Use two visible months when the expected ranges commonly cross a month boundary. For narrow layouts, keep one month or ensure the containing surface can accommodate the two-month grid.

### Single-month range picker

Use one visible month when the picker appears in a narrow surface or most ranges stay within the same month. Users can still navigate between months to select a range that crosses a month boundary.

```tsx
import { useState } from "react";
import { Stack, Text } from "@zentara-co/zenos-ui";
import { Calendar, type DateRange } from "@docs/src/recipes/calendar/calendar";
import { DateRangePicker } from "@docs/src/recipes/calendar/date-range-picker";

function formatCalendarDate(date: Date | undefined) {
  return date?.toLocaleDateString(undefined, {
    day: "numeric",
    month: "short",
    year: "numeric",
  });
}

function formatCalendarRange(range: DateRange | undefined) {
  if (!range?.from) return undefined;
  const from = formatCalendarDate(range.from);
  const to = formatCalendarDate(range.to);
  return to ? `${from} – ${to}` : `From ${from}`;
}

function CalendarSingleMonthDateRangePickerExample() {
  const [range, setRange] = useState<DateRange>();

  return (
    <Stack gap="3" align="center">
      <DateRangePicker.Root value={range} onValueChange={setRange}>
        <DateRangePicker.Trigger>
          {formatCalendarRange(range) ?? "Choose reservation dates"}
        </DateRangePicker.Trigger>
        <DateRangePicker.Content>
          <Calendar mode="range" defaultMonth={new Date(2026, 8)} />
        </DateRangePicker.Content>
      </DateRangePicker.Root>
      <Text color="subtle" size="s">
        A single calendar keeps the picker compact on narrow layouts.
      </Text>
    </Stack>
  );
}
```

### Picker Root API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| value / defaultValue | Date \| DateRange \| undefined | — | Controlled or initial picker selection; the exact type depends on the picker. |
| onValueChange | (value) => void | — | Runs when the nested Calendar changes selection. |
| open / defaultOpen | boolean | — | Controlled or initial popup visibility. |
| onOpenChange | (open: boolean) => void | — | Runs when popup visibility changes. |
| modal | boolean | false | Uses Base UI modal popover behavior when enabled. |

### Trigger and Content API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| Trigger.variant | InputVariant | default | Input-compatible trigger surface. |
| Trigger.render | ReactElement \| function | — | Composes the trigger with another button-like control. |
| Trigger.disabled | boolean | false | Prevents the picker from opening; Field disabled state is inherited. |
| Content.side / align | Base UI position values | bottom / start | Preferred popup placement relative to the trigger. |
| Content.sideOffset | number | 4 | Distance in pixels between trigger and popup. |
| className | string | — | Styling escape hatch on Trigger, Content, or Calendar. |

## Localization and time zones

Pass a DayPicker locale object and format the trigger label with the same locale. Use an IANA `timeZone` when the product's calendar day must not depend on the viewer's machine time zone.

```tsx
import { enGB } from "@daypicker/react/locale";

<Calendar locale={enGB} timeZone="Europe/London" />;
```

Keep the stored domain value and display formatting deliberate. A JavaScript `Date` is an instant, while many product concepts—birthdays, billing days, booking dates—represent a calendar date without a time.

## Accessibility

DayPicker supplies grid semantics, accessible day labels, and arrow-key navigation. Keep these behaviors intact:

- Give standalone calendars an `aria-label` when the surrounding heading does not identify their purpose.
- Use the trigger text to communicate the current value; do not rely on placeholder color alone.
- Leave disabled dates focus-safe and visibly distinct.
- Announce validation through `Field.Error` and `aria-invalid` rather than changing color only.
- Preserve Escape-to-close and focus return for both picker variants.

Source: https://zenos-ui.pages.dev/recipes/calendar/