# Skeleton

A placeholder for content that is still loading. Wraps the content it stands in for: text becomes a cap-height bar as wide as the text, and an element becomes a block its size, hidden underneath. `aria-hidden`.

## Use for

- a placeholder for content that is still loading
- a loading skeleton for a section, row or table
- keeping the space of a control while loading without drawing a bone

## Practices

- Do: Build a skeleton in its own `<feature>.skeleton.tsx` from the same components as the view. The rules are in the Skeletons guide (`mosaic guides inspect skeletons`).
- Do: Write placeholder strings at a typical length, one line each. Bars do not wrap.
- Do: Wrap row actions with `visible={false}` so the row keeps its height without a bone.
- Don't: Leave a skeleton up when the fetch returns nothing. Render `EmptyState` instead.
- Don't: Add skeleton code to a component or view. Wrap content in `Skeleton` from the skeleton file.

## API reference

### Skeleton

Renders a `span` around its children and forwards its ref. Carries `data-shape` for element children, and `data-text` and `data-visible`.

Slot: `cl-skeleton`

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `show` | `boolean` | `true` | When `false`, renders the children as they are. |
| `visible` | `boolean` | `true` | When `false`, keeps the space but draws no bone. |
| `shape` | `SkeletonShape` | `'rounded'` | `rounded` for media and buttons, `pill` for avatars and round controls, `square` for image tiles. Ignored for text. |
| `width` | `number \| string` |  | Fixed width, as px or a CSS length. For a skeleton with no children. |
| `height` | `number \| string` |  | Fixed height, as px or a CSS length. For a skeleton with no children. |

## Examples

### A text bar

```tsx
<Section.Label>
  <Skeleton>{device.name}</Skeleton>
</Section.Label>
```

### Content that stays mounted

```tsx
<Skeleton show={loading}>{title}</Skeleton>
```

## Related

- [EmptyState](/docs/components/empty-state.md)
- [useSpinDelay](/docs/hooks/use-spin-delay.md)
- [VisuallyHidden](/docs/components/visually-hidden.md)
