# Note panel

An open note in the side panel. Metadata sits in a quiet band on top: the kind, where it belongs, the actions, then who wrote it and when, with Edited opening the version history. The note itself has the white page below. Comments follow under a divider, with @ to tag colleagues.

- Beta: ready to use; its API can still change in a minor release.
- Category: Patterns · Notes & tasks

```tsx
import { NotePanel } from "@leap-crm/design-system";
```

## Best practices

- Do: Set `context` only when the note belongs somewhere other than the page it's opened on, like its matter when it's opened from a contact.
- Do: Pass only the actions the reader may take. Each of `onEdit`, `onCopyLink`, `onHistory`, `onMove`, `onPinChange` and `onDelete` adds its menu item, and a missing one leaves it out.
- Do: Pass `onHistory` with `edited`, so “Edited” after the date opens the `NoteVersionHistory`.
- Do: Pass `people`, so @names in the note and its comments show in link colour and can be tagged in a new comment.
- Don't: Delete straight from `onDelete`. The menu item calls it at once, so confirm in an `AlertDialog` whose confirming button carries `data-agent-confirm`.
- Don't: Set `entrance` or `leaving` when the panel opens from a `NoteGrid`. The grid sets them as the tile grows into the panel.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter | In the comment field, posts the comment. |
| ArrowDown, ArrowUp | While the list of people is open, move through it. |
| Enter, Tab | While the list of people is open, choose the highlighted person. |
| Escape | Closes the list of people. |

## Related

- [Note grid](./note-grid.md)
- [Note tile](./note-tile.md)
- [Note version history](./note-version-history.md)
- [Note composer](./note-composer.md)

## Examples

What the examples import:

```tsx
import { useState } from "react";
import { NotePanel, type NoteComment } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const people = [
  { name: "Mia Gold", initials: "MG" },
  { name: "Sam Evans", initials: "SE" },
];

const body =
  "Agent called: the vendor prefers 60 days and will take 45 with a 10% deposit. Rose is fine with either.\n\n@Mia Gold to confirm with her lender before we reply. If the lender needs longer than 45 days, we counter at 60 with the 10% deposit.";

function OpenNote() {
  const [pinned, setPinned] = useState(true);
  const [comments, setComments] = useState<NoteComment[]>([
    {
      id: "1",
      author: people[0] ?? { name: "" },
      time: "4:38 pm",
      text: "Lender says 45 days is fine if the valuation is back by the 5th.",
    },
    {
      id: "2",
      author: people[1] ?? { name: "" },
      time: "4:51 pm",
      text: "Good, I will tell the agent 45. @Mia Gold can you send the valuation request today?",
    },
    {
      id: "3",
      author: people[0] ?? { name: "" },
      time: "5:02 pm",
      text: "Sent.",
    },
  ]);
  return (
    <NotePanel
      className="w-lg"
      kind="call"
      context={{ type: "matter", label: "14 Hill St purchase" }}
      title="Vendor wants a 60-day settlement"
      body={body}
      author={{ name: "Sam Evans", initials: "SE", viaFirmPilot: true }}
      date="21 Nov, 4:12 pm"
      edited
      pinned={pinned}
      onPinChange={setPinned}
      onEdit={() => undefined}
      onCopyLink={() => undefined}
      onHistory={() => undefined}
      onMove={() => undefined}
      onDelete={() => undefined}
      onClose={() => undefined}
      people={people}
      you={{ name: "Marcus Hugh", initials: "MH" }}
      comments={comments}
      onComment={text =>
        setComments(list => [
          ...list,
          {
            id: String(list.length + 1),
            author: { name: "Marcus Hugh", initials: "MH" },
            time: "Just now",
            text,
          },
        ])
      }
    />
  );
}
```

### An open note

Pin, the ⋯ menu and Close sit together. Type @ in the comment field to tag someone; Enter posts.

```tsx
<OpenNote />
```

### Written by someone, no comments yet

```tsx
<NotePanel
  className="w-lg"
  kind="note"
  title="Finance pre-approval received"
  body="Rose sent the pre-approval letter from her broker, valid to 15 Jan. Saved under Documents."
  author={{ name: "Mia Gold", initials: "MG" }}
  date="18 Nov, 9:30 am"
  onClose={() => undefined}
  onComment={() => undefined}
/>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `kind` (required) | `NoteKind` |  | What the note records. Its icon and word lead the metadata band. |
| `context` | `NoteContext` |  | Where the note belongs, only when that isn't this page. |
| `title` (required) | `string` |  | The note's title. |
| `body` (required) | `string` |  | The note. Line breaks are kept; @names of `people` show in link colour. |
| `author` (required) | `NoteAuthor` |  | Who wrote it. With `viaFirmPilot`, the byline reads "via Firm Pilot". |
| `date` (required) | `string` |  | When it was written, already formatted, like "21 Nov, 4:12 pm". |
| `edited` | `boolean` | `false` | Shows "Edited" after the date, a link to the version history. |
| `pinned` | `boolean` | `false` | Pressed when the note is pinned. |
| `onPinChange` | `(pinned: boolean) => void` |  | Pins or unpins the note. Shows the pin button and the Pin or Unpin menu item. |
| `onEdit` | `() => void` |  | Opens the note for editing. |
| `onCopyLink` | `() => void` |  | Copies a link to the note. |
| `onHistory` | `() => void` |  | Opens the version history, from the menu and from "Edited". |
| `onMove` | `() => void` |  | Moves the note to another matter. |
| `onDelete` | `() => void` |  | Deletes the note. |
| `onClose` | `() => void` |  | Closes the panel. |
| `comments` | `unknown` | `[]` | Comments under the note, oldest first. |
| `people` | `unknown` | `[]` | Staff who can be tagged with @ in the note and in a comment. |
| `you` | `NotePerson` |  | Whoever is writing a comment, for the avatar beside the field. |
| `onComment` | `(text: string) => void` |  | Adds a comment. Shows the comment field. |
| `entrance` | `boolean` | `false` | Opening from a tile: the band, then the note, then the comments fade and sharpen in, after the surface has started to move. NoteGrid sets it. |
| `leaving` | `boolean` | `false` | Closing back into a tile: the panel's words fade out before the surface moves. NoteGrid sets it. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
