# Clamp

A block kept to a few of its lines under a fade, with one control that opens the rest, its end in view while it grows.

Live variants: https://design.arcadia.is/components/clamp

```tsx
import { Clamp } from "@arcadia/ui";
```

```tsx
import {
  Card, CardHeader, CardTitle, CardBody, Clamp, CopyButton,
} from "@arcadia/ui";

<Card mono>
  <CardHeader icon="terminal"><CardTitle>make test</CardTitle></CardHeader>
  <CardBody>
    <Clamp
      lines={5} align="end" control="text" scroll follow
      more={`Show all ${COUNT}`} less="Show less" label="Output text"
      note={<span {...stylex.props(styles.count)}>{COUNT}</span>}
      trailing={<CopyButton variant="text" size="xs" text={RUN} label="Copy output" copiedLabel="Copied" />}
    >
      <pre {...stylex.props(styles.output)}>{RUN}</pre>
    </Clamp>
  </CardBody>
</Card>
```

## Accessibility

The control is a button: Enter or Space opens and closes it, and it carries `aria-expanded` and `aria-controls` for the block it opens. The button label tells the reader what it opens.

A block that scrolls open takes the keyboard once it is focused, with the kit's scroll area keys, and its end stays in view while content arrives until the reader scrolls away.

## API reference

### Clamp

- `lines` (`number`, required): The lines kept while closed, in the content's own text: the block takes that height.
- `more` (`string`, required): The words on the control while closed ("Show all 40 lines", "Show full description").
- `less` (`string`, required): Its words while open ("Show less").
- `align` (`"start" | "end"`, default `"start"`): Which end stands while closed. Default "start": a paragraph keeps its first lines. "end" keeps the last lines: a job's last output, read from its end.
- `control` (`"button" | "text"`, default `"button"`): The control: a ghost button under the block, or a text button in the row its note and trailing controls share.
- `scroll` (`boolean`, default `false`): While open, the block scrolls above --clamp-open-max instead of growing with its content.
- `follow` (`boolean`, default `false`): Its end stays in view while the content grows, until the reader scrolls away: a job still writing. Needs scroll.
- `note` (`ReactNode`): What goes before the control in its row, in the quiet ink: what the content is, how much of it there is. Only with control="text".
- `trailing` (`ReactNode`): What goes after the control in its row: a Copy button, a link. Only with control="text".
- `label` (`string`, default `"More"`): What the scrolling block is, for assistive tech ("Output text").
- `open` (`boolean`): Open, controlled.
- `defaultOpen` (`boolean`, default `false`): Open before the person asks.
- `onOpenChange` (`(open: boolean, details: OpenChangeDetails) => void`): Called when the person opens or closes it.
- `hold` (`(change: () => void, anchor: Element | null) => void`, default `(change) => change()`): Wraps each change Clamp makes to open or close, given the box to keep in view: a product's scroll keeper holds the reader's place across it. Omit it and the change runs at once.
- `rootStyle` (`ClampStyle`): Typed StyleX override: where it sits and its knobs.
- `children` (`ReactNode`, required): What it holds.
