ResizeHandle

import { ResizeHandle } from "@surfaces-ui/components";

A handle on the right or bottom edge of something, dragged to change its width or height: the same handle Arrange draws between a Grid's columns and under a component, for an app to place between two panes of its own. A focusable separator that says its value and bounds; dragged with pointer events, so a mouse, a pen and a finger all work; moved by the arrow keys (Shift for bigger steps), Home and End; put back by Enter or a double click. It holds no size of its own: the host keeps value, draws each change from onChange and keeps the size on onChangeEnd. Its parent must be positioned, since it sits on that parent's edge.

Props

PropTypeRequiredWhat it is
edge"right" \"bottom"yes
valuenumberThe size it stands for, in any unit: pixels, a share, a percentage. Left out when no size is set yet.
minnumberThe least it can be.
maxnumberThe most it can be.
snapnumberValues land on multiples of this (10 rounds to ten pixels).
stepnumberHow far an arrow key moves it; Shift moves five steps. A twentieth of the range by default.
unitPixelsnumberHow many pixels on screen one unit is: 1 for pixels, a pane's width for a share of it. A function of the handle is read when a drag starts.
labelstringyesWhat it resizes, for assistive technology: "Resize the map and the list".
valueTextstringThe value in words, when a number alone does not say it: "40% and 60%".
alwaysbooleanShown all the time, rather than when its parent is pointed at or it has focus (it always shows on touch).

Parts the host supplies

Props that take code. Each is optional unless marked; the component leaves out what it needs it for.

  • onReset: Reset. Enter or a double click puts the size back. On the page: back to half and half.
  • startFrom: Start from what is drawn. Where a drag starts when no value is set, such as the height drawn now.

Callbacks

  • onChange: Each new value while it is dragged, and after each key.
  • onChangeEnd: When a drag ends (committed, or cancelled by Escape back where it started) and after each key: where to keep the size.

Example

tsx
<ResizeHandle
  edge="right"
  value={0.5}
  min={0.25}
  max={0.75}
  step={0.05}
  label="Resize the map and the list"
  valueText="50% and 50%"
  onReset={onReset}
  onChange={…}
  onChangeEnd={…}
/>