# Skeleton

> Placeholder text lines, circles and rectangles with the Data Grid's transform-only shimmer, rendered in Server Components and sized from the content they stand in for.

Canonical: https://salmonui.dev/docs/notifications/skeleton

```tsx
import { Skeleton } from '@salmonui/notifications/skeleton';
import '@salmonui/notifications/skeleton/styles.css';

<div aria-busy="true">
  <Skeleton shape="circle" />
  <Skeleton lines={3} />
</div>;
```

`Skeleton` is a server component: no `"use client"` directive, no hooks and
no client JavaScript, so the placeholders are in the server HTML and there
is nothing to hydrate.

### Live demo: Skeleton profile card

Live demo: https://salmonui.dev/demos/notifications/skeleton-card

A loading profile card built from text, circle and rectangle skeletons with sizes in pixels and percent, a skeleton sized from the button it stands in for, the wave, pulse or no animation, and right-to-left.

`Demo.tsx`:

```tsx
'use client';

import { useState } from 'react';
import { Avatar } from '@salmonui/layout/avatar';
import { Badge } from '@salmonui/notifications/badge';
import { Button } from '@salmonui/buttons/button';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { Select } from '@salmonui/dropdowns/select';
import { Skeleton, type SkeletonAnimation } from '@salmonui/notifications/skeleton';

const ANIMATIONS = [
  { value: 'wave', label: 'wave' },
  { value: 'pulse', label: 'pulse' },
  { value: 'false', label: 'none' },
];

// A profile card that loads: placeholder shapes while loading, then the same
// card sized from its content. The controls pick the animation and direction.
export default function SkeletonCardDemo() {
  const [loading, setLoading] = useState(true);
  const [animation, setAnimation] = useState<SkeletonAnimation>('wave');
  const [rtl, setRtl] = useState(false);
  return (
    <div dir={rtl ? 'rtl' : 'ltr'} style={{ display: 'grid', gap: 16, maxInlineSize: 420 }}>
      <div className="demo-toolbar">
        <Button variant="outline" onClick={() => setLoading(!loading)}>
          {loading ? 'Finish loading' : 'Load again'}
        </Button>
        <label>
          Animation
          <Select aria-label="Animation" data={ANIMATIONS} value={String(animation)} onValueChange={(value) => value != null && setAnimation(value === 'false' ? false : (value as 'wave' | 'pulse'))} />
        </label>
        <Checkbox checked={rtl} onCheckedChange={(checked) => setRtl(checked)}>
          Right to left
        </Checkbox>
      </div>
      <section aria-label="Profile" aria-busy={loading} style={{ display: 'grid', gap: 12, padding: 12, border: '1px solid var(--salmon-border-subtle)', borderRadius: 'var(--salmon-radius-lg)' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
          {loading ? <Skeleton shape="circle" animation={animation} /> : <Avatar name="Grace Hopper" shape="circle" />}
          <div style={{ flex: 1, display: 'grid', gap: 4 }}>
            {loading ? <Skeleton width="60%" animation={animation} /> : <strong>Grace Hopper</strong>}
            {loading ? <Skeleton width={120} height={12} animation={animation} /> : <small>Rear admiral</small>}
          </div>
        </div>
        {loading ? <Skeleton shape="rect" width="100%" height={120} animation={animation} /> : <div style={{ blockSize: 120, borderRadius: 'var(--salmon-radius-sm)', background: 'var(--salmon-color-primary-subtle)' }} />}
        {loading ? <Skeleton lines={3} animation={animation} /> : <p style={{ margin: 0 }}>Invented the first compiler and popularized machine-independent programming languages.</p>}
        {/* Sized from the button it stands in for, with the button's own corner radius. */}
        <div>
          <Skeleton loading={loading} animation={animation} style={{ borderRadius: 'var(--salmon-radius-md)' }}>
            <Button tone="primary">
              Follow
            </Button>
          </Skeleton>
        </div>
        <div style={{ display: 'flex', gap: 8 }}>
          {loading ? (
            <>
              <Skeleton shape="rect" width={64} height={20} animation={animation} />
              <Skeleton shape="rect" width={64} height={20} animation={animation} />
            </>
          ) : (
            <>
              <Badge>Navy</Badge>
              <Badge>COBOL</Badge>
            </>
          )}
        </div>
      </section>
    </div>
  );
}
```

## Shapes and sizes

- `shape`: `'text'` (default, one line of text height), `'circle'`
  (40 px) or `'rect'`. A square is a `rect` with equal
  `width` and `height`.
- `lines`: several text bars; the last one is shorter.
- `width` and `height` take a number of pixels or any CSS length (`'60%'`,
  `'4rem'`) and set the logical inline and block size.

## Animation

`animation` is `'wave'` (default), `'pulse'` or `false`. The wave is
the same compositor-only transform on a pseudo-element, and the same
`salmon-data-grid-shimmer` keyframes, as the Data Grid skeleton rows: one CSS
definition for both, with no layout or paint per frame. `'pulse'` is an
opacity animation and also serves as the fade effect: a separate
fade would look alike, and one fewer keyframes set keeps the stylesheet
small. In
right-to-left pages the wave runs toward the inline end. Every
animation stops under `prefers-reduced-motion` and in forced colors, where
the bars keep a visible outline.

## Loading content

```tsx
<Skeleton loading={!user}>
  <UserCard user={user ?? placeholderUser} />
</Skeleton>
```

`loading` defaults to `true`. With children,
the skeleton takes the size of the children, which stay hidden and `inert`
while loading; `loading={false}` renders the children alone.

## Accessibility

Skeletons are always `aria-hidden` and take no `label`: a label
on every skeleton would make a screen reader read the same text many times.
Instead the loading region carries `aria-busy="true"` and one status message (a
`Spinner` with `label`, or a `Message` with `live="polite"`).

## Class, style and lifecycle

`className` and `style` reach the root `<span>`, and other DOM props are
spread onto it; `ref` is that `<span>`. Direction comes from the inherited
`dir`. There is nothing to persist:
a skeleton has no state. There is no teardown method and no mount event:
render the skeleton while loading and remove it, or pass
`loading={false}`.

API reference: [`@salmonui/notifications/skeleton`](https://salmonui.dev/docs/reference/notifications/skeleton).
