# Exploded screen

A screen of live UI pulled apart into floating layers, each labelled on a leader line, so one image explains how an AI product is built: the app, the agent panel over it, the tool calls and the agent's cursor. It is flat at progress 0 and apart at 1.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Exploded screen. An invoices app with an agent working in it, pulled apart into its layers: the app, the agent panel, the tool calls and the agent's cursor, each on a leader line. Preview: https://chatcn.dev/preview/exploded-screen-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/exploded-screen
```

## Usage

```tsx
import {
  ExplodedLayer,
  ExplodedScreen,
  useScrollProgress,
} from "@/components/ui/chatcn/pro/exploded-screen"

const ref = React.useRef<HTMLDivElement>(null)
const progress = useScrollProgress(ref)

<div ref={ref}>
  <ExplodedScreen progress={progress}>
    <ExplodedLayer depth={3} label="Agent cursor">
      <AgentCursor x={0.05} y={0.6} action={{ kind: "select", label: "Select row" }} />
    </ExplodedLayer>
    <ExplodedLayer depth={2} label="Tool calls">
      <ToolCalls />
    </ExplodedLayer>
    <ExplodedLayer depth={1} label="Agent panel">
      <AgentPanel />
    </ExplodedLayer>
    <ExplodedLayer depth={0} label="App">
      <App />
    </ExplodedLayer>
  </ExplodedScreen>
</div>
```

Every layer is the full screen rectangle, laid out at `viewport` px wide (720 by default) and scaled to fit, holding real DOM. Leave a layer transparent where it has nothing, the way an overlay is. At progress 0 the layers lie on each other and you see the plain screen. To 0.35 the camera turns to the isometric angle; from 0.25 the layers lift along their normal by `depth * gap`, the top one first. Labels fade in after 0.6.

`progress` takes a number, or a source that changes outside React: `useScrollProgress(ref)` ties it to the scroll position (0 as the element enters, 1 once it is centered), and `createProgress()` gives you one to set from a slider or a timeline. Sources never re-render the layers' content. `hover` opens it on hover and focus instead, on a critically damped spring.

Upper layers float as their own content: give each piece its own surface (a panel's background, a card) and it occludes what is under it cleanly. Only the base layer draws the whole screen as a sheet. Point each label at its content with `anchor`; a tag that would sit over any layer's content moves to the other side. Narrower than 480 px, the tags give way to numbered markers on the layers and a two column legend under the stack, so the stack keeps the full width. Lay content out so a lifted layer clears the text below it: lifting moves a layer up and to the right of the one beneath.

Each layer is drawn with the flattened matrix of the 3D camera, so text is painted at full resolution at every frame instead of being sampled from a texture, and the layers paint in depth order: one can never cut through another. The stack scales to fit its box, so the component keeps the screen's footprint from flat to apart.

## Examples

### Progress, labels, gap and hover

Example: Exploded screen states. Flat, halfway and apart, labels at the start, a wider gap, on hover, and at phone width. Preview: https://chatcn.dev/preview/exploded-screen-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `progress` | `number | ProgressSource` | 0 flat to 1 apart. Default 0 |
| `hover` | `boolean` | Open on hover and focus instead of `progress` |
| `gap` | `number` | Distance between layers when apart, in screen px. Default 104 |
| `aspect` | `number` | Width over height. Default 1.6 |
| `viewport` | `number` | CSS width the layers lay out at. Default 720 |
| `labels` | `"end" | "start" | "none"` | Label side, logical. Default `end` |
| `radius` | `number` | Corner radius of the screen and the layers. Default 16 |
| `reducedMotion` | `boolean` | Defaults to the user's setting |
| `ExplodedLayer` `depth` | `number` | 0 is the base plate. Higher lies on top |
| `ExplodedLayer` `label` | `string` | The tag on the leader line and the layer's name |
| `ExplodedLayer` `anchor` | `string` | Selector for the content the leader points at, for example the card the layer holds |
| `ExplodedLayer` `shadow` | `boolean` | Cast a contact shadow on the layer below. Default true; turn it off for a cursor |
| `ExplodedLayer` `plane` | `boolean` | Draw the layer's whole screen as a hairline sheet when apart. Default only for depth 0 |

## Accessibility

- Layers render top first, whatever order you pass them in, so content reads in depth order. Each is a group named by its label.
- With `hover`, the screen is focusable and opens on focus, so it works from the keyboard. Otherwise the scene has no controls of its own; its content keeps its own semantics.
- Reduced motion: no camera move. It cuts to apart at progress 0.5 and back below it.
- Under `forced-colors` the shadows drop out; the base plate, the tags, the leader lines and the markers keep plain system outlines.

Source: https://chatcn.dev/docs/components/exploded-screen