Resizable Panel
Lets users resize two adjacent panes with a drag handle or keyboard, then stacks them in narrow containers.
pnpm dlx shadcn@latest add @haze/resizable-panel---
import { GripVertical } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
id: string;
label?: string;
startSize?: number;
class?: string;
}
const { id, label = "Resize panels", startSize = 42, class: className } = Astro.props;
const size = Number.isFinite(startSize) ? Math.round(Math.min(80, Math.max(20, startSize))) : 42;
---
<div data-haze-resizable-panel class={cn("@container overflow-hidden rounded-xl border border-border bg-card text-card-foreground", className)}>
<div data-split-grid style={`--haze-split: ${size / 100}`}
class="grid @sm:grid-cols-[minmax(0,calc((100%-24px)*var(--haze-split)))_24px_minmax(0,1fr)]">
<div id={`${id}-start`} class="min-w-0 px-3 py-3.5">
<slot name="start"><p class="text-[0.8125rem]/5">First panel</p></slot>
</div>
<div data-split-handle data-split-label={label} data-split-controls={`${id}-start`} data-split-size={size}
class="group relative hidden min-h-8 touch-none outline-none place-items-center select-none @sm:grid [[data-haze-resizable-panel][data-enhanced]_&]:cursor-col-resize">
<span aria-hidden="true" class="pointer-events-none absolute inset-y-0 left-1/2 w-px bg-border transition-colors duration-150 ease-snappy group-hover:bg-border-strong group-data-[dragging]:bg-border-strong"></span>
<span aria-hidden="true" class="pointer-events-none relative hidden h-8 w-4 place-items-center rounded-md border border-border bg-muted text-muted-foreground transition-[border-color,color] duration-150 ease-snappy group-hover:border-border-strong group-data-[dragging]:border-border-strong group-focus-visible:outline-2 group-focus-visible:outline-offset-1 group-focus-visible:outline-ring [[data-haze-resizable-panel][data-enhanced]_&]:grid">
<GripVertical aria-hidden="true" class="size-3.5" />
</span>
</div>
<div class="min-w-0 border-t border-border px-3 py-3.5 @sm:border-t-0">
<slot name="end"><p class="text-[0.8125rem]/5">Second panel</p></slot>
</div>
</div>
</div>
<script>
function enhance(root: HTMLElement) {
if (root.hasAttribute("data-enhanced")) return;
const grid = root.querySelector<HTMLElement>("[data-split-grid]");
const handle = root.querySelector<HTMLElement>("[data-split-handle]");
if (!grid || !handle) return;
const initial = Number(handle.dataset.splitSize);
const direction = () => getComputedStyle(grid).direction === "rtl" ? -1 : 1;
let size = initial;
let pointer: number | undefined;
let offset = 0;
const setSize = (value: number) => {
size = Math.round(Math.min(80, Math.max(20, value)));
grid.style.setProperty("--haze-split", String(size / 100));
handle.setAttribute("aria-valuenow", String(size));
handle.setAttribute("aria-valuetext", `${size}%`);
};
handle.addEventListener("keydown", (event) => {
const step = event.shiftKey ? 10 : 5;
const positions: Record<string, number | undefined> = {
ArrowLeft: size - step * direction(),
ArrowRight: size + step * direction(),
Home: 20,
End: 80,
};
const position = positions[event.key];
if (position === undefined) return;
event.preventDefault();
setSize(position);
});
handle.addEventListener("pointerdown", (event) => {
if (event.button !== 0 || pointer !== undefined) return;
const rect = handle.getBoundingClientRect();
pointer = event.pointerId;
offset = event.clientX - rect.left - rect.width / 2;
handle.setPointerCapture(pointer);
handle.setAttribute("data-dragging", "");
});
handle.addEventListener("pointermove", (event) => {
if (event.pointerId !== pointer) return;
const rect = grid.getBoundingClientRect();
const handleWidth = handle.offsetWidth;
const space = rect.width - handleWidth;
if (space <= 0) return;
const center = event.clientX - offset;
const fromStart = direction() === 1 ? center - rect.left : rect.right - center;
setSize((fromStart - handleWidth / 2) / space * 100);
});
handle.addEventListener("lostpointercapture", () => {
pointer = undefined;
handle.removeAttribute("data-dragging");
});
handle.addEventListener("dblclick", () => setSize(initial));
handle.setAttribute("role", "separator");
handle.setAttribute("aria-orientation", "vertical");
handle.setAttribute("aria-label", handle.dataset.splitLabel ?? "Resize panels");
handle.setAttribute("aria-controls", handle.dataset.splitControls ?? "");
handle.setAttribute("aria-valuemin", "20");
handle.setAttribute("aria-valuemax", "80");
handle.tabIndex = 0;
setSize(initial);
root.setAttribute("data-enhanced", "");
}
const init = () => document.querySelectorAll<HTMLElement>("[data-haze-resizable-panel]").forEach(enhance);
init();
if (!document.documentElement.hasAttribute("data-haze-resizable-panel-listener")) {
document.documentElement.setAttribute("data-haze-resizable-panel-listener", "");
document.addEventListener("astro:page-load", init);
}
</script>When to use
- Two panes share space, such as files and an editor.
- The desired reading width varies by task or document.
When not to use
- One panel can expand without competing with another panel for space.
Installation
Add the Haze registry to components.json once, then install Resizable Panel with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/resizable-panelnpx shadcn@latest add @haze/resizable-panelyarn dlx shadcn@latest add @haze/resizable-panelbunx --bun shadcn@latest add @haze/resizable-panelFirst 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 | – | ID prefix for the pane linked to the resize handle. |
| label | string | Resize panels | Accessible name for the separator. |
| startSize | number | 42 | Initial percent assigned to the first pane. |
| class | string | – | Classes for the container. |
Keyboard interactions
- ←→
- Resize by five percentage points. Add Shift to resize by ten.
- HomeEnd
- Move to the minimum or maximum width.
Accessibility
- The separator announces the current size as a percentage.
- On narrow screens the panes stack in reading order.
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 "Resizable Panel" with `npx shadcn@latest add @haze/resizable-panel`. 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 ResizablePanel from "@/components/haze/ui/resizable-panel.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/resizable-panel.md
Customize with real content
Adapt the Haze resizable-panel ui for our product. Replace the demo values of these props with our real content: id, label, startSize, class. Keep the layout, the heading level rules and these accessibility details: The separator announces the current size as a percentage. On narrow screens the panes stack in reading order. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using resizable-panel, check it fits: use it when two panes share space, such as files and an editor.; the desired reading width varies by task or document.. Avoid it when one panel can expand without competing with another panel for space.. Alternatives: @haze/card, @haze/scroll-area, @haze/tabs.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.