# Skeleton

Placeholder shapes in the layout of content that is still loading.

- Family: feedback
- Import: `import { Skeleton, SkeletonGroup } from "@senvenli/react/feedback";`
- Page: https://design.senvenli.com/docs/components/skeleton
- JSON: https://design.senvenli.com/docs/components/skeleton.json

## Example: A loading list

Shapes mirror the rows they stand for; SkeletonGroup names the busy region.

```tsx
import { Skeleton, SkeletonGroup } from "@senvenli/react/feedback";
import { Stack } from "@senvenli/react/layout";

const ROWS = ["first", "second", "third"];

export default function Example() {
  return (
    <SkeletonGroup label="Loading customers" isLoading>
      <Stack space="space-200">
        {ROWS.map((row) => (
          <Stack direction="horizontal" key={row} space="space-150" wrap={false}>
            <Skeleton variant="circle" size={32} />
            <div className="min-w-0 flex-1">
              <Skeleton variant="text" lines={2} />
            </div>
          </Stack>
        ))}
      </Stack>
    </SkeletonGroup>
  );
}
```

## Examples

### Swapping in the content

`isLoaded` shows the children in place of the shape.

```tsx
import { Button } from "@senvenli/react/action";
import { Avatar, Text } from "@senvenli/react/display";
import { Skeleton, SkeletonGroup } from "@senvenli/react/feedback";
import { Stack } from "@senvenli/react/layout";
import { useState } from "react";

export default function Example() {
  const [isLoading, setLoading] = useState(true);
  return (
    <Stack space="space-200" align="start">
      <div className="w-full">
        <SkeletonGroup label="Loading customer" loadedLabel="Customer" isLoading={isLoading}>
          <Stack direction="horizontal" space="space-150" wrap={false}>
            <Skeleton variant="circle" size={32} isLoaded={!isLoading}>
              <Avatar name="Sofia Marin" src="/avatars/05.webp" />
            </Skeleton>
            <div className="min-w-0 flex-1">
              <Skeleton variant="text" lines={2} isLoaded={!isLoading}>
                <Stack>
                  <Text weight="medium">Sofia Marin</Text>
                  <Text size="body-small" tone="subtle">ada@example.com</Text>
                </Stack>
              </Skeleton>
            </div>
          </Stack>
        </SkeletonGroup>
      </div>
      <Button onPress={() => setLoading((current) => !current)}>{isLoading ? "Show the content" : "Show the skeleton"}</Button>
    </Stack>
  );
}
```

### A card with a photo

`aspectRatio` holds the photo's box, and `radius` matches what it replaces.

```tsx
import { Skeleton, SkeletonGroup } from "@senvenli/react/feedback";
import { Box, Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <div className="mx-auto max-w-xs">
      <SkeletonGroup label="Loading project" isLoading>
        <Box padding="space-200" radius="large" border>
          <Stack space="space-200">
            <Skeleton aspectRatio="16/9" radius="large" />
            <Skeleton width="50%" height={16} />
            <Skeleton variant="text" lines={3} />
            <Skeleton width={96} height={32} radius="medium" />
          </Stack>
        </Box>
      </SkeletonGroup>
    </div>
  );
}
```

## Guidelines

### When to use it

- A layout is loading and its shape is known.

### Use something else when

- [spinner](https://design.senvenli.com/docs/components/spinner.md): The layout of what loads is unknown or very small.
- [progress](https://design.senvenli.com/docs/components/progress.md): The task's progress can be measured.

## Accessibility

Built in:

- SkeletonGroup marks the region busy and announces when it has loaded.

You provide:

- A `label` on SkeletonGroup that says what is loading.

## API reference

### Skeleton

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| isLoaded | `boolean` |  | no | Shows the children instead of the shape once the data is there. |
| children | `React.ReactNode` |  | no |  |
| delay | `number` |  | no | Milliseconds before the shape appears (default 300); the space is held meanwhile. |
| variant | `"text" \| "circle" \| "rectangle"` |  | no | `rectangle` (default): a block of `width` × `height`; `text`: `lines` of text, the last one shorter; `circle`: an avatar of `size` px. |
| lines | `number` |  | no | `text`: the number of 12px lines (default 2). |
| size | `number` |  | no | `circle`: the diameter in px (default 32, a list avatar). |
| width | `string \| number` |  | no | CSS width ("60%", 240); default full width. |
| height | `string \| number` |  | no | CSS height; default 12px (a text line). |
| radius | `"none" \| "small" \| "medium" \| "large" \| "full"` |  | no | The radius of what it replaces: `medium` for a button, `large` for a card photo. |
| aspectRatio | `string` |  | no | Aspect ratio for photos ("16/9"). |
| motion | `ComponentMotion` |  | no | `auto` (follow the device), `reduce` or `none`, for this component; the provider's setting otherwise. |

### SkeletonGroup

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| label | `string` |  | yes | What is loading ("Loading orders"); the region's name while busy. |
| loadedLabel | `string` |  | no | The region's name once loaded ("Orders"); none by default. |
| isLoading | `boolean` |  | yes |  |
| children | `React.ReactNode` |  | yes |  |

### Tokens it reads

`--ds-background-neutral`, `--ds-radius-full`, `--ds-radius-large`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-space-075`

## Related

- [spinner](https://design.senvenli.com/docs/components/spinner.md)
