# Skeleton

Placeholder with a shimmer, shown while content loads. Three shapes: `rect` (a block that fills its parent by default, size it with `--skeleton-width` and `--skeleton-height`), `circle` (an avatar, `--skeleton-size`) and `text` (`lines` bars of text height, the last one shorter). The shimmer is in sync across all skeletons on the page and stops with reduced motion. It is hidden from screen readers: mark the region that is loading with `aria-busy="true"`. Its shape is exposed as `data-shape` for app CSS.

```ts
import { Skeleton } from '@likable-hair/svelte';
```

Category: simple. Source: `src/lib/components/simple/loaders/Skeleton.svelte`.

## Examples

### Loading card

Skeletons in the shape of the content that is coming. The region that is loading gets `aria-busy="true"`; the skeletons themselves are hidden from screen readers.

```svelte
<script lang="ts">
	import { Skeleton, Switch } from '@likable-hair/svelte';

	let loaded = $state(false);
</script>

<div class="stack">
	<Switch bind:checked={loaded} label="Loaded" />
	<article class="card" aria-busy={!loaded}>
		{#if loaded}
			<header>
				<span class="avatar">GR</span>
				<div>
					<b>Giulia Rossi</b>
					<p>Colour and cut · 2h ago</p>
				</div>
			</header>
			<div class="photo"></div>
			<p>Warm copper balayage with a soft layered cut. Next appointment in six weeks for a gloss.</p>
		{:else}
			<header>
				<Skeleton shape="circle" --skeleton-size="44px" />
				<div class="lines">
					<Skeleton --skeleton-height="12px" --skeleton-width="60%" />
					<Skeleton --skeleton-height="10px" --skeleton-width="35%" />
				</div>
			</header>
			<Skeleton --skeleton-height="110px" --skeleton-border-radius="8px" />
			<Skeleton shape="text" lines={2} />
		{/if}
	</article>
</div>

<style>
	.stack {
		display: grid;
		gap: 16px;
		justify-items: start;
		width: min(100%, 360px);
	}

	.card {
		box-sizing: border-box;
		display: grid;
		gap: 12px;
		width: 100%;
		padding: 16px;
		border: 1px solid var(--global-color-border);
		border-radius: var(--global-radius-lg);
		background: var(--global-color-surface-solid);
		font-size: 14px;
	}

	header {
		display: flex;
		align-items: center;
		gap: 12px;
	}

	.lines {
		display: grid;
		flex: 1;
		gap: 8px;
	}

	.avatar {
		display: grid;
		place-items: center;
		width: 44px;
		height: 44px;
		border-radius: 50%;
		background: var(--global-color-primary-soft);
		color: var(--global-color-primary);
		font-weight: 600;
	}

	b {
		font-weight: 600;
	}

	p {
		margin: 0;
		color: var(--global-color-text-2);
	}

	header p {
		color: var(--global-color-text-3);
		font-size: 12px;
	}

	.photo {
		height: 110px;
		border-radius: 8px;
		background: var(--global-gradient-soft);
	}
</style>
```

### Shapes

`rect` fills its parent (here a 64px row) unless `--skeleton-width` and `--skeleton-height` say otherwise, `circle` is `--skeleton-size` wide, `text` draws `lines` bars of text height with a shorter last line.

```svelte
<script lang="ts">
	import { Skeleton } from '@likable-hair/svelte';
</script>

<div class="grid">
	<div class="cell"><Skeleton /></div>
	<Skeleton shape="circle" --skeleton-size="64px" />
	<Skeleton shape="text" lines={3} />
</div>

<style>
	.grid {
		display: grid;
		grid-template-columns: 1fr auto 2fr;
		align-items: center;
		gap: 24px;
		width: 100%;
	}

	.cell {
		height: 64px;
	}
</style>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `shape` | `'rect' \| 'circle' \| 'text'` | `'rect'` | `rect` a block, `circle` an avatar, `text` one or more lines of text. |
| `lines` | `number` | `1` | Number of lines with `shape="text"`. With more than one, the last line is shorter. |
| `class` | `string` | `''` | Extra classes on the root element. |

It also accepts the native attributes and events of `<div>` (for example `id`, `title`, `aria-label`, `onkeydown`), which are forwarded to the element.

## CSS variables

For a single instance, pass them as style props: `<Skeleton --skeleton-background="tomato">`. The `--skeleton-default-*` defaults apply to the whole app: override them in `:root` or in a theme.

| Per-instance variable | Default |
| --- | --- |
| `--skeleton-background` | `--skeleton-default-background`: `var(--global-color-surface-2)` |
| `--skeleton-highlight-color` | `--skeleton-default-highlight-color`: `var(--global-color-surface-3)` |
| `--skeleton-border-radius` | `--skeleton-default-border-radius`: `var(--global-radius-xs)` |
| `--skeleton-duration` | `--skeleton-default-duration`: `1.6s` |
| `--skeleton-width` | `--skeleton-default-width`: `100%` |
| `--skeleton-height` | `--skeleton-default-height`: `100%` |
| `--skeleton-min-height` | `--skeleton-default-min-height`: `1em` |
| `--skeleton-size` | `--skeleton-default-size`: `40px` |
| `--skeleton-line-gap` | `--skeleton-default-line-gap`: `0.65em` |
| `--skeleton-line-height` | `--skeleton-default-line-height`: `0.75em` |
| `--skeleton-last-line-width` | `--skeleton-default-last-line-width`: `60%` |
