RegistryInstall CalendarCN with the shadcn CLI

Components

Calendar Header

The live demo's header, with the month and week, the view switcher, today, previous and next, and the panel toggles.

CalendarHeader is the bar at the top of the live demo: a sidebar toggle, the month and year with the period on screen ("Week 23" while week numbers are on), then the view switcher, today, previous and next, and a context panel toggle. It reads the calendar from useCalendar(), so it goes inside CalendarProvider. The panels belong to your app, so their state comes in as props, and each toggle shows only when you pass its callback.

Installation

pnpm dlx shadcn add @calendarcn/calendar-header

Usage

import { CalendarHeader } from "@/components/calendar-header";
import { CalendarProvider } from "@/components/calendar-provider";
import { WeekView } from "@/components/week-view";

export function Schedule() {
  return (
    <CalendarProvider defaultEvents={events}>
      <div className="flex h-[600px] flex-col">
        <CalendarHeader />
        <div className="min-h-0 flex-1">
          <WeekView />
        </div>
      </div>
    </CalendarProvider>
  );
}

On its own it shows the title, the view switcher, today, previous and next. The view switcher sets the provider's view, so render the view the provider is on below it, as the preview does: TimeGrid for day and week, MonthView, YearView and AgendaView.

Panels

Pass a panel's state and toggle to get its button, with a tooltip that shows the panel's shortcut:

const [sidebarOpen, setSidebarOpen] = React.useState(true);
const [contextPanelOpen, setContextPanelOpen] = React.useState(false);

<CalendarHeader
  sidebarOpen={sidebarOpen}
  onToggleSidebar={() => setSidebarOpen((open) => !open)}
  contextPanelOpen={contextPanelOpen}
  onToggleContextPanel={() => setContextPanelOpen((open) => !open)}
>
  <Avatar className="size-7">
    <AvatarImage src={user.image} alt={user.name} />
    <AvatarFallback>{user.initials}</AvatarFallback>
  </Avatar>
</CalendarHeader>;
  • The sidebar toggle sits before the title. Its tooltip reads "Open sidebar" or "Close sidebar", by sidebarOpen.
  • The context panel toggle sits at the end, and hides while the panel is open, as in Notion Calendar: close the panel from the panel itself.
  • Children show before the view switcher, on wide headers only. The demo puts the signed-in user's avatar there.

Keyboard shortcuts

The tooltips advertise ⌘/ for the sidebar and / for the context panel. Turn those keys on, with the calendar's own, by passing the same toggles to useCalendarShortcuts() inside the provider:

import { useCalendarShortcuts } from "@/hooks/use-calendar-shortcuts";

useCalendarShortcuts({
  onToggleSidebar: toggleSidebar,
  onToggleContextPanel: toggleContextPanel,
});

Narrow screens

The header is a container (@container/header), so it follows its own width rather than the screen's:

Header widthShows
Under 20remThe short month ("Sep"), today, previous and next
20remThe view switcher
28remThe full month name, and a divider after the sidebar toggle
36remThe period on screen, the children, and a larger title

Build your own

The header is made of parts you can use in a header of your own. Each reads useCalendar(). The Calendar block's toolbar is built from them too.

import {
  CalendarNavigation,
  CalendarPeriodLabel,
  CalendarViewSwitcher,
} from "@/components/calendar-header";

function Toolbar() {
  const { monthName, year } = useCalendar();

  return (
    <header className="@container/header flex h-12 items-center gap-2 border-b px-3">
      <h2 className="min-w-0 flex-1 truncate font-semibold">
        {monthName} {year}
        <CalendarPeriodLabel className="ml-2 text-xs font-normal text-muted-foreground" />
      </h2>
      <CalendarViewSwitcher />
      <CalendarNavigation buttonClassName="size-8" />
    </header>
  );
}

API Reference

CalendarHeader

PropTypeDefault
sidebarOpen
Whether the sidebar is open. Its toggle's tooltip reads "Close sidebar" when it is, "Open sidebar" otherwise.
booleanfalse
onToggleSidebar
Opens or closes the sidebar. The sidebar toggle shows only when this is set.
() => void–
contextPanelOpen
Whether the context panel is open. Its toggle hides while it is.
booleanfalse
onToggleContextPanel
Opens or closes the context panel. The toggle shows only when this is set.
() => void–
children
Shown before the view switcher on headers 36rem and wider, e.g. the signed-in user's avatar.
React.ReactNode–
className
Classes for the <header> element.
string–

CalendarNavigation

Today, then previous and next. The arrows are labelled with the period they move by: a day, a week, a month, a year or the agenda's 30 days.

PropType
buttonClassName
Classes for the previous and next buttons, e.g. their size.
string

CalendarPeriodLabel

The period on screen: the day in day view ("Thursday, Jun 4") and the dates in the agenda ("Jun 4 – Jul 3"). While the provider's week numbers are on (viewSettings.showWeekNumbers), day and week view add the week's number ("Week 23"), where Notion Calendar shows it. It's empty in month and year view, where the title says it all. In year view the title shows the year alone. Day and month names follow the provider's locale.

PropType
className
Classes for the <span>.
string

CalendarViewSwitcher

The view dropdown, wired to the provider: day, week, month, year or agenda, 2 to 9 days, and the view settings. It takes no props. Every view reads the three settings:

  • Weekends (⇧⌘E): off, day and week view show weekdays only and step over the weekend. The day after Friday is Monday, a full week shows Monday to Friday, a few days count weekdays (three days from Thursday are Thursday, Friday and Monday), and a drag from Friday to the next column lands on Monday. A Saturday you go to opens the Monday after it. Month and year view drop their weekend columns, and the agenda leaves weekend days out.
  • Declined events: off, the events you declined are hidden. On, they're drawn struck through on a dashed outline, without their color. An event is declined when its participant marked self (or the one whose email is the event's calendarEmail) has the response "declined".
  • Week numbers: on, the title names the week in day and week view ("Week 23"), the agenda marks where each week starts, and month and year view and the mini calendar number their weeks.

ViewDropdown in components/view-dropdown.tsx is the same menu driven by props instead of useCalendar().

On this page