Drawer12
A panel that slides in from an edge, for filters, settings and details next to the page. It springs in and overshoots a little in Sticker, without ever showing a gap at the edge.
<DialogTrigger>
<Button>Open drawer</Button>
<Drawer title="Notifications">You're all caught up.</Drawer>
</DialogTrigger>Usage
import { Button, DialogTrigger, Drawer } from "plonk-ui";
export function Notifications() {
return (
<DialogTrigger>
<Button>Notifications</Button>
<Drawer title="Notifications">…</Drawer>
</DialogTrigger>
);
}A drawer is a Dialog on the edge: the same
DialogTrigger, the same title, description, footer and close, and the
same focus behavior.
Filters
A form inside a drawer. Children as a function get close, so the drawer can
close after the form is applied.
import { useState } from "react";
import {
Button,
DialogTrigger,
Drawer,
Input,
Radio,
RadioGroup,
Switch,
} from "plonk-ui";
export default function Filters() {
const [applied, setApplied] = useState("All projects");
function apply(data: FormData) {
const status = String(data.get("status"));
const mine = data.get("mine") === "on";
setApplied(`${status}${mine ? ", mine only" : ""}`);
}
return (
<div className="flex flex-col items-center gap-3">
<DialogTrigger>
<Button variant="neutral">Filters</Button>
<Drawer title="Filters" description="Narrow down the project list.">
{({ close }) => (
<form
action={(data) => {
apply(data);
close();
}}
className="flex flex-col gap-5"
>
<Input label="Search" name="query" placeholder="Project name" />
<RadioGroup
label="Status"
name="status"
defaultValue="All projects"
>
<Radio value="All projects" label="All" />
<Radio value="Active" label="Active" />
<Radio value="Archived" label="Archived" />
</RadioGroup>
<Switch name="mine" label="Only mine" />
<Button type="submit" className="self-start">
Apply
</Button>
</form>
)}
</Drawer>
</DialogTrigger>
<span className="font-bold">Showing: {applied}</span>
</div>
);
}Bottom sheet
placement="bottom" slides up from the bottom, which is where thumbs are on a
phone. It's as tall as its content, up to 85% of the screen.
import { Button, DialogTrigger, Drawer } from "plonk-ui";
const TARGETS = ["Copy link", "Email", "Slack", "Download PDF"];
export default function Bottom() {
return (
<DialogTrigger>
<Button>Share</Button>
<Drawer placement="bottom" title="Share “Spring launch”">
{({ close }) => (
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
{TARGETS.map((target) => (
<Button key={target} variant="neutral" onPress={close}>
{target}
</Button>
))}
</div>
)}
</Drawer>
</DialogTrigger>
);
}Personalities
Sticker springs the panel in with a small overshoot; the panel is drawn wider than it looks, so the overshoot never opens a gap at the edge. Retro slides it in steps and frames it as a window. Comic and Arcade bring their dialog backdrops along: dark halftone and scanlines. With reduced motion, the panel slides in short and plain.
Accessibility
- Focus moves into the drawer, stays inside while it's open, and returns to the trigger when it closes.
Escand clicking outside close it. Turn those off withisKeyboardDismissDisabledandisDismissable={false}.titlenames the drawer; without one, passaria-label.
API
Use it inside a DialogTrigger, or
control it with isOpen.
| Prop | Type | Default | Description |
|---|---|---|---|
title | ReactNode | — | Heading, also the drawer's accessible name. |
description | ReactNode | — | Text under the title, linked to the drawer as its description. |
footer | RenderSlot | — | Bottom row, pinned under the scrolling content. Pass a function to get close. |
placement | "left" | "right" | "bottom" | "right" | Edge it slides in from. bottom works well as a sheet on phones. |
isDismissable | boolean | true | Close when clicking outside. |
hideClose | boolean | false | Hides the close box. |
closeLabel | string | "Close" | Accessible name of the close box. |
aria-label | string | — | Accessible name. Required when there's no title. |
className | string | — | Extra classes for the panel. |
isOpen | boolean | — | Controlled open state. Use with onOpenChange. |
defaultOpen | boolean | — | Open on first render, when uncontrolled. |
onOpenChange | (isOpen: boolean) => void | — | Called with true or false when it opens or closes. |
isKeyboardDismissDisabled | boolean | false | Stops Esc from closing it. |