Components / Overlays

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.

Drawer · PlaygroundLive
placement
JSX
<DialogTrigger>
  <Button>Open drawer</Button>
  <Drawer title="Notifications">You're all caught up.</Drawer>
</DialogTrigger>

Usage

TSX
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.

Drawer · FiltersLive
Showing: All projects
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.

Drawer · Bottom sheetLive
TSX
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.
  • Esc and clicking outside close it. Turn those off with isKeyboardDismissDisabled and isDismissable={false}.
  • title names the drawer; without one, pass aria-label.

API

Use it inside a DialogTrigger, or control it with isOpen.

PropTypeDefaultDescription
titleReactNode—Heading, also the drawer's accessible name.
descriptionReactNode—Text under the title, linked to the drawer as its description.
footerRenderSlot—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.
isDismissablebooleantrueClose when clicking outside.
hideClosebooleanfalseHides the close box.
closeLabelstring"Close"Accessible name of the close box.
aria-labelstring—Accessible name. Required when there's no title.
classNamestring—Extra classes for the panel.
isOpenboolean—Controlled open state. Use with onOpenChange.
defaultOpenboolean—Open on first render, when uncontrolled.
onOpenChange(isOpen: boolean) => void—Called with true or false when it opens or closes.
isKeyboardDismissDisabledbooleanfalseStops Esc from closing it.