# People Picker

Notion Calendar's F and P dialog, to meet with someone or show a teammate's calendar.

`PeoplePicker` is the dialog the [live demo](/) opens with `F` ("Meet with...") and `P` ("Show teammate calendar..."), and from the same commands in the [Command Menu](/docs/components/command-menu). It searches the provider's `contacts` by name or email, and offers a typed address no contact has. Picking someone meets with them or shows their calendar through [`useCalendarPeople()`](/docs/components/calendar-core#usecalendarpeople), so it goes inside `CalendarProvider`.

## Installation

```bash
npx shadcn add @calendarcn/people-picker
```

Or install it by hand:

1. Install the items it builds on: `@calendarcn/calendar-core`
2. Add the shadcn/ui components it uses: `npx shadcn add command dialog kbd`
3. Copy these files into your project, keeping the paths under your components, hooks and lib folders:
   - [`components/people-picker.tsx`](https://github.com/vmnog/calendarcn/blob/main/src/components/people-picker.tsx)

## Usage

```tsx
import { useCalendarShortcuts } from "@/hooks/use-calendar-shortcuts";
import { CalendarProvider } from "@/components/calendar-provider";
import { PeoplePicker } from "@/components/people-picker";
import { WeekView } from "@/components/week-view";
import type { PeoplePickerMode } from "@/components/calendar-types";

export function Schedule() {
  return (
    <CalendarProvider
      defaultEvents={events}
      contacts={contacts}
      contactEvents={contactEvents}
    >
      <CalendarWithPeople />
    </CalendarProvider>
  );
}

function CalendarWithPeople() {
  const [open, setOpen] = React.useState(false);
  const [mode, setMode] = React.useState<PeoplePickerMode>("meet-with");
  const openPicker = (next: PeoplePickerMode) => {
    setMode(next);
    setOpen(true);
  };

  // F and P open it, as in Notion Calendar
  useCalendarShortcuts({
    onMeetWith: () => openPicker("meet-with"),
    onShowTeammateCalendar: () => openPicker("teammate"),
  });

  return (
    <>
      <WeekView />
      <PeoplePicker open={open} onOpenChange={setOpen} mode={mode} />
    </>
  );
}
```

- `"meet-with"` adds the person to the meeting: their events show beside yours and the times you're all free are highlighted. An event you create meanwhile invites them. See [Meeting with people](/docs/components/calendar-core#meeting-with-people).
- `"teammate"` shows their calendar beside yours, without a meeting.

The people already added are left out of the list. The arrow keys move through it, `Enter` picks, and `Esc` closes the picker, which opens empty the next time. The [Calendar Sidebar](/docs/components/calendar-sidebar) lists who was picked, each removable.

## API Reference

### PeoplePicker

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` (required) | `boolean` | – | Whether the picker is open. |
| `onOpenChange` (required) | `(open: boolean) => void` | – | Called when the picker opens or closes: on Escape, a click outside, or once someone is picked. |
| `mode` | `"meet-with" \| "teammate"` | `"meet-with"` | Meet with the picked person, or show their calendar. Also sets the placeholder: "Meet with..." or "Show teammate calendar...". |
