Event calendar

A full calendar of events by day, week, month or year.

import { EventCalendar } 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

EventCalendar props

PropTypeWhat it does
events`CalendarEvent[] \undefined`
value`Date \null \undefined`The selected day.
defaultValue`Date \null \undefined`
onValueChange`((date: Date) => void) \undefined`
month`Date \undefined`Any day in the month on show.
defaultMonth`Date \undefined`
onMonthChange`((month: Date) => void) \undefined`
view`EventCalendarView \undefined`Day and Week show hours with timed events; Month shows days; Year shows months. Figma: View.
defaultView`EventCalendarView \undefined`
onViewChange`((view: EventCalendarView) => void) \undefined`
views`EventCalendarView[] \undefined`Which views the switch offers.
header`"full" \"simple" \undefined`Full: in the month view the title opens the twelve months (and its year opens the years); in the year view it opens the years. In the week and day views it is plain text and the arrows move it. The view switch shows. Simple: a plain title with the arrows. Figma: Header.
yearRange`[number, number] \undefined`Years people can jump to from the title. Defaults to ten years either side of today.
maxEvents`number \undefined`Event rows shown in a day before "+2 more".
startHour`number \undefined`The hour the day and week views scroll to first.
hourHeight`number \undefined`Height of one hour in the day and week views, in px.
weekStartsOn`0 \1 \undefined`0 for Sunday, 1 for Monday.
locale`string \undefined`For month, weekday and time formats. Defaults to the browser's language.
renderDay`((date: Date, events: CalendarEvent[]) => ReactNode) \undefined`Extra content inside a day of the month view, under its events, like a price or a status.
renderMonth`((month: Date, events: CalendarEvent[]) => ReactNode) \undefined`Extra content inside a month in the year view.
onEventClick`((event: CalendarEvent) => void) \undefined`
onSlotClick`((date: Date) => void) \undefined`Called with the time when people click an empty slot in the day or week view, rounded to 30 minutes. Use it to add an event there.
classNames`Partial<Record<EventCalendarPart, string>> \undefined`Extra class names for the parts inside the component, by part name, like { header: 'my-header' }.
styles`Partial<Record<EventCalendarPart, CSSProperties>> \undefined`Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }.

It also takes the usual HTML attributes for its element.

Examples

Overview

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

const today = new Date();
const on = (day: number, h = 9, m = 0) => new Date(today.getFullYear(), today.getMonth(), day, h, m);

const events = [
  { id: '1', title: 'Design review', start: on(6, 10), end: on(6, 11), color: 'blue' },
  { id: '2', title: 'Team offsite', start: on(13), end: on(15), color: 'purple' },
  { id: '3', title: 'Launch', start: on(20, 14), end: on(20, 15), color: 'green' },
  { id: '4', title: 'Payroll run', start: on(27), color: 'orange' },
];

export default function Example() {
  return (
    <div style={{ width: '100%' }}>
      <EventCalendar events={events} />
    </div>
  );
}

Week

Hours down the side and the week across. Overlapping events sit side by side.

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

const now = new Date();
const at = (dayOffset: number, h: number) => new Date(now.getFullYear(), now.getMonth(), now.getDate() + dayOffset, h);

const events = [
  { id: '1', title: 'Stand-up', start: at(0, 9), end: at(0, 10), color: 'blue' },
  { id: '2', title: 'Design review', start: at(0, 9), end: at(0, 11), color: 'purple' },
  { id: '3', title: 'Lunch with Ada', start: at(1, 12), end: at(1, 13), color: 'green' },
  { id: '4', title: 'Planning', start: at(-1, 14), end: at(-1, 16), color: 'orange' },
];

export default function Demo() {
  return (
    <div style={{ width: '100%' }}>
      <EventCalendar events={events} defaultView="week" />
    </div>
  );
}

Simple header

Just the title and arrows, with no view switch.

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

const now = new Date();
const on = (day: number) => new Date(now.getFullYear(), now.getMonth(), day, 10);

export default function Demo() {
  return (
    <div style={{ width: '100%' }}>
      <EventCalendar header="simple" events={[{ id: '1', title: 'Payroll run', start: on(25), color: 'green' }]} />
    </div>
  );
}

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