# Skeleton

> A placeholder in the shape of content that is loading.

A skeleton draws gray placeholders in the shape of the content that is loading, so the page doesn't jump when it arrives.

## When to use

- Use it when you know the shape of what is loading: rows of a list, a card, a profile.
- Use a [Spinner](https://design.sosialoka.tech/components/spinner/) for a short wait without a known shape, such as a button that saves.
- Match the real layout: the same number of rows and the same sizes, roughly.

_Live preview of the React and Vue versions: https://design.sosialoka.tech/components/skeleton/_

## Anatomy

1. Shape placeholder
2. Line placeholder

Boxes on `muted` with `radius-md` and a gentle `animate-pulse`. The container that is loading carries `aria-busy="true"` and a screen-reader text such as "Memuat rilis…".

## Variants

There is one style. Shape it with size classes: `size-10` for an avatar, `h-4 w-3/4` for a line of text.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `className` | `class` | `width`, `height` on a `muted` box | class | none | The size and shape. |

## Code

**React**
```tsx
import { Skeleton } from "@/components/ui/skeleton"

export default function SkeletonDemo() {
  return (
    <div aria-busy="true" className="grid w-full max-w-sm gap-4">
      <span className="sr-only">Memuat rilis…</span>
      {[0, 1, 2].map((row) => (
        <div key={row} className="flex items-center gap-3">
          <Skeleton className="size-10" />
          <div className="grid flex-1 gap-2">
            <Skeleton className="h-4 w-3/4" />
            <Skeleton className="h-3 w-1/2" />
          </div>
        </div>
      ))}
    </div>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { Skeleton } from "@/components/ui/skeleton"
</script>

<template>
  <div aria-busy="true" class="grid w-full max-w-sm gap-4">
    <span class="sr-only">Memuat rilis…</span>
    <div v-for="row in 3" :key="row" class="flex items-center gap-3">
      <Skeleton class="size-10" />
      <div class="grid flex-1 gap-2">
        <Skeleton class="h-4 w-3/4" />
        <Skeleton class="h-3 w-1/2" />
      </div>
    </div>
  </div>
</template>
```

**Flutter**
```dart
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

// shadcn_ui has no skeleton: muted boxes with the md radius stand in, and the list says it is busy.
class Bone extends StatelessWidget {
  const Bone({super.key, required this.width, required this.height});

  final double width;
  final double height;

  @override
  Widget build(BuildContext context) {
    final theme = ShadTheme.of(context);
    return Container(
      width: width,
      height: height,
      decoration: BoxDecoration(color: theme.colorScheme.muted, borderRadius: theme.radius),
    );
  }
}

class SkeletonDemo extends StatelessWidget {
  const SkeletonDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return Semantics(
      label: 'Memuat rilis…',
      child: ExcludeSemantics(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          spacing: 16,
          children: [
            for (var row = 0; row < 3; row++)
              const Row(
                mainAxisSize: MainAxisSize.min,
                spacing: 12,
                children: [
                  Bone(width: 40, height: 40),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    spacing: 8,
                    children: [Bone(width: 240, height: 16), Bone(width: 160, height: 12)],
                  ),
                ],
              ),
          ],
        ),
      ),
    );
  }
}
```

## Install

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/skeleton.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/skeleton.json
```

## Accessibility

- Put `aria-busy="true"` on the container that is loading and remove it when the content is in.
- Give screen readers one text for the whole placeholder, such as "Memuat rilis…", and hide the boxes from them.
- The pulse stops with `prefers-reduced-motion`.
