Drawer
Un panel que entra por el costado para una tarea más larga (crear, editar, ver los detalles de una cosa) mientras la página se queda en su lugar detrás.
import { Drawer } from '@sypnia/ui/react'
En esta página
Crear algo
Un formulario con sus botones siempre a la vista abajo.
Código
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>
</>
);
} Ver una fila
Presiona un número de pedido: sus detalles se abren al lado de la tabla.
| Order | Customer | Total |
|---|---|---|
| Laura Méndez | US$ 128.40 | |
| Diego Ruiz | US$ 42.00 | |
| Ana Castaño | US$ 310.95 |
Código
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>
</>
);
} Cuándo usarlo
Úsalo cuando
- Crear o editar algo con varios campos, sin salir de la lista a la que pertenece.
- Ver una fila en detalle y volver al mismo lugar de la tabla.
- Hace falta más espacio:
size="lg".
No lo uses cuando
- Es una pregunta corta o uno o dos campos: Dialog.
- La tarea tiene varios pasos o es lo principal que vino a hacer la persona: dale una página.
- Se abriría encima de otro panel.
Para todos
- Las mismas reglas que Dialog: capa superior, foco retenido adentro, el foco vuelve a lo que lo abrió.
- Un toque en el fondo lo cierra, igual que Escape y la cruz; un arrastre que empieza adentro no. Con
dirtyconserva los cambios sin guardar y dice cómo cerrar. - El título y los botones quedan a la vista mientras el cuerpo se desplaza.
- En el celular llena la pantalla, así se lee como una página con un botón para cerrar.
Props
| Drawer | Tipo | Por defecto |
|---|---|---|
onCloseobligatorio | () => void | |
titleobligatorio | ReactNode | |
dirtyThe 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 | |
dismissableWhether 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 | |
footerButtons at the bottom, inside <Actions>. | ReactNode | |
linesHow many lines of skeleton the body shows while loading. | number | |
loadingWhat it shows is on its way: the title and the buttons stay, the body is lines of skeleton. | boolean | |
openWhether it is open. It can also simply be mounted and unmounted: it is open while mounted. | boolean | |
size | "md" | "lg" | md |