# Canvas X-ray

The boxes, spacings and text lines of an element of a captured page, the guides to its parent or to another element, and the tag that names it.

Live variants: https://design.arcadia.is/components/canvas-xray

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

A small page and its survey. Point for its boxes, or choose one below for its marks and its readout.

```tsx
import { useState } from "react";
import { SegmentedControl } from "@arcadia/ui";

function Looking() {
  const [hovered, setHovered] = useState<string | null>(null);
  const [selected, setSelected] = useState<string | null>("e3");
  return (
    <div {...stylex.props(CanvasXrayStyles.stack)}>
      <CanvasXrayStage hovered={hovered} selected={selected} onHover={setHovered} onChoose={setSelected} />
      <SegmentedControl aria-label="Element" size="sm" items={NAMES} value={selected ?? ""} onValueChange={setSelected} />
    </div>
  );
}
```

## Accessibility

With nothing chosen the overlay is out of the way of a reader. With an element chosen it is one image whose name is the readout: the element, its size and each spacing it carries. It takes no focus and no pointer of its own. With an area, it is one image named for the area's size and the number of elements it reaches. On a plane, the arrows step the chosen element through an entered frame, and each one's readout is heard.

- Arrows: On a plane with X-ray in hand and a frame entered, steps through the page's elements
- A drag across a frame: On a plane with X-ray in hand, surveys every element in its area
- Escape: Lets the area go

## API reference

### CanvasXray

- `items` (`readonly CanvasXrayItem[]`, required): The elements of the survey, outermost first.
- `bars` (`readonly CanvasBox[]`, default `[]`): The boxes of its text lines.
- `frame` (`{ box: CanvasBox; page: { readonly w: number; readonly h: number } }`, required)
- `hovered` (`string | null`): The element under the pointer.
- `selected` (`string | null`): The element chosen: its guides and its readout stand, and the spaces between its children.
- `area` (`CanvasBox | null`, default `null`): An area of the page, in page pixels: every element it reaches is outlined at once, with its padding and the spaces between neighbours, and the rest of the frame is veiled. The element under the pointer is still named.
- `rootStyle` (`RootStyle`): A component's typed override prop: `Layout` and its documented knobs, each the references it takes or another kit knob of its kind; anything else is a type error at the call site (STYLEX.md).
