Drawer
A panel that slides in from an edge for secondary tasks, details or navigation.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native <dialog>
- 8 parts, named exports
- role="dialog" named by the title.
- Focus is trapped while open and returns to the trigger on close.
- Escape and the overlay close it.
- Styles in one file:
dialog.css
Import
import '@monoline/css';
import {Drawer} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add drawer
Usage
import {Button, Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle, DrawerTrigger} from '@monoline/react';
<div style={{display: 'flex', gap: 'var(--s3)'}}>
{(['right', 'left'] as const).map((side) => (
<Drawer key={side}>
<DrawerTrigger asChild><Button variant="line">Open {side}</Button></DrawerTrigger>
<DrawerContent side={side}><DrawerHeader><DrawerTitle>Filters</DrawerTitle><DrawerDescription>Narrow the list by status or owner.</DrawerDescription></DrawerHeader></DrawerContent>
</Drawer>
))}
</div>
Anatomy
Import the parts you need and nest them like this.
import {Drawer, DrawerTrigger, DrawerClose, DrawerContent, DrawerHeader, DrawerFooter, DrawerTitle, DrawerDescription} from '@monoline/react';
<Drawer>
<DrawerTrigger />
<DrawerClose />
<DrawerContent />
<DrawerHeader />
<DrawerFooter />
<DrawerTitle />
<DrawerDescription />
</Drawer>
Examples
Right and left
Props
DrawerContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
side | "start" | "top" | "right" | "bottom" | "left" | "end" | 'right' | The edge it slides from. `start` and `end` follow the reading direction; `left` and `right` are fixed. |
showClose | boolean | true | Shows a "Close" text button. Escape and the backdrop always close it. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[data-side="bottom"] | drawer.css |
[data-side="end"] | drawer.css |
[data-side="left"] | drawer.css |
[data-side="right"] | drawer.css |
[data-side="start"] | drawer.css |
[data-side="top"] | drawer.css |
CSS classes
| Class | Stylesheet |
|---|---|
.command | dialog.css |
.dialog-close | dialog.css |
.dialog-content | dialog.css |
.dialog-description | dialog.css |
.dialog-footer | dialog.css |
.dialog-header | dialog.css |
.dialog-overlay | dialog.css |
.dialog-title | dialog.css |
.drawer-content | dialog.css |
.drawer-content | drawer.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.command {
border-color: var(--accent);
}
.command[data-side="bottom"] {
background: var(--wash);
}
Accessibility
- role="dialog" named by the title.
- Focus is trapped while open and returns to the trigger on close.
- Escape and the overlay close it.