Skip to content

Drawer

A panel that slides in from the side for a longer task (create, edit, look at the details of one thing) while the page stays in its place behind.

import { Drawer } from '@sypnia/ui/react'

On this page
  1. Create something
  2. Look at one row
  3. When to use it
  4. For everyone
  5. Props

Create something

A form with its buttons always in view at the bottom.

Code
import { useState } from 'react';
import { Actions, Button, Checkbox, Drawer, Field, Fieldset, Input, NativeSelect } from '@sypnia/ui/react';

// The page stays behind, in its place. On a phone the drawer fills the screen.
export default function Create() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <Button variant="primary" icon="plus" onClick={() => setOpen(true)}>New API key</Button>
      <Drawer open={open} onClose={() => setOpen(false)} title="New API key"
        footer={<Actions><Button onClick={() => setOpen(false)}>Cancel</Button><Button variant="primary" onClick={() => setOpen(false)}>Create key</Button></Actions>}>
        <Field label="Name" hint="A name that tells you where the key is used."><Input autoFocus placeholder="Back office" /></Field>
        <Field label="Expires">
          <NativeSelect defaultValue="90"><option value="30">In 30 days</option><option value="90">In 90 days</option><option value="never">Never</option></NativeSelect>
        </Field>
        <Fieldset legend="This key can">
          <Checkbox label="Read rows" defaultChecked />
          <Checkbox label="Add and change rows" defaultChecked />
          <Checkbox label="Delete rows" />
        </Fieldset>
      </Drawer>
    </>
  );
}

Look at one row

Press an order number: its details open beside the table.

OrderCustomerTotal
Laura MéndezUS$ 128.40
Diego RuizUS$ 42.00
Ana CastañoUS$ 310.95
Code
import { useState } from 'react';
import { Badge, Button, Drawer, KeyValue, Table } from '@sypnia/ui/react';

const orders = [
  { id: '1042', customer: 'Laura Méndez', total: 'US$ 128.40', status: 'Paid' },
  { id: '1041', customer: 'Diego Ruiz', total: 'US$ 42.00', status: 'Pending' },
  { id: '1040', customer: 'Ana Castaño', total: 'US$ 310.95', status: 'Paid' },
];
// Press a row: its details open beside the list, which keeps its place.
export default function Inspect() {
  const [order, setOrder] = useState<(typeof orders)[number] | null>(null);
  return (
    <>
      <Table label="Orders" rows={orders} rowKey={(o) => o.id} columns={[
        { id: 'id', header: 'Order', cell: (o) => <Button size="sm" variant="quiet" onClick={() => setOrder(o)}>{o.id}</Button> },
        { id: 'customer', header: 'Customer', cell: (o) => o.customer },
        { id: 'total', header: 'Total', numeric: true, cell: (o) => o.total },
      ]} />
      <Drawer size="lg" open={order !== null} onClose={() => setOrder(null)} title={`Order ${order?.id}`}>
        {order && <KeyValue items={[
          ['Customer', order.customer],
          ['Total', order.total],
          ['Status', <Badge tone={order.status === 'Paid' ? 'ok' : 'warn'}>{order.status}</Badge>],
          ['Placed', 'November 16, 2026, 14:32'],
          ['Ships to', 'Calle 10 # 43-12, Medellín'],
        ]} />}
      </Drawer>
    </>
  );
}

When to use it

Use it when

  • Creating or editing something with several fields, without leaving the list it belongs to.
  • Looking at one row in detail and going back to the same place in the table.
  • More room is needed: size="lg".

Do not use it when

  • It is a short question or a field or two: Dialog.
  • The task has several steps or is the main thing the person came to do: give it a page.
  • It would open over another drawer.

For everyone

  • Same rules as Dialog: top layer, focus held inside, focus returns to what opened it.
  • A press on the backdrop closes it, as do Escape and the cross; a drag that starts inside does not. With dirty it keeps unsaved changes and says how to close.
  • The title and the buttons stay in view while the body scrolls.
  • On phones it fills the screen, so it reads as a page with a close button.

Props

DrawerTypeDefault
onCloserequired () => void
titlerequired ReactNode
dirty

The form inside has changes that are not saved. A press outside or Escape then does not close it and does not lose them: the panel nudges and says to save or cancel. Only the buttons close it.

boolean
dismissable

Whether a press on the backdrop (outside the panel) closes it. On by default; Escape always closes it too. Set false for a form that must be finished or cancelled with its buttons.

boolean
footer

Buttons at the bottom, inside <Actions>.

ReactNode
lines

How many lines of skeleton the body shows while loading.

number
loading

What it shows is on its way: the title and the buttons stay, the body is lines of skeleton.

boolean
open

Whether it is open. It can also simply be mounted and unmounted: it is open while mounted.

boolean
size "md" | "lg" md
  1. Create something
  2. Look at one row
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms