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-headerUsage
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 width | Shows |
|---|---|
| Under 20rem | The short month ("Sep"), today, previous and next |
| 20rem | The view switcher |
| 28rem | The full month name, and a divider after the sidebar toggle |
| 36rem | The 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
| Prop | Type | Default |
|---|---|---|
sidebarOpenWhether the sidebar is open. Its toggle's tooltip reads "Close sidebar" when it is, "Open sidebar" otherwise. | boolean | false |
onToggleSidebarOpens or closes the sidebar. The sidebar toggle shows only when this is set. | () => void | – |
contextPanelOpenWhether the context panel is open. Its toggle hides while it is. | boolean | false |
onToggleContextPanelOpens or closes the context panel. The toggle shows only when this is set. | () => void | – |
childrenShown before the view switcher on headers 36rem and wider, e.g. the signed-in user's avatar. | React.ReactNode | – |
classNameClasses 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.
| Prop | Type |
|---|---|
buttonClassNameClasses 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.
| Prop | Type |
|---|---|
classNameClasses 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'scalendarEmail) 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().