# Skeleton

Create placeholder content while loading data.

```tsx
import { Skeleton } from '@fluxui-dev/react';

<Skeleton.Group animate="shimmer" className="flex items-center gap-4">
    <Skeleton className="size-10 rounded-full" />

    <div className="flex-1">
        <Skeleton.Line />
        <Skeleton.Line className="w-1/2" />
    </div>
</Skeleton.Group>
```

## Line of text

Create a loading state for a single line of text. `Skeleton.Line` occupies the full line-height of text while rendering a slimmer bar, giving it the visual proportions of real text.

```tsx
<Skeleton.Group animate="shimmer">
    <Skeleton.Line className="mb-2 w-1/4" />
    <Skeleton.Line />
    <Skeleton.Line />
    <Skeleton.Line className="w-3/4" />
</Skeleton.Group>
```

## Animation

Use the `animate` prop to add an animation to the skeleton.

```tsx
<Skeleton />
<Skeleton animate="shimmer" />
<Skeleton animate="pulse" />
```

## Examples

Here are some examples of different ways you can use the skeleton component.

### Table

Use the skeleton component to create a loading state for a table.

```tsx
<Skeleton.Group animate="shimmer">
    <table className="w-full text-left text-sm">
        <thead>
            <tr>
                <th>Customer</th>
                <th>Date</th>
                <th>Status</th>
                <th>Amount</th>
            </tr>
        </thead>

        <tbody>
            {orders.map((order) => (
                <tr key={order}>
                    <td>
                        <div className="flex items-center gap-2">
                            <Skeleton className="rounded-full size-5" />

                            <div className="flex-1">
                                <Skeleton.Line style={{ width: `${50 + Math.random() * 50}%` }} />
                            </div>
                        </div>
                    </td>

                    <td>
                        <Skeleton.Line />
                    </td>

                    <td>
                        <Skeleton.Line />
                    </td>

                    <td>
                        <Skeleton.Line />
                    </td>
                </tr>
            ))}
        </tbody>
    </table>
</Skeleton.Group>
```

### Chart

Use the skeleton component to create a loading state for a chart.

```tsx
import { Card, Heading, Skeleton, Text } from '@fluxui-dev/react';

<Card className="dark:bg-zinc-800">
    <div className="flex flex-col gap-6">
        <div className="flex gap-12">
            <div>
                <Text>Today</Text>

                <Heading size="xl" className="mt-2 tabular-nums">$---</Heading>

                <Text className="mt-2 tabular-nums">-:-- PM</Text>
            </div>

            <div>
                <Text>Yesterday</Text>

                <Heading size="lg" className="mt-2 tabular-nums">$---</Heading>
            </div>
        </div>

        <Skeleton animate="shimmer" className="aspect-[4/1] size-full rounded-lg" />
    </div>
</Card>
```

## Reference

### Skeleton

**Prop:**

- `animate` - Animation style for the skeleton. Options: `shimmer`, `pulse`. Defaults to no animation, or to the enclosing `Skeleton.Group`'s.
- `children` - Content rendered inside the placeholder.

**CSS Variable:**

- `--flux-shimmer-color` - The background color used for the shimmer animation. Defaults to `white` in light mode and zinc-900 in dark mode. Set this to match your page's background color to prevent the shimmer from showing through gaps between skeleton elements.

**Attribute:**

- `data-flux-skeleton` - Applied to the root element for styling and identification.

### Skeleton.Line

**Prop:**

- `size` - Size of the line. Options: `base`, `lg`. Defaults to `base`.
- `animate` - Animation style for the skeleton. Options: `shimmer`, `pulse`. Defaults to no animation. Can be inherited from a parent `Skeleton.Group`.

**Attribute:**

- `data-flux-skeleton-line` - Applied to the root element for styling and identification.

### Skeleton.Group

**Prop:**

- `animate` - Animation style for all skeleton elements within the group. Options: `shimmer`, `pulse`. Defaults to no animation. Inherited by child `Skeleton` and `Skeleton.Line` components that set none of their own.

**Attribute:**

- `data-flux-skeleton-group` - Applied to the root element for styling and identification.
