# Empty, loading and error

> What a page shows when there is nothing yet, while it loads, and when loading fails.

Every list and card has three states besides "full". Show them in the place where the content would be, at the same size, so the page doesn't jump.

## When to use

- **Empty:** the collection has nothing yet, or no row matches the filters.
- **Loading:** the data is on its way. Show a skeleton in the shape of the content.
- **Error:** loading failed. Say what failed and offer a way to try again.

## Empty

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

A title, one sentence about what will appear, and the one action that fills the space. When filters hide every row, the action clears the filters.

## Loading

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

Skeletons in the shape of the rows that are coming, `aria-busy="true"` on the container, and a sentence for screen readers. Skip the skeleton for loads under about 300 ms.

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

/** Loading: skeletons in the shape of the rows that are coming, and a sentence for screen readers. */
export default function LoadingStateDemo() {
  return (
    <div aria-busy="true" className="grid w-full max-w-md gap-4 rounded-xl border border-border bg-card p-4">
      <span className="sr-only">Memuat rilis…</span>
      {[0, 1, 2].map((row) => (
        <div key={row} className="flex items-center gap-3" aria-hidden="true">
          <Skeleton className="size-10 rounded-md" />
          <div className="grid flex-1 gap-2">
            <Skeleton className="h-4 w-2/3" />
            <Skeleton className="h-3 w-1/3" />
          </div>
        </div>
      ))}
    </div>
  )
}
```

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

/** Loading: skeletons in the shape of the rows that are coming, and a sentence for screen readers. */
</script>

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

**Flutter**
```dart
// Loading: placeholder bars in the shape of the rows that are coming, and a label for screen readers.
// shadcn_ui has no skeleton widget; muted boxes with the theme radius do the job.
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

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

  @override
  Widget build(BuildContext context) {
    final muted = ShadTheme.of(context).colorScheme.muted;
    Widget bar(double width, double height) => Container(
      width: width,
      height: height,
      decoration: BoxDecoration(color: muted, borderRadius: BorderRadius.circular(6)),
    );
    return Semantics(
      label: 'Memuat rilis…',
      child: ExcludeSemantics(
        child: ShadCard(
          width: 448,
          child: Column(
            children: [
              for (var row = 0; row < 3; row++)
                Padding(
                  padding: const EdgeInsets.symmetric(vertical: 8),
                  child: Row(
                    children: [
                      bar(40, 40),
                      const SizedBox(width: 12),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [bar(240, 14), const SizedBox(height: 8), bar(120, 12)],
                      ),
                    ],
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}
```

## Error

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

`role="alert"`, what failed, what to do next, and "Coba lagi". The message comes from the backend when there is one.

**React**
```tsx
import { RefreshCwIcon, TriangleAlertIcon } from "lucide-react"
import { Button } from "@/components/ui/button"

/** Loading failed: what failed, what to do next, and a way to try again. */
export default function ErrorStateDemo() {
  return (
    <div
      role="alert"
      className="flex w-full max-w-md flex-col items-center gap-4 rounded-xl border border-border bg-card px-6 py-10 text-center"
    >
      <span className="grid size-12 place-items-center rounded-lg bg-destructive-soft text-destructive">
        <TriangleAlertIcon className="size-6" />
      </span>
      <div className="grid gap-1">
        <h2 className="text-lg font-semibold">Rilis belum bisa dimuat</h2>
        <p className="text-sm text-muted-foreground">Cek koneksimu, lalu coba lagi.</p>
      </div>
      <Button variant="outline">
        <RefreshCwIcon />
        Coba lagi
      </Button>
    </div>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { RefreshCw, TriangleAlert } from "@lucide/vue"
import { Button } from "@/components/ui/button"

/** Loading failed: what failed, what to do next, and a way to try again. */
</script>

<template>
  <div role="alert" class="flex w-full max-w-md flex-col items-center gap-4 rounded-xl border border-border bg-card px-6 py-10 text-center">
    <span class="grid size-12 place-items-center rounded-lg bg-destructive-soft text-destructive">
      <TriangleAlert class="size-6" />
    </span>
    <div class="grid gap-1">
      <h2 class="text-lg font-semibold">Rilis belum bisa dimuat</h2>
      <p class="text-sm text-muted-foreground">Cek koneksimu, lalu coba lagi.</p>
    </div>
    <Button variant="outline"><RefreshCw />Coba lagi</Button>
  </div>
</template>
```

**Flutter**
```dart
// Loading failed: what failed, what to do next, and a way to try again. Announced as a live region.
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:sosialoka_ui/sosialoka_ui.dart';

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

  @override
  Widget build(BuildContext context) {
    final theme = ShadTheme.of(context);
    final c = context.sosialoka;
    return Semantics(
      liveRegion: true,
      child: ConstrainedBox(
        constraints: const BoxConstraints(maxWidth: 448),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              width: 48,
              height: 48,
              decoration: BoxDecoration(color: c.destructiveSoft, borderRadius: BorderRadius.circular(8)),
              child: Icon(LucideIcons.triangleAlert, color: c.destructive),
            ),
            const SizedBox(height: 16),
            Text('Rilis belum bisa dimuat', style: theme.textTheme.large),
            const SizedBox(height: 4),
            Text('Cek koneksimu, lalu coba lagi.', style: theme.textTheme.muted),
            const SizedBox(height: 16),
            ShadButton.outline(
              leading: const Icon(LucideIcons.refreshCw, size: 16),
              onPressed: () {},
              child: const Text('Coba lagi'),
            ),
          ],
        ),
      ),
    );
  }
}
```

## Code for the empty state

**React**
```tsx
import { DiscIcon, PlusIcon } from "lucide-react"
import { Button } from "@/components/ui/button"

/** Nothing here yet: what will appear, in one sentence, and the one action that fills it. */
export default function EmptyStateDemo() {
  return (
    <div className="flex w-full max-w-md flex-col items-center gap-4 rounded-xl border border-dashed border-border px-6 py-10 text-center">
      <span className="grid size-12 place-items-center rounded-lg bg-muted text-muted-foreground">
        <DiscIcon className="size-6" />
      </span>
      <div className="grid gap-1">
        <h2 className="text-lg font-semibold">Belum ada rilis</h2>
        <p className="text-sm text-muted-foreground">Rilis pertamamu akan muncul di sini.</p>
      </div>
      <Button>
        <PlusIcon />
        Rilis baru
      </Button>
    </div>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { Disc, Plus } from "@lucide/vue"
import { Button } from "@/components/ui/button"

/** Nothing here yet: what will appear, in one sentence, and the one action that fills it. */
</script>

<template>
  <div class="flex w-full max-w-md flex-col items-center gap-4 rounded-xl border border-dashed border-border px-6 py-10 text-center">
    <span class="grid size-12 place-items-center rounded-lg bg-muted text-muted-foreground">
      <Disc class="size-6" />
    </span>
    <div class="grid gap-1">
      <h2 class="text-lg font-semibold">Belum ada rilis</h2>
      <p class="text-sm text-muted-foreground">Rilis pertamamu akan muncul di sini.</p>
    </div>
    <Button><Plus />Rilis baru</Button>
  </div>
</template>
```

**Flutter**
```dart
// Nothing here yet: what will appear, in one sentence, and the one action that fills it.
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

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

  @override
  Widget build(BuildContext context) {
    final theme = ShadTheme.of(context);
    return ConstrainedBox(
      constraints: const BoxConstraints(maxWidth: 448),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            width: 48,
            height: 48,
            decoration: BoxDecoration(color: theme.colorScheme.muted, borderRadius: BorderRadius.circular(8)),
            child: Icon(LucideIcons.disc, color: theme.colorScheme.mutedForeground),
          ),
          const SizedBox(height: 16),
          Text('Belum ada rilis', style: theme.textTheme.large),
          const SizedBox(height: 4),
          Text('Rilis pertamamu akan muncul di sini.', style: theme.textTheme.muted),
          const SizedBox(height: 16),
          ShadButton(
            leading: const Icon(LucideIcons.plus, size: 16),
            onPressed: () {},
            child: const Text('Rilis baru'),
          ),
        ],
      ),
    );
  }
}
```

## Built from

[Button](https://design.sosialoka.tech/components/button/) and the Skeleton that installs with [Sidebar](https://design.sosialoka.tech/components/sidebar/).

## Flutter

shadcn_ui has no skeleton widget. Muted boxes with the theme radius do the job. Wrap the error state in `Semantics(liveRegion: true)`.
