import { Button } from "@senvenli/react/action";
import { DescriptionList } from "@senvenli/react/display";
import { DialogTrigger, Drawer } from "@senvenli/react/overlay";
export default function Example() {
return (
<DialogTrigger>
<Button>View order</Button>
<Drawer title="Order ORD-1040" description="Ada Lovelace · placed March 18">
<DescriptionList
items={[
{ label: "Status", value: "Shipped" },
{ label: "Total", value: "$248.00" },
{ label: "Tracking", value: "1Z 999 AA1 01 2345 6784", copyValue: "1Z999AA10123456784" },
{ label: "Note" },
]}
/>
</Drawer>
</DialogTrigger>
);
}import { Drawer } from "@senvenli/react/overlay";Examples
Unsaved changes
Closing asks first while there are edits; saving closes without the question.import { Button } from "@senvenli/react/action";
import { TextArea } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";
import { DialogTrigger, Drawer, useDrawerClose } from "@senvenli/react/overlay";
import { useState } from "react";
function SaveActions({ onSave }: { onSave: () => void }) {
const close = useDrawerClose();
return (
<Stack direction="horizontal" space="space-100" justify="end">
<Button variant="subtle" onPress={() => close()}>
Cancel
</Button>
<Button
variant="primary"
onPress={() => {
onSave();
// The parent's `hasUnsavedChanges` has not re-rendered yet: skip the question.
close({ force: true });
}}
>
Save note
</Button>
</Stack>
);
}
export default function Example() {
const [saved, setSaved] = useState("Prefers delivery before noon.");
const [draft, setDraft] = useState(saved);
return (
<DialogTrigger onOpenChange={(isOpen) => isOpen && setDraft(saved)}>
<Button>Edit note</Button>
<Drawer
title="Customer note"
description="Ada Lovelace"
hasUnsavedChanges={draft !== saved}
footer={<SaveActions onSave={() => setSaved(draft)} />}
>
<TextArea label="Note" description="Change the text, then try to close." value={draft} onChange={setDraft} />
</Drawer>
</DialogTrigger>
);
}From any edge
`position`: start, end (default), top or bottom; the app decides, at every width.import { Button } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { SegmentedControl } from "@senvenli/react/navigation";
import { DialogTrigger, Drawer, type DrawerPosition } from "@senvenli/react/overlay";
import { useState } from "react";
// The edge is the app's choice, at every width: `start` and `end` mirror in right-to-left.
export default function Example() {
const [position, setPosition] = useState<DrawerPosition>("end");
return (
<Stack space="space-200" align="center">
<SegmentedControl
label="Position"
items={[
{ id: "start", label: "Start" },
{ id: "end", label: "End" },
{ id: "top", label: "Top" },
{ id: "bottom", label: "Bottom" },
]}
value={position}
onChange={(value) => setPosition(value as DrawerPosition)}
/>
<DialogTrigger>
<Button>Open the drawer</Button>
<Drawer position={position} title="Filters">
<Text>This drawer came in from the {position}.</Text>
</Drawer>
</DialogTrigger>
</Stack>
);
}From the bottom
`position="bottom"` is a sheet that snaps between half and full height.import { Button } from "@senvenli/react/action";
import { DialogTrigger, Drawer } from "@senvenli/react/overlay";
import { RadioGroup } from "@senvenli/react/selection";
export default function Example() {
return (
<DialogTrigger>
<Button iconBefore="arrow-up-down">Sort</Button>
<Drawer position="bottom" title="Sort orders">
<RadioGroup
label="Sort by"
defaultValue="newest"
items={[
{ value: "newest", label: "Newest first" },
{ value: "oldest", label: "Oldest first" },
{ value: "total", label: "Highest total" },
]}
/>
</Drawer>
</DialogTrigger>
);
}Guidelines
When to use it
- Viewing or editing a record while keeping the list in view.
Use something else when
- The task needs full attention. Dialog
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Esc | Closes, asking first when there are unsaved changes. |
Built in
- Unsaved changes ask before closing in a real nested modal.
- The bottom sheet has a grip to expand or close.
You provide
- A title.
API reference
Drawer
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | – | Open without a DialogTrigger (a URL, a row click). Inside a DialogTrigger, put |
defaultOpen | boolean | – | |
onOpenChange | (isOpen: boolean) => void | – | |
titleRequired | React.ReactNode | – | |
description | React.ReactNode | – | Under the title: "Jordan Lee · 14–18 Oct". When given, the drawer is described by it ( |
headerActions | React.ReactNode | – | Beside the close button: a status Badge, a menu. |
childrenRequired | React.ReactNode | – | |
footer | React.ReactNode | – | Sticky at the bottom: the record's actions. |
size | OverlaySize | – | small 380px, large 560px (medium reads as large). |
position | DrawerPosition | – | The edge it slides in from, at every width (the app decides, e.g. |
hasUnsavedChanges | boolean | – | Closing (button, Esc, scrim, useDrawerClose) asks first: "Unsaved changes". |
motion | ComponentMotion | – |
|
isOpenbooleanOpen without a DialogTrigger (a URL, a row click). Inside a DialogTrigger, put
onOpenChangeon the trigger instead: the trigger owns the state there.defaultOpenbooleanonOpenChange(isOpen: boolean) => voidtitleRequiredReact.ReactNodedescriptionReact.ReactNodeUnder the title: "Jordan Lee · 14–18 Oct". When given, the drawer is described by it (
aria-describedby); without it (or with"",false,null) nothing is rendered.headerActionsReact.ReactNodeBeside the close button: a status Badge, a menu.
childrenRequiredReact.ReactNodefooterReact.ReactNodeSticky at the bottom: the record's actions.
sizeOverlaySizesmall 380px, large 560px (medium reads as large).
positionDrawerPositionThe edge it slides in from, at every width (the app decides, e.g.
bottomon phones):end(default) andstartare the inline sides and mirror in right-to-left;bottomis a sheet that snaps between half and full height;topdrops down from above.hasUnsavedChangesbooleanClosing (button, Esc, scrim, useDrawerClose) asks first: "Unsaved changes".
motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.