# Skeleton

```tsx
import { Skeleton, useDelayedLoading } from '@tangible/ui';
```

Interactive docs and examples: [Skeleton in Storybook](https://design.tangible.one/?path=/docs/components-skeleton--docs).

## Skeleton props

| Prop | Type | Default | Description |
| - | - | - | - |
| `lines?` | `number` | `1` | Text only: how many lines. The last of several is shorter. |
| `shape?` | `"block" \| "circle" \| "text"` | `'text'` | - \`text\`: lines of text, each one line-height tall (the default); \`circle\`: an avatar-sized circle, sized by \`size\`; \`block\`: media, a chart or a tile; 16:9 unless sized with \`style\` |
| `size?` | `"lg" \| "md" \| "sm" \| "xl" \| "xs" \| "xxl"` | | Circle only: Avatar's size scale. Unset, it is the md size (2.5rem). |
| `textStyle?` | `SkeletonTextStyle` | | Text only: size the lines to a text style. Without it, the lines take the surrounding font size and line height. |

Also accepts the standard attributes of `HTMLAttributes` (`data-*`, `aria-*`, event handlers), passed to the element it renders.

### Skeleton.Region

Also exported as `SkeletonRegion`.

| Prop | Type | Default | Description |
| - | - | - | - |
| `loading` | `boolean` | | Whether the content is loading. |
| `children?` | `ReactNode` | | The loaded content. On a first load it isn't rendered until loading ends (it may have no data yet); once shown, it stays up until the fallback replaces it. |
| `delay?` | `number` | `300` | How long loading must last before the fallback shows, in ms. A faster load shows nothing and swaps once. |
| `fallback?` | `ReactNode` | | Shown in place of the content while loading: compose `Skeleton`s in the real layout. Without one, the region is still busy and announces, but shows nothing while loading. |
| `loadedLabel?` | `string` | | Announced when content arrives, only after `loadingLabel` was announced ("Courses loaded"). Ignored without `loadingLabel`. |
| `loadingLabel?` | `string` | | Announced politely once loading has lasted past `delay` ("Loading courses"). Nothing is announced for a fast load. Named as Button's: it is spoken, it doesn't name the region. |
| `minDuration?` | `number` | `500` | Once shown, the fallback stays at least this long, in ms, so content doesn't replace it a frame later. |
| `stale?` | `boolean` | `false` | Keep showing the current content while loading (a refetch). The region is marked busy and no fallback shows: swapping loaded content for grey bars on every refresh is a regression, not a loading state. |

Also accepts the standard attributes of `HTMLAttributes` (`data-*`, `aria-*`, event handlers), passed to the element it renders.

## Hooks

### useDelayedLoading

```ts
useDelayedLoading(loading: boolean, { delay, minDuration }?: DelayedLoadingOptions): boolean
```

## Examples

- [Circle](https://design.tangible.one/?path=/story/components-skeleton--circle): Avatar's size ladder. Unset, a circle is md (2.5rem).

- [Block](https://design.tangible.one/?path=/story/components-skeleton--block): 16:9 until sized with `aspectRatio` or `blockSize`. It fills its container's width.

- [Region: stale refetch](https://design.tangible.one/?path=/story/components-skeleton--region-stale): Starts with "Keep content" on: the first load shows nothing for the delay, then the skeleton; every reload after that keeps the list up and only marks the region busy.

Other stories: Default, Paragraph, Text Styles, In Card, In List Row, In a stat tile, Surfaces, Dashboard, Dashboard: loaded and loading, Region, Region: focus on reload, useDelayedLoading ([interactive page](https://design.tangible.one/?path=/docs/components-skeleton--docs)).

## Component API tokens

Read via fallback, never declared. Set one on an ancestor to restyle every instance under it.

- `--tui-skeleton-bg`
- `--tui-skeleton-radius`
- `--tui-skeleton-duration`

---

Interactive version: https://design.tangible.one/?path=/docs/components-skeleton--docs
