# Resizable Panel

> Lets users resize two adjacent panes with a drag handle or keyboard, then stacks them in narrow containers.

- Kind: ui · Category: Layout and media · Interactivity: script
- Install: `npx shadcn@latest add @haze/resizable-panel`
- File: `src/components/haze/ui/resizable-panel.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/resizable-panel

## Use when
- Two panes share space, such as files and an editor.
- The desired reading width varies by task or document.

## Avoid when
- One panel can expand without competing with another panel for space.

## Alternatives
- [card](https://hazeui.com/ui/card.md)
- [scroll-area](https://hazeui.com/ui/scroll-area.md)
- [tabs](https://hazeui.com/ui/tabs.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | ID prefix for the pane linked to the resize handle. |
| label | `string` | Resize panels | no | Accessible name for the separator. |
| startSize | `number` | 42 | no | Initial percent assigned to the first pane. |
| class | `string` |  | no | Classes for the container. |

## Accessibility
- The separator announces the current size as a percentage.
- On narrow screens the panes stack in reading order.
- Key ← / →: Resize by five percentage points. Add Shift to resize by ten.
- Key Home / End: Move to the minimum or maximum width.

## Agent prompts

### 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": "https://hazeui.com/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: https://hazeui.com/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.

## Example requests that should lead here
- Build an editor with a resizable notes pane.
- Add a keyboard-operable split view for a list and its details.

## Source

```astro
---
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>
```
