RegistryInstall CalendarCN with the shadcn CLI

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-menu

Usage

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 date

To 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
/>
  • onImportIcs and onExportIcs add "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 to parseIcs() and adds the events, and downloads toIcs(events) as a file.
  • onCycleTheme adds "Set theme...". The demo goes from system to light to dark with useTheme() from next-themes.
  • onSearchEvents adds "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.
  • onShowShortcuts adds "Show keyboard shortcuts" (?). The demo shows the details sidebar's full list.
  • onMeetWith and onShowTeammateCalendar add "Meet with..." (F) and "Show teammate calendar..." (P). The demo opens the People Picker from both.
  • onToggleSidebar and onToggleContextPanel add the panel toggles, next to the Calendar Header's buttons.
  • onShareAvailability adds "Share availability..." (S), and onCreateSchedulingLink adds "Create recurring scheduling link..." and "Create one-off scheduling link...", called with "recurring" or "one-off". Calendar App passes them from useScheduling(); the link commands only when the app creates scheduling links.
  • onOpenSettings adds "Go to settings" (⌘,). The demo opens the Calendar Settings dialog.
  • onAddCalendarAccount and onManageCalendarAccounts add "Add calendar account" and "Manage calendar accounts". The demo adds an .ics file as a calendar, and opens the settings on the calendars.
  • onSupport adds "Support & feedback" and onAbout adds "About CalendarCN". The demo opens a new GitHub issue in a new tab, and the docs.
  • showComingSoon also 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

PropTypeDefault
open
Whether the menu is open.
boolean–
onOpenChange
Called when the menu opens or closes: on Escape, a click outside, or before a command runs.
(open: boolean) => void–
onToggleSidebar
Adds "Toggle sidebar" (⌘ /).
() => void–
onToggleContextPanel
Adds "Toggle context panel" (/).
() => void–
onCycleTheme
Adds "Set theme..." (Shift M).
() => void–
onImportIcs
Adds "Import .ics file...".
() => void–
onExportIcs
Adds "Export .ics file".
() => void–
onShareAvailability
Adds "Share availability..." (S).
() => void–
onCreateSchedulingLink
Adds "Create recurring scheduling link..." and "Create one-off scheduling link...".
(kind: "recurring" | "one-off") => void–
onOpenSettings
Adds "Go to settings" (⌘ ,).
() => void–
onAddCalendarAccount
Adds "Add calendar account".
() => void–
onManageCalendarAccounts
Adds "Manage calendar accounts".
() => void–
onSupport
Adds "Support & feedback".
() => void–
onAbout
Adds "About CalendarCN".
() => void–
onMeetWith
Adds "Meet with..." (F).
() => void–
onShowTeammateCalendar
Adds "Show teammate calendar..." (P).
() => void–
onSearchEvents
Adds "Search events" (called with an empty query) and, once text is typed, "Search events for “…”" (called with that text).
(query: string) => void–
onShowShortcuts
Adds "Show keyboard shortcuts" (?).
() => void–
defaultPage
The page the menu opens on, each time it opens: its commands, or Go to date's field.
"commands" | "go-to-date""commands"
showComingSoon
Also lists the commands CalendarCN doesn't have yet, disabled with a "Soon" badge.
booleanfalse
timeZoneCommand
Opens the menu on that time zone command's list instead of the commands, e.g. "travel" for the Z key.
"travel" | "add" | "primary" | "hide"–

On this page