Playground

Drawer

A panel that slides in from an edge for secondary tasks, details or navigation.

  • 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

PropTypeDefaultDescription
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.
showClosebooleantrueShows 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.

AttributeStylesheet
[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

ClassStylesheet
.commanddialog.css
.dialog-closedialog.css
.dialog-contentdialog.css
.dialog-descriptiondialog.css
.dialog-footerdialog.css
.dialog-headerdialog.css
.dialog-overlaydialog.css
.dialog-titledialog.css
.drawer-contentdialog.css
.drawer-contentdrawer.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.