Drawer
A panel that comes from an edge of the screen and can be dragged: side is "bottom" (the default), "top", "left", "right", or "start" and "end", which follow the reading direction. snapPoints are the places it can rest (0.5 for half the screen, "20rem", "content"). modal={false} leaves the page usable beside it. Swipe it away, or press Escape.
Preview
Use
import {
Drawer,
DrawerBody,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
ItemText,
List,
ListItem,
buttonClass,
toast,
} from '@/components/ui';
<Drawer>
<DrawerTrigger className={buttonClass()}>Open order</DrawerTrigger>
<DrawerContent handle="grip">
<DrawerHeader>
<DrawerTitle>Order <span className="ui-mono">#1188</span></DrawerTitle>
<DrawerDescription>Otis Brandt, paid on 26 November</DrawerDescription>
</DrawerHeader>
<DrawerBody>
<List>
<ListItem><ItemText className="ui-grow" title="Linen tote" note="Natural" /><span className="ui-mono">£24.00</span></ListItem>
<ListItem><ItemText className="ui-grow" title="Enamel mug" note="Two" /><span className="ui-mono">£28.00</span></ListItem>
</List>
</DrawerBody>
<DrawerFooter>
<DrawerClose className={buttonClass({ variant: 'ghost' })}>Close</DrawerClose>
<DrawerClose className={buttonClass({ variant: 'primary' })} afterClose={() => toast.success({ title: 'Order #1188 marked as sent' })}>Mark as sent</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>Options
No options of its own.
It also takes the 26 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.
Parts
What goes inside one.
Without React
With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:
components/card.csscomponents/tabs.csscomponents/dialog.csscomponents/tab-bar.csscomponents/prose.csscomponents/site-header.csscomponents/page-transitions.cssparts/carousel.cssparts/drawer.cssparts/board.cssIn the examples
Small screens made with it and the rest of the kit. They work: click, type and choose in them.
- Noor Haddad#1187
- Otis Brandt#1188
- Yuki Tanabe#1189
On top of the page: states, do and don’t
A panel from an edge that the person drags: swipe it away, or rest it at several heights (snapPoints={[0.5, 0.9]} with handle="button"). side is bottom, top, left, right. Use it where the panel is moved by hand, above all on a phone; for a plain side panel the dialog's drawer is enough.
States. Closed, opening (fades and rises), open, closing (fades before what it changed appears: afterClose). While open, focus is inside and Escape closes it; when it closes, focus goes back to what opened it.
Do
- Name every dialog, drawer and popover (
DialogTitle,DrawerTitle, oraria-label). - Use
AlertDialogfor anything that cannot be undone, with the action named on its button ("Delete 3 files"). - Use a
Draweron a phone for what aPopoverdoes on a computer.
Don't
- Don't open a dialog from a dialog; change what the open one shows instead.
- Don't put the only way to do something in a right-click menu or a tooltip.
- Don't use a toast for something the person must not miss: that is an
Alerton the page.