Components
Drawer
A panel that slides in from the left or right for editing alongside the page.
pnpm dlx shadcn@latest add @caliper/drawerWhen to use
Use it for
- Editing a record while keeping the list visible behind it.
- Navigation on small screens.
Skip it when
- A one-line confirmation; use a dialog.
- Phones where a bottom sheet is more natural.
Installation
pnpm dlx shadcn@latest add @caliper/drawer
Adds its 4 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage
This is the code behind the preview above. It is built from Drawer, DrawerTrigger, DrawerClose, DrawerContent, DrawerTitle, DrawerDescription, DrawerHeader and DrawerFooter.
import { useState, type ReactNode } from "react" import { AvatarGroup } from "@/components/ui/avatar-group" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { SegmentedControl } from "@/components/ui/segmented-control" import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger } from "@/components/ui/drawer" import { Field } from "@/components/ui/field" import { Input } from "@/components/ui/input" import { cn } from "@/components/ui/lib/cn" function Panel({ title, context, media, action, className, children }: { title: string; context: string; media?: ReactNode; action?: ReactNode; className?: string; children?: ReactNode }) { return ( <section className={cn("grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}> <div className="flex items-center gap-3"> {media} <div className="grid min-w-0 flex-1 gap-1"> <p className="font-medium">{title}</p> <p className="text-sm text-muted-foreground">{context}</p> </div> {action} </div> {children} </section> ); } const visibilityLabel: Record<string, string> = { private: "Private", team: "Design team", workspace: "Workspace" }; export function EditDrawer() { const [project, setProject] = useState({ name: "Harbour redesign", visibility: "team" }); const [name, setName] = useState(project.name); const [visibility, setVisibility] = useState(project.visibility); return ( <Panel title={project.name} context="Booking flow and room pages · updated today by Mara Chen"> <div className="flex items-center justify-between gap-3"> <AvatarGroup label="Project team" max={3} members={[{ name: "Mara Chen" }, { name: "Noor Haddad" }, { name: "Ivo Petrov" }, { name: "Sana Okafor" }]} /> <Badge tone={project.visibility === "private" ? "slate" : project.visibility === "team" ? "violet" : "teal"}>{visibilityLabel[project.visibility]}</Badge> </div> <Drawer onOpenChange={(open) => { if (open) { setName(project.name); setVisibility(project.visibility); } }}> <DrawerTrigger asChild> <Button variant="secondary" className="justify-self-start">Edit project</Button> </DrawerTrigger> <DrawerContent> <DrawerHeader> <DrawerTitle>Edit project</DrawerTitle> <DrawerDescription>Rename it or change who can see it.</DrawerDescription> </DrawerHeader> <div className="grid gap-5 py-2"> <Field label="Name"> {(control) => <Input {...control} value={name} onChange={(event) => setName(event.currentTarget.value)} />} </Field> <div className="grid gap-1.5"> {/* The group is named by its own label; this line is the visible heading for it. */} <span aria-hidden="true" className="text-sm font-medium">Visibility</span> <SegmentedControl label="Visibility" value={visibility} onValueChange={setVisibility} options={[{ value: "private", label: "Private" }, { value: "team", label: "Team" }, { value: "workspace", label: "Workspace" }]} /> <p className="text-sm text-muted-foreground">{visibility === "team" ? "Everyone on the Design team can open it." : visibility === "private" ? "Only you and people you invite." : "Anyone in Halden can find it."}</p> </div> </div> <DrawerFooter> <DrawerClose asChild><Button variant="ghost">Cancel</Button></DrawerClose> <DrawerClose asChild><Button onClick={() => setProject({ name: name.trim() || project.name, visibility })}>Save changes</Button></DrawerClose> </DrawerFooter> </DrawerContent> </Drawer> </Panel> ); }
API reference
Drawer
component
No props of its own; it accepts the native props of its root element.
DrawerTrigger
component
No props of its own; it accepts the native props of its root element.
DrawerClose
component
No props of its own; it accepts the native props of its root element.
DrawerContent
component
Also accepts the native props of its root element and a ref.
DrawerTitle
component
No props of its own; it accepts the native props of its root element.
DrawerDescription
component
No props of its own; it accepts the native props of its root element.
DrawerHeader
component
No props of its own; it accepts the native props of its root element.
Accessibility
It is built on native elements, so roles and focus come from the browser.
Keyboard and focus handling comes from Radix dialog: arrow keys move through items, Enter and Space select, and Escape closes and returns focus.
Motion
It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.