# Skeleton

Muted placeholders while content loads. Skeleton breathes, for content reloading in place; Bone sweeps a light band across, for the workspace preview. Both hide from screen readers, so mark the region they fill aria-busy, and both hold still under reduced motion.

- Beta: ready to use; its API can still change in a minor release.
- Category: Status & indicators

```tsx
import { Bone, Skeleton, SkeletonSwap } from "@leap-crm/design-system";
```

## Best practices

- Do: Build the placeholder to the content's shape: `line` at the height of the text, `circle` for an avatar, `box` for a checkbox or small icon.
- Do: Wrap it in `SkeletonSwap`, so the loaded content fades in where the skeleton was, the height eases and the region is marked busy.
- Do: Mark the region `aria-busy` yourself when you use `Skeleton` or `Bone` without `SkeletonSwap`. Both are hidden from screen readers.
- Do: Use `Skeleton` for content reloading in place, and `Bone` for the workspace preview.
- Don't: Use it for a short wait on one control, like saving a contact. Set the button's `loading`, or use `Spinner`.

## Related

- [Spinner](./spinner.md)
- [Empty State](./empty-state.md)
- [Progress](./progress.md)

## Examples

What the examples import:

```tsx
import { useState } from "react";
import { Avatar, Bone, Button, Skeleton, SkeletonSwap } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const wait = (ms: number) =>
  new Promise<void>(resolve => {
    setTimeout(resolve, ms);
  });

function LoadingRow() {
  return (
    <div className="flex items-center gap-3">
      <Skeleton shape="circle" className="size-8" />
      <div className="flex flex-1 flex-col gap-1.5">
        <Skeleton className="h-3.5 w-1/2" />
        <Skeleton className="h-3 w-3/4" />
      </div>
    </div>
  );
}

function Reload() {
  const [loading, setLoading] = useState(false);
  const load = async () => {
    setLoading(true);
    await wait(1200);
    setLoading(false);
  };
  return (
    <div className="flex w-80 flex-col items-start gap-4">
      <SkeletonSwap
        loading={loading}
        skeleton={
          <div className="flex flex-col gap-4">
            <LoadingRow />
            <LoadingRow />
          </div>
        }
        className="w-full"
      >
        <div className="flex flex-col gap-4">
          {[
            ["Jane Citizen", "JC", "Reviewing the costs agreement"],
            ["Sam Taylor", "ST", "Waiting on the title search"],
            ["Priya Nair", "PN", "Settlement booked for Friday"],
          ].map(([name = "", initials, note]) => (
            <div key={name} className="flex items-center gap-3">
              <Avatar
                name={name}
                initials={initials}
                size="lg"
                person="contact"
              />
              <div className="flex flex-col">
                <span className="text-body text-neutral-text">{name}</span>
                <span className="text-small text-neutral-text-muted">
                  {note}
                </span>
              </div>
            </div>
          ))}
        </div>
      </SkeletonSwap>
      <Button intent="outline" size="sm" onClick={load}>
        {loading ? "Loading…" : "Reload"}
      </Button>
    </div>
  );
}
```

### Shapes

Line (4 px radius) at the height of the text it stands in for, circle for avatars, box (2 px radius) for checkboxes and small icons.

```tsx
<div className="flex items-center gap-6">
  <Skeleton className="h-3 w-40" />
  <Skeleton shape="circle" className="size-10" />
  <Skeleton shape="box" className="size-3.5" />
</div>
```

### A loading row

```tsx
<div aria-busy="true" className="flex w-80 items-center gap-3">
  <Skeleton shape="box" className="size-3.5" />
  <Skeleton shape="circle" className="size-7" />
  <div className="flex flex-1 flex-col gap-1.5">
    <Skeleton className="h-3.5 w-3/4" />
    <Skeleton className="h-3 w-1/2" />
  </div>
</div>
```

### Skeleton to content

SkeletonSwap trades the skeleton for the content in one place: the content fades and sharpens in as the skeleton fades out, and the height eases when they differ (here, two placeholder rows become three people), so nothing below jumps. The region is aria-busy while loading.

```tsx
<Reload />
```

### Bone

Each bone takes its index, so the sweep moves down the block as one wave.

```tsx
<div aria-busy="true" className="flex w-80 flex-col gap-2">
  {["w-1/2 h-4", "w-full h-3", "w-full h-3", "w-2/3 h-3"].map(
    (size, index) => (
      <Bone
        key={size + String(index)}
        index={index}
        className={`${size} rounded-md`}
      />
    ),
  )}
</div>
```

## Props

### Skeleton

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `shape` | `"line" \| "circle" \| "box"` | `"line"` | Line (4 px radius) at the height of the text it stands in for, circle for avatars, box (2 px radius) for checkboxes and small icons. |
| `className` | `string` |  | Its size, like "h-3 w-40". The shape, colour and pulse are fixed. |
| `style` | `CSSProperties` |  | Inline styles on the root element, like a CSS variable it reads. |

### SkeletonSwap

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `loading` (required) | `boolean` |  | Whether the content is still loading: shows the skeleton and marks the region busy. |
| `skeleton` (required) | `ReactNode` |  | The placeholder, built from Skeleton or Bone to the content's shape. |
| `children` (required) | `ReactNode` |  | The loaded content. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### Bone

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `index` | `number` | `0` | Its place in a block of bones, so the sweep moves down the block as one wave. |
| `className` | `string` |  | Its size and radius, like "h-3 w-40 rounded-md". |
| `style` | `CSSProperties` |  | Inline styles on the root element, like a CSS variable it reads. |
