# Resize grip

An interactive window splitter in a reserved gutter with a centred fluid grip, keyboard stepping, and zero deformation under reduced motion.

Live variants: https://design.arcadia.is/components/resize-grip

```tsx
import {
  ResizeGrip, ResizeGripGlyph, trackResizeGrip, computeResizeGripFrame,
} from "@arcadia/ui";
```

```tsx
import { useState, useLayoutEffect, useRef } from "react";
import { ResizeGrip } from "@arcadia/ui";

function VerticalSplit() {
  const [preferredWidth, setWidth] = useState(SIDEBAR_START);
  const [max, setMax] = useState(SIDEBAR_MAX);
  const width = Math.min(preferredWidth, max);
  const split = useRef<HTMLDivElement>(null);
  const grip = useRef<HTMLDivElement>(null);
  const startWidth = useRef(SIDEBAR_START);

  useLayoutEffect(() => {
    const frame = split.current, handle = grip.current;
    if (!frame || !handle) return;
    const watch = new ResizeObserver(([entry]) => {
      if (!entry || entry.contentRect.width === 0) return;
      const minPane = 2 * Number.parseFloat(getComputedStyle(frame).getPropertyValue("--space-16"));
      const limit = clamp(Math.floor(entry.contentRect.width - handle.offsetWidth - minPane), SIDEBAR_MIN, SIDEBAR_MAX);
      setMax(limit);
    });
    watch.observe(frame);
    return () => watch.disconnect();
  }, []);

  return (
    <div ref={split} {...sx("cmp-resize-split", ResizeGripStyles.split)}>
      <div {...sx("cmp-resize-sidebar", ResizeGripStyles.sidebar)} style={{ width }}>
        <span {...sx(null, ResizeGripStyles.label)}>Projects</span>
        <span {...sx(null, ResizeGripStyles.item)}>Atlas</span>
        <span {...sx(null, ResizeGripStyles.item)}>Beacon</span>
        <span {...sx(null, ResizeGripStyles.value)}>{width}px</span>
      </div>
      <ResizeGrip
        ref={grip}
        label="Resize sidebar"
        value={width}
        min={SIDEBAR_MIN}
        max={max}
        valueText={`${width} pixels`}
        onDragStart={() => { startWidth.current = width; }}
        onDragMove={({ total }) => setWidth(clamp(Math.round(startWidth.current + total), SIDEBAR_MIN, max))}
        onDragCancel={() => setWidth(startWidth.current)}
        onStep={(delta) => setWidth(clamp(width + delta, SIDEBAR_MIN, max))}
        onJump={(edge) => setWidth(edge === "min" ? SIDEBAR_MIN : max)}
        onReset={() => setWidth(Math.min(SIDEBAR_START, max))}
      />
      <div {...sx("cmp-resize-pane", ResizeGripStyles.pane)}>
        <span {...sx(null, ResizeGripStyles.label)}>Workspace</span>
        <span {...sx(null, ResizeGripStyles.item)}>Release checklist</span>
      </div>
    </div>
  );
}
```

## API reference

### ResizeGrip

- `label` (`string`, required)
- `orientation` (`ResizeGripOrientation`, default `"vertical"`)
- `value` (`number`)
- `min` (`number`)
- `max` (`number`)
- `valueText` (`string`)
- `step` (`number`, default `16`)
- `largeStep` (`number`, default `step * 3`)
- `disabled` (`boolean`, default `false`)
- `active` (`boolean`)
- `onDragStart` (`(start: ResizeGripDragStart) => void`)
- `onDragMove` (`(drag: ResizeGripDragEvent) => void`)
- `onDragEnd` (`(drag: ResizeGripDragEvent) => void`)
- `onDragCancel` (`() => void`)
- `onStep` (`(delta: number, event: ReactKeyboardEvent<HTMLDivElement>) => void`)
- `onJump` (`(edge: "min" | "max", event: ReactKeyboardEvent<HTMLDivElement>) => void`)
- `onReset` (`() => void`)
- `rootStyle` (`RootStyle<ResizeGripKnobs>`)

Rest props go to `<div>` props.
