# Skeleton

import { Callout } from "fumadocs-ui/components/callout";
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
import { Step, Steps } from "fumadocs-ui/components/steps";
import { Tabs, Tab } from "fumadocs-ui/components/tabs";
import {
  Badge,
  Card,
  CardContent,
  CardHeader,
  CardTitle,
  Skeleton,
  Table,
  TableBody,
  TableCell,
  TableRow,
} from "@pycolors/ui";
import {
  ArrowRight,
  CheckCircle,
  CircleAlert,
  Circle,
  Clock,
  Inbox,
  LayoutTemplate,
  Rows3,
  Sparkles,
  Table2,
  XCircle,
} from "lucide-react";
import { PreferAvoid } from '@/components/docs/prefer-avoid';
import { DocsLinks } from "@/components/docs/docs-links";
import { DocsFeatureGrid } from "@/components/docs/docs-feature-grid";

<div className="flex flex-wrap items-center gap-2">
  <Badge variant="outline">
    UI
  </Badge>

  <Badge>
    Skeleton
  </Badge>
</div>

## Preserve layout while content loads

The **Skeleton** component is a visual placeholder used during loading states.

It helps:

* preserve layout structure
* reduce layout shift
* improve perceived performance
* communicate that content is expected soon
* keep product surfaces stable while data loads

Skeleton is a **pure UI primitive**. It renders shapes and does not own any loading, fetching, or async logic.

<Callout title="Core idea">
  Skeleton shows the shape of content that is coming. It is not a message, an explanation, or an error state.
</Callout>

### Import

```tsx title="skeleton-import.tsx"
import { Skeleton, type SkeletonProps } from "@pycolors/ui";
```

### Basic usage

Use Skeleton to temporarily replace content while data is loading.

<Tabs items={["Preview", "Code"]}>
  <Tab value="Preview">
    <Preview>
      <div className="space-y-2">
        <Skeleton className="h-4 w-2/3" />

        <Skeleton className="h-4 w-1/2" />
      </div>
    </Preview>
  </Tab>

  <Tab value="Code">
    ```tsx title="basic-skeleton.tsx"
    import { Skeleton } from "@pycolors/ui";

    export function BasicSkeleton() {
      return (
        <div className="space-y-2">
          <Skeleton className="h-4 w-2/3" />
          <Skeleton className="h-4 w-1/2" />
        </div>
      );
    }
    ```
  </Tab>
</Tabs>

## When to use Skeleton

Use Skeleton when the layout is known and real content is expected soon.

<DocsFeatureGrid
  columns={3}
  tone="platform"
  items={[
  {
    title: 'Known layout',
    description:
      'Use when you already know the shape of the final content.',
    icon: LayoutTemplate,
  },
  {
    title: 'Short wait',
    description:
      'Use for loading content that should appear soon.',
    icon: Clock,
  },
  {
    title: 'Data surfaces',
    description:
      'Use in cards, tables, lists, dashboards, and profile sections.',
    icon: Rows3,
  },
]}
/>

### Card loading state

Skeleton composes naturally with surfaces such as Card.

<Tabs items={["Preview", "Code"]}>
  <Tab value="Preview">
    <Preview>
      <Card>
        <CardHeader>
          <Skeleton className="h-5 w-1/3" />

          <Skeleton className="h-4 w-2/3" />
        </CardHeader>

        <CardContent>
          <Skeleton className="h-24 w-full" />
        </CardContent>
      </Card>
    </Preview>
  </Tab>

  <Tab value="Code">
    ```tsx title="card-loading-skeleton.tsx"
    import {
      Card,
      CardHeader,
      CardContent,
      Skeleton,
    } from "@pycolors/ui";

    export function CardLoadingSkeleton() {
      return (
        <Card>
          <CardHeader>
            <Skeleton className="h-5 w-1/3" />
            <Skeleton className="h-4 w-2/3" />
          </CardHeader>
          <CardContent>
            <Skeleton className="h-24 w-full" />
          </CardContent>
        </Card>
      );
    }
    ```
  </Tab>
</Tabs>

### Table loading state

Use Skeleton inside table rows when the table shape is known.

<Tabs items={["Preview", "Code"]}>
  <Tab value="Preview">
    <Preview>
      <Table>
        <TableBody>
          {Array.from({ length: 3 }).map((_, index) => (
                    <TableRow key={index}>
                      <TableCell>
                        <Skeleton className="h-4 w-32" />
                      </TableCell>
                      <TableCell>
                        <Skeleton className="h-4 w-24" />
                      </TableCell>
                      <TableCell>
                        <Skeleton className="h-4 w-16" />
                      </TableCell>
                    </TableRow>
                  ))}
        </TableBody>
      </Table>
    </Preview>
  </Tab>

  <Tab value="Code">
    ```tsx title="table-loading-skeleton.tsx"
    import {
      Skeleton,
      Table,
      TableBody,
      TableRow,
      TableCell,
    } from "@pycolors/ui";

    export function TableLoadingSkeleton() {
      return (
        <Table>
          <TableBody>
            {Array.from({ length: 3 }).map((_, index) => (
              <TableRow key={index}>
                <TableCell>
                  <Skeleton className="h-4 w-32" />
                </TableCell>
                <TableCell>
                  <Skeleton className="h-4 w-24" />
                </TableCell>
                <TableCell>
                  <Skeleton className="h-4 w-16" />
                </TableCell>
              </TableRow>
            ))}
          </TableBody>
        </Table>
      );
    }
    ```
  </Tab>
</Tabs>

### Circular skeleton

Use `circle` for avatar, icon, or round media placeholders.

<Tabs items={["Preview", "Code"]}>
  <Tab value="Preview">
    <Preview>
      <div className="flex items-center gap-3">
        <Skeleton circle className="h-10 w-10" />

        <div className="space-y-2">
          <Skeleton className="h-4 w-32" />

          <Skeleton className="h-3 w-24" />
        </div>
      </div>
    </Preview>
  </Tab>

  <Tab value="Code">
    ```tsx title="circular-skeleton.tsx"
    import { Skeleton } from "@pycolors/ui";

    export function CircularSkeleton() {
      return (
        <div className="flex items-center gap-3">
          <Skeleton circle className="h-10 w-10" />
          <div className="space-y-2">
            <Skeleton className="h-4 w-32" />
            <Skeleton className="h-3 w-24" />
          </div>
        </div>
      );
    }
    ```
  </Tab>
</Tabs>

### Usage patterns

<Steps>
  <Step>
    #### Match the final content shape

    Skeleton should approximate the content it replaces: text lines, avatars, cards, or rows.
  </Step>

  <Step>
    #### Preserve layout height

    Keep the loading state close to the final height to reduce layout shift.
  </Step>

  <Step>
    #### Keep it simple

    Prefer a few clear shapes over a detailed fake version of the final UI.
  </Step>

  <Step>
    #### Replace quickly when data is ready

    Skeleton is temporary. It should disappear as soon as real content can render.
  </Step>

  <Step>
    #### Use another state when loading ends

    Empty, error, and success states need their own UI. Skeleton only represents loading.
  </Step>
</Steps>

## Skeleton vs Spinner vs EmptyState vs Alert

| Situation                                    | Use                       |
| -------------------------------------------- | ------------------------- |
| Layout is known and content is loading       | Skeleton                  |
| Short unknown background task                | Spinner or inline loading |
| Request succeeded but no data exists         | EmptyState                |
| Request failed                               | Alert                     |
| Long-running operation requiring explanation | Dedicated status UI       |
| Blocking app-level loading                   | Route-level loading UI    |

<Callout type="info" title="Decision rule">
  Use Skeleton for expected content. Use EmptyState for valid absence. Use Alert for failure.
</Callout>

## API

#### Props

| Prop        | Type      | Default | Description                 |
| ----------- | --------- | ------- | --------------------------- |
| `circle`    | `boolean` | `false` | Renders a circular skeleton |
| `className` | `string`  | —       | Additional Tailwind classes |

Skeleton also accepts standard HTML `div` props.

```ts title="skeleton-props.ts"
React.HTMLAttributes<HTMLDivElement>
```

### TypeScript types

```ts title="skeleton-types.ts"
export interface SkeletonProps
  extends React.HTMLAttributes<HTMLDivElement> {
  circle?: boolean;
}
```

### Accessibility

Skeleton is visual only.

Guidelines:

* Skeleton always renders with `aria-hidden="true"` — this is a fixed guarantee of the component and cannot be overridden by a passed-through prop
* Skeleton should never receive focus
* Skeleton should not be used as a status message
* Do not announce every placeholder to screen readers
* Provide accessible loading semantics at a higher level when needed
* The pulse animation respects `prefers-reduced-motion` and is disabled automatically for users who request it
* Replace skeletons with real content as soon as possible

<Callout title="Accessibility rule">
  Skeletons describe visual shape for sighted users. They are not content and should not be announced as content.
</Callout>

## Prefer / avoid

<PreferAvoid
  prefer={[
  'matching the final content shape',
  'simple placeholder geometry',
  'stable layout height',
  'table skeletons for table rows',
  'separate empty and error states',
]}
  avoid={[
  'using Skeleton for errors',
  'using Skeleton for empty states',
  'overly detailed fake layouts',
  'long-running skeletons with no explanation',
  'layout shifts between loading and loaded states',
]}
/>

### Product copy guidelines

Skeleton usually does not need copy.

<Tabs items={["Good", "Avoid"]}>
  <Tab value="Good">
    <div className="rounded-2xl border border-border/60 bg-card p-6">
      <div className="text-sm font-medium text-foreground">
        Silent loading shape
      </div>

      <div className="mt-2 text-sm leading-6 text-muted-foreground">
        Let the placeholder communicate that content is coming when the wait is short.
      </div>
    </div>
  </Tab>

  <Tab value="Avoid">
    <div className="rounded-2xl border border-border/60 bg-card p-6">
      <div className="text-sm font-medium text-foreground">
        Too much loading copy
      </div>

      <div className="mt-2 text-sm leading-6 text-muted-foreground">
        Avoid explaining every loading placeholder. Use copy only for longer or unusual waits.
      </div>
    </div>
  </Tab>
</Tabs>

## Common questions

<Accordions type="single">
  <Accordion title="Should Skeleton include text for screen readers?">
    Usually no. Skeleton should be hidden from assistive technologies. If loading status matters, announce it at the parent region level.
  </Accordion>

  <Accordion title="Should I use Skeleton or a spinner?">
    Use Skeleton when the final layout is known. Use a spinner or inline loading state when the shape is unknown or the action is small.
  </Accordion>

  <Accordion title="Can Skeleton be used in tables?">
    Yes. Use skeleton cells inside table rows to preserve table structure while data loads.
  </Accordion>

  <Accordion title="How detailed should a skeleton be?">
    Keep it simple. Match the main structure, not every detail.
  </Accordion>
</Accordions>

## Related

<DocsLinks
  variant="list"
  tone="platform"
  items={[
  {
    title: 'Empty, loading, and error states',
    href: '/docs/guides/empty-loading-error',
    description:
      'Design consistent async states across real product surfaces.',
    icon: LayoutTemplate,
  },
  {
    title: 'Table',
    href: '/docs/ui/table',
    description:
      'Use Skeleton inside table rows for structured loading states.',
    icon: Table2,
  },
  {
    title: 'EmptyState',
    href: '/docs/ui/empty-state',
    description:
      'Use EmptyState when loading succeeded but no data exists.',
    icon: Inbox,
  },
  {
    title: 'Alert',
    href: '/docs/ui/alert',
    description:
      'Use Alert when a request fails or needs important feedback.',
    icon: CircleAlert,
  },
]}
/>