# Drawer

A panel that slides in from the edge for a focused task over the page: the CRM's side panel. Built on ui-sdk's Drawer: modal, Escape or a press outside closes it, a swipe toward its edge dismisses it, and focus returns to the trigger.

- Beta: ready to use; its API can still change in a minor release.
- Category: Overlays

```tsx
import { Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerBody, DrawerFooter } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for a focused task over the page, like editing a contact or reviewing an opportunity, where the page stays in place behind it.
- Do: Give `DrawerHeader` a `title` that names the record, like Jane Citizen, and a `subtitle` for what it is, like Individual · Client.
- Do: Put long content in `DrawerBody`, which scrolls under the overlay scrollbar while the header and footer stay put.
- Do: Set `dismissible={false}` while the drawer holds unsaved edits, and ask Discard changes? in `onDismissAttempt`: a swipe, Escape or a press outside then reports the attempt instead of closing.
- Don't: Turn off `closeButton`. A panel needs a visible way out besides Escape and a swipe.
- Don't: Use it for a quick question or a confirmation. Use `Dialog`, or `AlertDialog` for a choice that can't be undone.

## Keyboard

| Keys | What they do |
| --- | --- |
| Tab | Stays inside the drawer and cycles through its controls in order. |
| Escape | Closes the drawer on top only. |

## Related

- [Dialog](./dialog.md)
- [Popover](./popover.md)
- [Panel Header](./panel-header.md)

## Examples

What the examples import:

```tsx
import { UserRound } from "lucide-react";
import { Button, Drawer, DrawerBody, DrawerClose, DrawerContent, DrawerFooter, DrawerHeader, DrawerTrigger } from "@leap-crm/design-system";
```

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

```tsx
const fields = [
  ["Email", "jane@citizen.com.au"],
  ["Phone", "0412 345 678"],
  ["Address", "14 Harbour Street, Sydney NSW 2000"],
  ["Source", "Website enquiry"],
  ["Responsible", "Ada Hartley"],
] as const;

function EditContact({ long = false }: { long?: boolean }) {
  const rows = long ? [...fields, ...fields, ...fields, ...fields] : fields;
  return (
    <Drawer>
      <DrawerTrigger
        render={
          <Button intent="outline" icon={<UserRound />}>
            {long ? "Long panel" : "Edit contact"}
          </Button>
        }
      />
      <DrawerContent>
        <DrawerHeader
          icon={<UserRound />}
          title="Jane Citizen"
          subtitle="Individual · Client"
        />
        <DrawerBody>
          <dl className="flex flex-col gap-4">
            {rows.map(([term, detail], index) => (
              <div
                key={`${term}-${String(index)}`}
                className="flex flex-col gap-1"
              >
                <dt className="text-small text-neutral-text-muted">{term}</dt>
                <dd className="text-body m-0">{detail}</dd>
              </div>
            ))}
          </dl>
        </DrawerBody>
        <DrawerFooter>
          <DrawerClose render={<Button intent="outline">Cancel</Button>} />
          <DrawerClose render={<Button>Save</Button>} />
        </DrawerFooter>
      </DrawerContent>
    </Drawer>
  );
}
```

### Side panel

From the end edge, up to 640 px wide: Panel header's layout (icon tile, title, muted line, round close), a padded body and the actions along the bottom.

```tsx
<EditContact />
```

### Long content

The body scrolls under the overlay scrollbar; the header and footer stay put.

```tsx
<EditContact long />
```

## Props

Drawer takes ui-sdk's options: open, defaultOpen, onOpenChange, modal, dismissible={false} with onDismissAttempt (ask "Discard changes?"), snapPoints and controller. DrawerClose takes render and value.

### Drawer

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `side` | `ComponentProps<typeof DrawerRoot>["side"]` | `"end"` | The edge it slides from. `end` (right in left-to-right text) for panels. |

### DrawerContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### DrawerHeader

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `icon` | `ReactNode` |  | The 20 px icon in the 40 px tile on the left. |
| `tone` | `Exclude<Tone, "default" \| "plum"> \| "neutral"` | `"info"` | The icon tile's colour, as IconTile. |
| `title` (required) | `ReactNode` |  | Names the drawer. |
| `subtitle` | `ReactNode` |  | One muted line under the title, which describes the drawer. |
| `closeButton` | `boolean` | `true` | Shows the round close button. Leave it on: a panel needs a visible way out. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### DrawerBody

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `children` | `ReactNode` |  | What it shows inside. |

### DrawerFooter

No props of its own.
