# Drawer

Source: https://ecosphere.dev/docs/feedback/drawer (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

A right-side panel for a queue or a record you read beside the list rather than instead of it.

`import { EcoDrawer } from "vue-ecosphere"`

## Reminders due

Open the drawer, dismiss a few rows, close it with Escape.

Vue (vue-ecosphere):

```vue
<EcoButton variant="primary" @click="open = true">Reminders due</EcoButton>

<EcoDrawer v-model:open="open" title="Reminders due" note="6 people">
  <article class="taskrow">
    <span class="avatar" aria-hidden="true">AW</span>
    <div class="taskrow__b">
      <div class="taskrow__top"><span class="taskrow__t">Adam Woods</span><span class="taskrow__s">api.internal expires in 6 days</span></div>
      <p class="taskrow__p">Auto-renewal is off for this domain, so it needs a manual rotation before the expiry date.</p>
      <p class="taskrow__meta">Last updated <b>Jul 24</b></p>
    </div>
    <div class="taskrow__act">
      <EcoButton variant="primary" size="sm">Review now</EcoButton>
      …
    </div>
  </article>
</EcoDrawer>
```

React (react-ecosphere):

```tsx
const [open, setOpen] = useState(false);

<EcoButton variant="primary" onClick={() => setOpen(true)}>Reminders due</EcoButton>

<EcoDrawer open={open} onOpenChange={setOpen} title="Reminders due" note="6 people">
  <article className="taskrow">
    <span className="avatar" aria-hidden="true">AW</span>
    <div className="taskrow__b">
      <div className="taskrow__top"><span className="taskrow__t">Adam Woods</span><span className="taskrow__s">api.internal expires in 6 days</span></div>
      <p className="taskrow__p">Auto-renewal is off for this domain, so it needs a manual rotation before the expiry date.</p>
      <p className="taskrow__meta">Last updated <b>Jul 24</b></p>
    </div>
    <div className="taskrow__act">
      <EcoButton variant="primary" size="sm">Review now</EcoButton>
      …
    </div>
  </article>
</EcoDrawer>
```

## Width

A form has a natural width: set width (px or a CSS length) instead of leaving it at the default. Narrow the window below 1024px and the drawer spans the screen again.

Vue (vue-ecosphere):

```vue
<EcoDrawer v-model:open="narrow" title="Edit guardian" :width="520">
  <div style="padding: 8px 10px">
    <EcoTextField v-model="guardian" label="Name" first />
    <EcoTextField v-model="phone" label="Phone" type="tel" />
  </div>
</EcoDrawer>
```

React (react-ecosphere):

```tsx
<EcoDrawer open={narrow} onOpenChange={setNarrow} title="Edit guardian" width={520}>
  <div style={{ padding: "8px 10px" }}>
    <EcoTextField value={guardian} onChange={setGuardian} label="Name" first />
    <EcoTextField value={phone} onChange={setPhone} label="Phone" type="tel" />
  </div>
</EcoDrawer>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model:open` | `boolean` | false | Slides the drawer in (drawer.is-open) over a soft scrim, teleported to body. Escape, × and the scrim close it; focus is trapped and returns to the opener. |
| `title` | `string` | — | drawer__t; labels the dialog (#title slot). |
| `note` | `string` | — | Short figure beside the title (#note slot). |
| `dismissible` | `boolean` | true | Close on a scrim click. |
| `width` | `number \| string` | min(64vw, 900px) | Panel width in px or any CSS length, set through --drawer-w and capped at the viewport. Below 1024px the drawer spans the screen regardless. |
| `#default` | `slot { close }` | — | drawer__body content, e.g. taskrow articles. |
| `#actions` | `slot` | — | Extra head controls before the × button. |
| `@close` | `() => void` | — | Closed by any route. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `open / onOpenChange` | `boolean` | false | Slides the drawer in (drawer.is-open) over a soft scrim, portalled to body. Escape, × and the scrim close it; focus is trapped and returns to the opener. Or defaultOpen, uncontrolled. |
| `title` | `ReactNode` | — | drawer__t; labels the dialog. Text, or a node. |
| `note` | `ReactNode` | — | Short figure beside the title. |
| `dismissible` | `boolean` | true | Close on a scrim click. |
| `width` | `number \| string` | min(64vw, 900px) | Panel width in px or any CSS length, set through --drawer-w and capped at the viewport. Below 1024px the drawer spans the screen regardless. |
| `children` | `ReactNode \| ((scope: { close }) => ReactNode)` | — | drawer__body content, e.g. taskrow articles. |
| `actions` | `ReactNode` | — | Extra head controls before the × button. |
| `onClose` | `() => void` | — | Closed by any route. |
