Smooth drawer
Centered bottom sheet built on native dialog with a drag handle, optional price badge header, snap heights and drag-to-dismiss.
pnpm dlx shadcn@latest add @haze/smooth-drawer---
import { ChevronUp, X } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
/** Unique on the page. Buttons with `command="show-modal" commandfor="<id>"` open this sheet. */
id: string;
title?: string;
description?: string;
/** Optional formatted price displayed as a tabular-nums badge in the header (e.g. "$149.00"). */
price?: string;
/** Optional micro-label beneath the price badge (e.g. "One-time" or "/ year"). */
priceLabel?: string;
/** Optional eyebrow badge rendered above the sheet title. */
badge?: string;
/** Starting height of the bottom sheet. */
initialSnap?: "half" | "full";
/** Set to false when the opening trigger lives elsewhere on the page. */
trigger?: boolean;
/** Visible text for the built-in trigger button. Replaced by the "trigger" slot. */
triggerLabel?: string;
triggerVariant?: "primary" | "secondary" | "outline" | "ghost";
/** Accessible name of the close button. */
closeLabel?: string;
/** Accessible name of the snap-height toggle button. */
snapLabel?: string;
class?: string;
}
const {
id,
title = "Studio Annual Pass",
description = "Review your plan details before confirming.",
price,
priceLabel,
badge,
initialSnap = "half",
trigger = true,
triggerLabel = "Open sheet",
triggerVariant = "outline",
closeLabel = "Close",
snapLabel = "Toggle sheet height",
class: className,
} = Astro.props;
const triggerVariants = {
primary: "border border-primary bg-primary text-primary-foreground shadow-key hover:opacity-90",
secondary: "border border-frame bg-secondary text-secondary-foreground shadow-key hover:bg-accent",
outline: "border border-border bg-field text-foreground shadow-key hover:border-border-strong hover:bg-accent",
ghost: "border border-transparent bg-transparent text-muted-foreground hover:bg-accent hover:text-foreground",
};
---
{
trigger && (
<button
type="button"
command="show-modal"
commandfor={id}
aria-haspopup="dialog"
class={cn(
"inline-flex cursor-pointer items-center justify-center gap-2 rounded-lg h-10 px-4 text-[0.8125rem]/5 font-medium whitespace-nowrap select-none transition-[background-color,border-color,color,box-shadow,opacity,scale] duration-150 ease-snappy active:scale-[0.98] motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring",
triggerVariants[triggerVariant],
)}
>
<slot name="trigger">{triggerLabel}</slot>
</button>
)
}
<dialog
id={id}
data-haze-smooth-drawer
data-snap={initialSnap}
data-initial-snap={initialSnap}
aria-labelledby={`${id}-title`}
aria-describedby={description ? `${id}-description` : undefined}
closedby="any"
class={cn(
"mx-auto mb-0 mt-auto max-h-[88dvh] w-full max-w-md rounded-t-2xl border border-b-0 border-border bg-popover p-0 text-popover-foreground shadow-float",
"data-[snap=full]:h-[86dvh]",
"translate-y-full transition-[translate,height,overlay,display] transition-discrete duration-300 ease-spring open:translate-y-0 starting:open:translate-y-full data-[dragging]:transition-none motion-reduce:transition-none",
"backdrop:bg-background/60 backdrop:opacity-0 backdrop:transition-[opacity,overlay,display] backdrop:transition-discrete backdrop:duration-300 open:backdrop:opacity-100 starting:open:backdrop:opacity-0 motion-reduce:backdrop:transition-none",
className,
)}
>
<div class="relative flex h-full max-h-[inherit] flex-col">
<div class="relative flex shrink-0 items-center justify-center px-5 pt-3 pb-1.5">
<div
data-sd-handle
class="flex w-32 cursor-grab touch-none items-center justify-center py-1.5 active:cursor-grabbing"
>
<span aria-hidden="true" class="h-1 w-10 rounded-full bg-border-strong"></span>
</div>
<div class="absolute top-2.5 right-3.5 flex items-center gap-1">
<button
type="button"
data-sd-snap
aria-label={snapLabel}
aria-pressed={initialSnap === "full" ? "true" : "false"}
class="hidden size-7 cursor-pointer items-center justify-center rounded-lg border border-transparent text-muted-foreground transition-[background-color,color,scale] duration-150 ease-snappy hover:border-frame hover:bg-accent hover:text-foreground active:scale-95 motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring [[data-haze-smooth-drawer][data-enhanced]_&]:inline-flex"
>
<ChevronUp class="size-3.5 transition-[rotate] duration-200 ease-snappy [[data-snap=full]_&]:rotate-180 motion-reduce:transition-none" aria-hidden="true" />
</button>
<form method="dialog">
<button
type="submit"
aria-label={closeLabel}
class="inline-flex size-7 cursor-pointer items-center justify-center rounded-lg border border-transparent text-muted-foreground transition-[background-color,color,scale] duration-150 ease-snappy hover:border-frame hover:bg-accent hover:text-foreground active:scale-95 motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
>
<X class="size-3.5" aria-hidden="true" />
</button>
</form>
</div>
</div>
<header class="flex items-start justify-between gap-3 border-b border-border px-5 pt-1.5 pb-4">
<div class="grid min-w-0 gap-1">
{
badge && (
<span class="inline-flex w-fit items-center rounded-md border border-frame bg-muted px-2 py-0.5 text-[0.6875rem]/4 font-medium text-foreground">
{badge}
</span>
)
}
<h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-[-0.015em] text-foreground">{title}</h2>
{description && <p id={`${id}-description`} class="text-[0.8125rem]/5 text-muted-foreground">{description}</p>}
</div>
{
price && (
<div class="grid shrink-0 justify-items-end rounded-lg border border-border bg-card px-2.5 py-1.5 shadow-key">
<span class="text-sm/5 font-semibold tabular-nums text-foreground">{price}</span>
{priceLabel && <span class="text-[0.6875rem]/3.5 text-muted-foreground">{priceLabel}</span>}
</div>
)
}
</header>
<div class="min-h-0 flex-1 overflow-y-auto px-5 py-4 text-[0.8125rem]/5">
<slot>
<p class="text-muted-foreground">Place order items, plan breakdowns or controls inside the default slot.</p>
</slot>
</div>
{
Astro.slots.has("footer") && (
<footer class="flex shrink-0 flex-col gap-2 border-t border-border px-5 py-4">
<slot name="footer" />
</footer>
)
}
</div>
</dialog>
<script>
const docRoot = document.documentElement;
if (!docRoot.hasAttribute("data-haze-invokers")) {
docRoot.setAttribute("data-haze-invokers", "");
if (!("command" in HTMLButtonElement.prototype)) {
document.addEventListener("click", (event) => {
const button = (event.target as Element | null)?.closest?.("button[commandfor]");
const target = button && document.getElementById(button.getAttribute("commandfor") ?? "");
if (!(target instanceof HTMLDialogElement)) return;
const command = button!.getAttribute("command");
if (command === "show-modal" && !target.open) target.showModal();
if (command === "close" && target.open) target.close();
});
}
if (!("closedBy" in HTMLDialogElement.prototype)) {
document.addEventListener("click", (event) => {
const dialog = event.target;
if (dialog instanceof HTMLDialogElement && dialog.open && dialog.getAttribute("closedby") === "any") dialog.close();
});
}
}
function enhanceSmoothDrawer(dialog: HTMLDialogElement) {
if (dialog.hasAttribute("data-enhanced")) return;
const handle = dialog.querySelector<HTMLElement>("[data-sd-handle]");
const snapBtn = dialog.querySelector<HTMLButtonElement>("[data-sd-snap]");
if (!handle) return;
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");
const setSnap = (next: "half" | "full") => {
dialog.dataset.snap = next;
snapBtn?.setAttribute("aria-pressed", String(next === "full"));
dialog.dispatchEvent(new CustomEvent("haze:smooth-drawer-snap", { detail: { snap: next }, bubbles: true }));
};
snapBtn?.addEventListener("click", () => {
setSnap(dialog.dataset.snap === "full" ? "half" : "full");
});
let activePointer = -1;
let startY = 0;
let startTime = 0;
let currentDy = 0;
handle.addEventListener("pointerdown", (event) => {
if (event.button !== 0 || !dialog.open) return;
activePointer = event.pointerId;
startY = event.clientY;
startTime = performance.now();
currentDy = 0;
handle.setPointerCapture(event.pointerId);
dialog.setAttribute("data-dragging", "");
});
handle.addEventListener("pointermove", (event) => {
if (event.pointerId !== activePointer) return;
currentDy = event.clientY - startY;
if (reduced.matches) return;
const offset = currentDy >= 0 ? currentDy : currentDy * 0.22;
dialog.style.translate = `0 ${Math.round(offset)}px`;
});
const finishDrag = (event: PointerEvent, cancelled: boolean) => {
if (event.pointerId !== activePointer) return;
activePointer = -1;
if (handle.hasPointerCapture(event.pointerId)) {
handle.releasePointerCapture(event.pointerId);
}
dialog.removeAttribute("data-dragging");
const elapsed = Math.max(1, performance.now() - startTime);
const velocity = currentDy / elapsed;
dialog.style.translate = "";
if (cancelled) return;
const isFull = dialog.dataset.snap === "full";
if (currentDy > 110 || velocity > 0.55) {
if (isFull && currentDy < 220 && velocity < 0.9) {
setSnap("half");
} else {
dialog.close();
}
} else if (currentDy < -60 || velocity < -0.45) {
setSnap("full");
}
};
handle.addEventListener("pointerup", (event) => finishDrag(event, false));
handle.addEventListener("pointercancel", (event) => finishDrag(event, true));
dialog.addEventListener("close", () => {
activePointer = -1;
dialog.removeAttribute("data-dragging");
dialog.style.translate = "";
const initial = dialog.dataset.initialSnap === "full" ? "full" : "half";
setSnap(initial);
});
dialog.setAttribute("data-enhanced", "");
}
const initSmoothDrawers = () => {
document.querySelectorAll<HTMLDialogElement>("[data-haze-smooth-drawer]").forEach(enhanceSmoothDrawer);
};
initSmoothDrawers();
if (!docRoot.hasAttribute("data-haze-smooth-drawer-listener")) {
docRoot.setAttribute("data-haze-smooth-drawer-listener", "");
document.addEventListener("astro:page-load", initSmoothDrawers);
}
</script>When to use
- Checkout reviews, plan confirmations or quick navigation need a refined bottom sheet modal
- Touch and pointer users benefit from dragging a sculpted grab handle to expand or dismiss a sheet
- A modal overlay requires native focus trapping, Escape dismissal and a backdrop without extra libraries
When not to use
- Content should dock to the left or right screen edge; use drawer
- A compact centered confirmation modal is needed; use dialog
Installation
Add the Haze registry to components.json once, then install Smooth drawer with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/smooth-drawernpx shadcn@latest add @haze/smooth-draweryarn dlx shadcn@latest add @haze/smooth-drawerbunx --bun shadcn@latest add @haze/smooth-drawerFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique dialog ID targeted by commandfor on opening or closing buttons. |
| title | string | "Studio Annual Pass" | Heading text used as the accessible name of the modal dialog. |
| description | string | "Review your plan details before confirming." | Optional subtitle linked via aria-describedby. |
| price | string | – | Optional formatted price rendered in a tabular-nums badge beside the title. |
| priceLabel | string | – | Optional micro-label rendered beneath the price badge. |
| badge | string | – | Optional eyebrow pill displayed above the sheet heading. |
| initialSnap | "half" | "full" | "half" | Starting snap height when the bottom sheet opens. |
| trigger | boolean | true | Render the built-in opening button; set false when triggering externally. |
| triggerLabel | string | "Open sheet" | Label of the built-in trigger button when the trigger slot is empty. |
| triggerVariant | "primary" | "secondary" | "outline" | "ghost" | "outline" | Visual variant of the built-in trigger button. |
| closeLabel | string | "Close" | Accessible name for the explicit close button. |
| snapLabel | string | "Toggle sheet height" | Accessible name for the keyboard-accessible snap height toggle button. |
| class | string | – | Extra classes applied to the dialog panel. |
Keyboard interactions
- EnterSpace
- Open the sheet from the trigger or toggle half/full snap height
- TabShiftTab
- Cycle focus through interactive elements inside the open sheet
- Escape
- Dismiss the bottom sheet and return focus to the trigger
Accessibility
- Built on a native modal <dialog> with command/commandfor and closedby="any", trapping focus and handling Escape natively.
- Includes both an explicit Close button inside <form method="dialog"> and a keyboard-operable snap height button alongside drag gestures.
- Honors prefers-reduced-motion by disabling spring transitions and live drag translation.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Smooth drawer" with `npx shadcn@latest add @haze/smooth-drawer`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import SmoothDrawer from "@/components/haze/ui/smooth-drawer.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/smooth-drawer.md
Customize with real content
Adapt the Haze smooth-drawer ui for our product. Replace the demo values of these props with our real content: id, title, description, price, priceLabel, badge, initialSnap, trigger, triggerLabel, triggerVariant, closeLabel, snapLabel, class. Keep the layout, the heading level rules and these accessibility details: Built on a native modal <dialog> with command/commandfor and closedby="any", trapping focus and handling Escape natively. Includes both an explicit Close button inside <form method="dialog"> and a keyboard-operable snap height button alongside drag gestures. Honors prefers-reduced-motion by disabling spring transitions and live drag translation. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using smooth-drawer, check it fits: use it when checkout reviews, plan confirmations or quick navigation need a refined bottom sheet modal; touch and pointer users benefit from dragging a sculpted grab handle to expand or dismiss a sheet; a modal overlay requires native focus trapping, escape dismissal and a backdrop without extra libraries. Avoid it when content should dock to the left or right screen edge; use drawer; a compact centered confirmation modal is needed; use dialog. Alternatives: @haze/drawer, @haze/dialog.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.