Calendar

Month grids for picking dates, and a full calendar for plans.

import { Calendar } from '@halo-ds/react';

When to use it

Calendar is the small month grid for picking one day, a range or several days. It sits inside the Date pickers or on its own, with arrows or month and year menus. Event calendar fills a page to show plans by day, week, month or year, with events in the days. Both live here; the boxes that open a Calendar are on the Date picker page.

Do

  • Start on today, or on the month people last looked at.
  • Use a few colours, each with one meaning, and say what they mean.
  • Open the event, or a short list of the day, when people pick it.
  • Use Menus when people jump far ahead or back, like bookings or history.

Don't

  • Use colour as the only way to tell events apart; the title says what it is.
  • Squeeze more than three events into a day; let "+2 more" list the rest.
  • Use it to pick a single date in a form; use a Date picker.
  • Show both a month and a year menu on very small screens without testing them.

Event calendar or Calendar?

Calendar is for picking a date. Event calendar is for seeing and planning what happens on each date.

  • Calendar: Picks a day or a range, in a date picker or on its own. Small, with month and year menus for dates far away.
  • Event calendar: Fills a page. Shows events on each day, opens a day or an event, and switches between month and year.

Props

Calendar props

PropTypeWhat it does
mode`"single" \undefined`
value (required)`Date \null`
onChange (required)(date: Date) => void
presetsundefined
min`Date \undefined`Earliest day that can be picked.
max`Date \undefined`Latest day that can be picked.
isDateDisabled`((date: Date) => boolean) \undefined`Return true for days that can't be picked, like weekends.
weekStartsOn`0 \1 \undefined`0 for Sunday, 1 for Monday.
locale`string \undefined`For month and weekday names. Defaults to the browser's language.
defaultMonth`Date \undefined`Month shown first. Defaults to the selected day or today.
months`2 \1 \undefined`How many months show side by side.
footerReactNodeSomething under the months, like Cancel and Apply buttons.
header`"picker" \"arrows" \undefined`Picker (the default): the month name can be clicked to swap the days for months and years, to jump straight to a date far away, like a birthday. Arrows: the month name is plain text, so the arrows are the only way to move. Two months side by side always use arrows. Figma: Header.
yearRange`[number, number] \undefined`Years people can jump to with the picker. Defaults to the min and max years, or 100 years back and 10 ahead.
classNames`Partial<Record<CalendarPart, string>> \undefined`Extra class names for the parts inside the component, by part name, like { header: 'my-header' }.
styles`Partial<Record<CalendarPart, CSSProperties>> \undefined`Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }.
maxCount`number \undefined`The most days people can pick. Other days stop responding once it is reached.

It also takes the usual HTML attributes for its element.

Examples

Overview

import { useState } from 'react';
import { Calendar } from '@halo-ds/react';
import type { DateRange } from '@halo-ds/react';

export default function Example() {
  const [range, setRange] = useState<DateRange | null>(null);
  return <Calendar mode="range" value={range} onChange={setRange} />;
}

Single day

Click the month name to jump to another month, or the year to jump to another year.

import { useState } from 'react';
import { Calendar } from '@halo-ds/react';

export default function Demo() {
  const [date, setDate] = useState<Date | null>(new Date());
  return <Calendar value={date} onChange={setDate} style={{ width: 320 }} />;
}

Several days

Each click adds or removes a day.

import { useState } from 'react';
import { Calendar } from '@halo-ds/react';

export default function Demo() {
  const [dates, setDates] = useState<Date[]>([]);
  return <Calendar mode="multiple" value={dates} onChange={setDates} style={{ width: 320 }} />;
}

More: https://halodesignsystem.dev/components/calendar