Components
Command Menu
The live demo's ⌘K menu, for creating an event, going to a typed date, today, previous and next, switching views, and your app's own commands.
CommandMenu is the live demo's ⌘K menu, built on shadcn/ui's Command in a Dialog. Creating an event, going to a date, today, previous and next, the day, week, month, year and agenda views, "Select all visible" (⌘A), the view settings ("Hide weekends", "Hide declined events" and "Hide week numbers", which read "Show …" while the setting is off, as in Notion Calendar), the week start ("Start week on..."), the number of days ("Set number of displayed days...") and the hour size ("Default hour size", "Zoom hours in", "Zoom hours out") come from useCalendar(), so it goes inside CalendarProvider. Commands that belong to your app, such as its panels, event search, the shortcut list, its theme and .ics files, show only when you pass their callback.
Installation
pnpm dlx shadcn add @calendarcn/command-menuUsage
import { useCalendarShortcuts } from "@/hooks/use-calendar-shortcuts";
import { CalendarProvider } from "@/components/calendar-provider";
import { CommandMenu } from "@/components/command-menu";
import { WeekView } from "@/components/week-view";
export function Schedule() {
return (
<CalendarProvider defaultEvents={events}>
<CalendarWithMenu />
</CalendarProvider>
);
}
function CalendarWithMenu() {
const [open, setOpen] = React.useState(false);
// ⌘K / Ctrl+K opens and closes the menu, even from a text field
useCalendarShortcuts({ onToggleCommandMenu: () => setOpen((o) => !o) });
return (
<>
<WeekView />
<CommandMenu open={open} onOpenChange={setOpen} />
</>
);
}The menu is controlled: it opens and closes through open and onOpenChange, and closes before it runs a command. The preview opens it from a button, to leave ⌘K to this site's search.
Go to date
"Go to date..." turns the menu's field into a date field, as in Notion Calendar. Type a date and the menu shows the day it reads, with its weekday, so you can check "next friday" before going there. Enter shows that day's period in the current view and briefly highlights it (navigateToDate). Esc closes the menu without moving, and ⌫ in the empty field goes back to the commands.
It reads "today", "tomorrow", weekdays ("friday", "next friday", "last monday"), "next week", "next month", "in 2 weeks", "3 days ago", "+3d", a month and day in either order ("dec 25", "25 december", "December 25th, 2027", "sept 5"), a month alone ("jan"), a numeric date in the locale's order ("12/25", or "25/12" in en-GB, "25.12." in German) and "2027-12-25". A date without a year is the next one from today, and weeks start on the provider's weekStartsOn. Month and weekday names work in the provider's locale and in English. The parser is parseDateQuery() in lib/date-query.ts, which the CLI installs with the menu:
import { parseDateQuery } from "@/lib/date-query";
parseDateQuery("next friday", { today: new Date(), locale, weekStartsOn });
// → the Friday of next week, at midnight, or null when the text isn't a dateTo open the menu straight on Go to date, as the . key does in the demo, pass defaultPage="go-to-date" before opening it:
const [page, setPage] = React.useState<CommandMenuPage>("commands");
useCalendarShortcuts({
onToggleCommandMenu: () => {
setPage("commands");
setOpen((o) => !o);
},
onGoToDate: () => {
setPage("go-to-date");
setOpen(true);
},
});
<CommandMenu open={open} onOpenChange={setOpen} defaultPage={page} />;Create event
"Create event..." (C outside the menu) starts a new event at the next half hour, as Notion Calendar does: on today when it's on screen, else on the first day shown (addEventAtNextSlot), all-day in month view. It goes through your createEvent and is a draft with its title focused: its first edit saves it, and undo and the details then work as for any new event.
Second lists
"Start week on..." and "Set number of displayed days..." open a second list in the same menu, as Notion Calendar's do: the days of the week other than the one the week starts on now ("Mondays", "Tuesdays", ...), or the day counts 2 to 9. Type to filter them, ↵ picks one, ⌫ in the empty search goes back to the commands, and Esc closes the menu.
Your app's commands
Pass a callback to add its command. These are the demo's:
<CommandMenu
open={open}
onOpenChange={setOpen}
onToggleSidebar={toggleSidebar}
onToggleContextPanel={toggleContextPanel}
onCycleTheme={cycleTheme}
onImportIcs={() => fileInputRef.current?.click()}
onExportIcs={exportIcs}
onOpenSettings={openSettings}
onAddCalendarAccount={addCalendarAccount}
onManageCalendarAccounts={manageCalendarAccounts}
onSupport={() => window.open(ISSUES_URL, "_blank")}
onAbout={() => router.push("/docs")}
onSearchEvents={(query) => detailsActions.current?.searchEvents(query)}
onShowShortcuts={() => detailsActions.current?.showAllShortcuts()}
onMeetWith={() => openPeoplePicker("meet-with")}
onShowTeammateCalendar={() => openPeoplePicker("teammate")}
showComingSoon
/>onImportIcsandonExportIcsadd "Import .ics file..." and "Export .ics file". Read and write the files with@calendarcn/ics: the demo opens a hidden<input type="file">, passes its text toparseIcs()and adds the events, and downloadstoIcs(events)as a file.onCycleThemeadds "Set theme...". The demo goes from system to light to dark withuseTheme()from next-themes.onSearchEventsadds "Search events", and once you type, "Search events for “…”" with your text. The demo opens the Details Sidebar's event search with the field focused.onShowShortcutsadds "Show keyboard shortcuts" (?). The demo shows the details sidebar's full list.onMeetWithandonShowTeammateCalendaradd "Meet with..." (F) and "Show teammate calendar..." (P). The demo opens the People Picker from both.onToggleSidebarandonToggleContextPaneladd the panel toggles, next to the Calendar Header's buttons.onShareAvailabilityadds "Share availability..." (S), andonCreateSchedulingLinkadds "Create recurring scheduling link..." and "Create one-off scheduling link...", called with"recurring"or"one-off". Calendar App passes them fromuseScheduling(); the link commands only when the app creates scheduling links.onOpenSettingsadds "Go to settings" (⌘,). The demo opens the Calendar Settings dialog.onAddCalendarAccountandonManageCalendarAccountsadd "Add calendar account" and "Manage calendar accounts". The demo adds an .ics file as a calendar, and opens the settings on the calendars.onSupportadds "Support & feedback" andonAboutadds "About CalendarCN". The demo opens a new GitHub issue in a new tab, and the docs.showComingSoonalso lists the Notion Calendar commands CalendarCN doesn't have yet, disabled with a "Soon" badge, as the demo does.
Time zones
The "Time zones" commands come from useCalendar(), like going to today and the views, so they work in any calendar:
- "Travel to time zone..." draws the calendar in another zone for now, with your home zone beside it. See Travel to a time zone.
- "Show additional time zones..." adds a zone's column beside the time axis.
- With more than one zone, "Make time zone primary..." and "Hide time zone..." pick one of the zones shown.
Each opens a list of zones in the menu's place, searched by city, zone name or offset ("Tokyo", "Japan", "+9"). ⌫ in an empty search goes back to the commands. Pass timeZoneCommand="travel" to open the menu on its list: the demo does that for Z, with useCalendarShortcuts({ onTravelToTimeZone }).
Keyboard shortcuts
The menu shows each command's shortcut. Pass the same callbacks to useCalendarShortcuts() to turn the keys on:
useCalendarShortcuts({
onToggleCommandMenu: () => setOpen((o) => !o),
onToggleSidebar: toggleSidebar,
onToggleContextPanel: toggleContextPanel,
onCycleTheme: cycleTheme,
});Theming
The dialog is translucent and blurred in dark mode. The CLI also adds a rule to your CSS file that dims the page less behind the menu in dark mode (rgb(0 0 0 / 0.3)), found through the data-command-menu attribute on the dialog. The rest of the look comes from your own command and dialog components.
API Reference
CommandMenu
| Prop | Type | Default |
|---|---|---|
openWhether the menu is open. | boolean | – |
onOpenChangeCalled when the menu opens or closes: on Escape, a click outside, or before a command runs. | (open: boolean) => void | – |
onToggleSidebarAdds "Toggle sidebar" (⌘ /). | () => void | – |
onToggleContextPanelAdds "Toggle context panel" (/). | () => void | – |
onCycleThemeAdds "Set theme..." (Shift M). | () => void | – |
onImportIcsAdds "Import .ics file...". | () => void | – |
onExportIcsAdds "Export .ics file". | () => void | – |
onShareAvailabilityAdds "Share availability..." (S). | () => void | – |
onCreateSchedulingLinkAdds "Create recurring scheduling link..." and "Create one-off scheduling link...". | (kind: "recurring" | "one-off") => void | – |
onOpenSettingsAdds "Go to settings" (⌘ ,). | () => void | – |
onAddCalendarAccountAdds "Add calendar account". | () => void | – |
onManageCalendarAccountsAdds "Manage calendar accounts". | () => void | – |
onSupportAdds "Support & feedback". | () => void | – |
onAboutAdds "About CalendarCN". | () => void | – |
onMeetWithAdds "Meet with..." (F). | () => void | – |
onShowTeammateCalendarAdds "Show teammate calendar..." (P). | () => void | – |
onSearchEventsAdds "Search events" (called with an empty query) and, once text is typed, "Search events for “…”" (called with that text). | (query: string) => void | – |
onShowShortcutsAdds "Show keyboard shortcuts" (?). | () => void | – |
defaultPageThe page the menu opens on, each time it opens: its commands, or Go to date's field. | "commands" | "go-to-date" | "commands" |
showComingSoonAlso lists the commands CalendarCN doesn't have yet, disabled with a "Soon" badge. | boolean | false |
timeZoneCommandOpens the menu on that time zone command's list instead of the commands, e.g. "travel" for the Z key. | "travel" | "add" | "primary" | "hide" | – |