# Details Sidebar

The right context panel of the demo, with the selected event's details, event search and the full keyboard shortcut list.

Live example, interactive at https://calendarcn.xyz/docs/components/details-sidebar. Its source:

```tsx title="src/examples/details-sidebar-demo.tsx"
"use client";

import * as React from "react";
import { PanelRightIcon } from "lucide-react";

import { CalendarProvider, useCalendar } from "@/components/calendar-provider";
import {
  CONTEXT_PANEL_WIDTH,
  DetailsSidebar,
} from "@/components/details-sidebar";
import { WeekView } from "@/components/week-view";
import { Button } from "@/components/ui/button";
import { SidebarProvider, useSidebar } from "@/components/ui/sidebar";
import { createSampleEvents } from "@/lib/sample-events";

export function DetailsSidebarDemo() {
  // The provider reads its initial events once, so create them once
  const [initialEvents] = React.useState(() => createSampleEvents(new Date()));

  return (
    <CalendarProvider defaultEvents={initialEvents} defaultNumberOfDays={3}>
      {/* The inline panel is position: fixed; the transform keeps it in this frame */}
      <SidebarProvider
        className="h-full min-h-0 [transform:translateZ(0)]"
        style={
          { "--sidebar-width": CONTEXT_PANEL_WIDTH } as React.CSSProperties
        }
      >
        <CalendarWithDetails />
      </SidebarProvider>
    </CalendarProvider>
  );
}

function CalendarWithDetails() {
  // Phones get the panel as an overlay; the open state is the SidebarProvider's
  const { isMobile, open, openMobile, setOpenMobile, toggleSidebar } =
    useSidebar();
  const { monthName, year } = useCalendar();
  const panelOpen = isMobile ? openMobile : open;

  return (
    <>
      <div className="flex min-w-0 flex-1 flex-col overflow-hidden">
        <header className="flex h-14 shrink-0 items-center gap-2 px-4">
          <h2 className="flex-1 truncate text-base font-extrabold">
            {monthName} {year}
          </h2>
          {!panelOpen && (
            <Button
              variant="ghost"
              size="icon"
              className="size-7 text-muted-foreground"
              onClick={toggleSidebar}
            >
              <PanelRightIcon />
              <span className="sr-only">Open context panel</span>
            </Button>
          )}
        </header>
        <div className="flex flex-1 flex-col overflow-hidden">
          {/* With the panel open, an event's details show there instead of a popover */}
          <WeekView
            scrollToHour={8}
            showEventPopover={!panelOpen}
            onEventPopoverExpand={() =>
              isMobile ? setOpenMobile(true) : toggleSidebar()
            }
          />
        </div>
      </div>
      <DetailsSidebar overlay={isMobile} className="h-full" />
    </>
  );
}
```

Details Sidebar is the right column of the [live demo](/), Notion Calendar's context panel. It shows the selected event's details in the [`EventDetailPanel`](/docs/components/event-details), and otherwise a search field and a list of useful shortcuts. While you mark open times inside a [`SchedulingProvider`](/docs/components/scheduling), it shows the scheduling panel: the meeting length, the text to copy and the marked times. On wide screens it's a fixed column beside the calendar; on narrower ones it opens as a sheet from the right ([Sidebar Overlay](/docs/components/sidebar-overlay)).

It reads the events and the selection from the surrounding [`CalendarProvider`](/docs/components/calendar-core), and edits the event through it.

## Installation

```bash
npx shadcn add @calendarcn/details-sidebar
```

Or install it by hand:

1. Install the items it builds on: `@calendarcn/calendar-core`, `@calendarcn/event-details`, `@calendarcn/sidebar-overlay`
2. Install the dependencies: `npm install date-fns lucide-react`
3. Add the shadcn/ui components it uses: `npx shadcn add button dropdown-menu kbd sidebar tooltip`
4. Copy these files into your project, keeping the paths under your components, hooks and lib folders:
   - [`components/details-sidebar.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/details-sidebar.tsx)
   - [`components/availability-panel.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/availability-panel.tsx)

## Usage

The panel's open state is shadcn/ui's `SidebarProvider`: open it with `useSidebar()` (`toggleSidebar`, `setOpen`), and set the provider's `--sidebar-width` to `CONTEXT_PANEL_WIDTH`. Put it last in the provider's row, after the calendar, and turn the views' popover off while the panel shows the details:

```tsx
import { CalendarProvider } from "@/components/calendar-provider";
import {
  CONTEXT_PANEL_WIDTH,
  DetailsSidebar,
} from "@/components/details-sidebar";
import { SidebarProvider, useSidebar } from "@/components/ui/sidebar";
import { WeekView } from "@/components/week-view";

export function CalendarPage() {
  return (
    <CalendarProvider defaultEvents={events}>
      <SidebarProvider
        className="h-screen"
        style={
          { "--sidebar-width": CONTEXT_PANEL_WIDTH } as React.CSSProperties
        }
      >
        <Calendar />
        <DetailsSidebar />
      </SidebarProvider>
    </CalendarProvider>
  );
}

function Calendar() {
  const { open, toggleSidebar } = useSidebar();

  return (
    <div className="flex min-w-0 flex-1 flex-col">
      <WeekView showEventPopover={!open} onEventPopoverExpand={toggleSidebar} />
    </div>
  );
}
```

On narrow screens, pass `overlay`. The demo shows the panel inline from 1280px wide and as an overlay below that, and opens the sheet when an event is selected on a phone (the views' popover doesn't fit beside an event there):

```tsx
const isWide = useMediaQuery("(min-width: 1280px)");
const { isMobile, setOpenMobile } = useSidebar();

<CalendarProvider onEventSelect={() => isMobile && setOpenMobile(true)}>
  {/* ... */}
  <DetailsSidebar overlay={!isWide} />
</CalendarProvider>;
```

Replace the shortcuts listed while nothing is selected with `shortcuts`:

```tsx
<DetailsSidebar
  shortcuts={[
    { label: "Command menu", keys: ["⌘", "K"] },
    { label: "Today", keys: ["T"] },
  ]}
/>
```

Mark a shortcut your app doesn't handle yet with `soon: true`: its row shows a "Soon" badge in place of the keys. The default list has none: CalendarCN handles every shortcut it lists.

### Search and the shortcut list from your commands

Pass a ref to `actionsRef` to open the panel from a command or a key: `searchEvents(query?)` opens it on event search with the field focused (and the text typed in, if you pass some), and `showAllShortcuts()` opens it on the full keyboard shortcut list. Both deselect a selected event, whose details would otherwise cover them. The demo calls them from the [Command Menu](/docs/components/command-menu) and the `?` key:

```tsx
import type { DetailsSidebarActions } from "@/components/week-view-types";

const panelActions = React.useRef<DetailsSidebarActions>(null);

useCalendarShortcuts({
  onShowShortcuts: () => panelActions.current?.showAllShortcuts(),
});

<DetailsSidebar actionsRef={panelActions} />;
```

### All keyboard shortcuts

The full list is Notion Calendar's: every shortcut under its group (General, Workflows, Editing, Calendar view, Calendar navigation, App navigation), the ones that act on an event under "With a selected event…". The field at the top finds one by name or by key, and `Esc` or its × goes back to the useful shortcuts. Selecting an event closes it too.

It lists `KEYBOARD_SHORTCUT_GROUPS` from `lib/keyboard-shortcuts.ts` ([Calendar Core](/docs/components/calendar-core)), every key the live demo handles. Pass `shortcutGroups` for your own: the demo leaves out `⌘,` when it has no settings, with `filterKeyboardShortcutGroups()`. The default "Useful shortcuts" take their Go to date and full-list keys from the same file.

The panel uses the calendar sidebar's colors: see [Colors](/docs/components/calendar-sidebar#colors).

## Features

- Selecting an event shows its details, editable in place. Creating one focuses its title.
- Search events by title, from the field or from your command (`actionsRef`). A repeating event is listed on each of its dates within a year of today. Results are grouped by day, past days dimmed, with "Today" always shown. Click a result to see its details, and "Search" to go back.
- The repeat row's arrows step through a repeating event's series.
- The full keyboard shortcut list, with a field to find one by name or key.
- `/` and the panel's button toggle it in the demo (the shortcut is the
  page's own). As a sheet it closes on an outside tap or `Esc`, and
  opens without focusing the search field, so a phone's keyboard stays down.

## API Reference

### DetailsSidebar

Other props go to the inline panel's fixed column.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `overlay` | `boolean` | `false` | Renders the panel as a sheet from the right (phones and tablets). |
| `shortcuts` | `DetailsSidebarShortcut[]` | `USEFUL_SHORTCUTS` | Shortcuts listed while no event is selected or searched: `{ label, keys, soon }`. Each key shows as a key cap; a `soon` one shows a "Soon" badge instead. |
| `shortcutGroups` | `KeyboardShortcutGroup[]` | `KEYBOARD_SHORTCUT_GROUPS` | The full keyboard shortcut list `showAllShortcuts()` shows: groups of `{ label, keys, alternativeKeys, keywords }`, with `sections` for the ones under a muted heading. |
| `actionsRef` | `Ref<DetailsSidebarActions>` | – | Receives `searchEvents(query?)` and `showAllShortcuts()`, which open the panel on event search or the full shortcut list with its field focused. |
| `className` | `string` | – | Classes for the inline panel's fixed column, e.g. `h-full` to fit a container that isn't the viewport. |

`CONTEXT_PANEL_WIDTH` (`309px`) is the panel's width: Notion Calendar's 308px plus a 1px border. `USEFUL_SHORTCUTS` is the default list.
