# Spinner

> Shows that something is loading or saving.

A spinner shows that a short task is running, such as saving a form or loading a list.

## When to use

- Use it inside a button while its action runs, with the button disabled and its label in the present tense ("Menyimpan…").
- Use it for a short wait with a label beside it, such as "Memuat data rilis".
- Use a [Skeleton](https://design.sosialoka.tech/components/skeleton/) when you know the shape of the content that is loading, and a [Progress](https://design.sosialoka.tech/components/progress/) bar when you know how far the task has come.

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

## Anatomy

1. Track
2. Spinning arc

A 16px Lucide `Loader2` icon (`size-4`) turning with `animate-spin`, in the current text color.

## Variants

There is one style. Change the size with a `size-*` class, such as `size-6` for a page that is loading.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `aria-label` | `aria-label` | `label` (Semantics) | text | `Loading` | What is loading, such as "Menyimpan". |
| `className` | `class` | `SizedBox.square(dimension:)` | class | `size-4` | The size. |

## Code

**React**
```tsx
import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"

export default function SpinnerDemo() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <Button disabled>
        <Spinner aria-label="Menyimpan" />
        Menyimpan…
      </Button>
      <div className="flex items-center gap-2 text-sm text-muted-foreground">
        <Spinner aria-label="Memuat data rilis" />
        Memuat data rilis
      </div>
    </div>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"
</script>

<template>
  <div class="flex flex-wrap items-center gap-6">
    <Button disabled>
      <Spinner aria-label="Menyimpan" />
      Menyimpan…
    </Button>
    <div class="flex items-center gap-2 text-sm text-muted-foreground">
      <Spinner aria-label="Memuat data rilis" />
      Memuat data rilis
    </div>
  </div>
</template>
```

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

// shadcn_ui has no spinner: a 16px CircularProgressIndicator in the primary color stands in.
class Spinner extends StatelessWidget {
  const Spinner({super.key, required this.label, this.color});

  final String label;
  final Color? color;

  @override
  Widget build(BuildContext context) {
    return Semantics(
      label: label,
      liveRegion: true,
      child: SizedBox.square(
        dimension: 16,
        child: CircularProgressIndicator(strokeWidth: 2, color: color ?? ShadTheme.of(context).colorScheme.primary),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final theme = ShadTheme.of(context);
    return Wrap(
      spacing: 24,
      runSpacing: 12,
      crossAxisAlignment: WrapCrossAlignment.center,
      children: [
        ShadButton(
          enabled: false,
          leading: Spinner(label: 'Menyimpan', color: theme.colorScheme.primaryForeground),
          child: const Text('Menyimpan…'),
        ),
        Row(
          mainAxisSize: MainAxisSize.min,
          spacing: 8,
          children: [
            const Spinner(label: 'Memuat data rilis'),
            Text('Memuat data rilis', style: theme.textTheme.muted),
          ],
        ),
      ],
    );
  }
}
```

## Install

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

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

## Accessibility

- It has `role="status"`; give it an `aria-label` that says what is happening.
- It keeps turning when `prefers-reduced-motion` is on: the turning is the only sign that the task is still running.
- When the task ends, replace it with the result, such as a toast or the loaded list.
