# Spinner

A compact, indeterminate loading indicator for short waits where the layout of the result is unknown. Prefer a skeleton for content areas, a progress bar when progress is measurable and a button's `loading` state for actions.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-spinner`
- Source: [libs/ui/src/lib/atoms/spinner/spinner.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/atoms/spinner/spinner.ts)

```typescript title="Import"
import { Spinner } from '@vigdx/ui/spinner';
```

## Sizes

`size` is `sm` (1em), `md` (1.5em, default) or `lg` (2em), all relative to the font size, so a spinner also grows with its surrounding text.

```typescript title="spinner-sizes.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Spinner } from '@vigdx/ui/spinner';

@Component({
  selector: 'app-spinner-sizes',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Spinner],
  template: `
    <div class="flex flex-wrap items-end gap-6">
      <vig-spinner size="sm" />
      <vig-spinner />
      <vig-spinner size="lg" />
      <span class="text-3xl"><vig-spinner size="lg" /></span>
    </div>
  `,
})
export class SpinnerSizesDemo {}
```

## Variants

`variant` sets the ring color: `primary` (default), `secondary` for quiet placements, or one of the status hues.

```typescript title="spinner-variants.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Spinner } from '@vigdx/ui/spinner';

@Component({
  selector: 'app-spinner-variants',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Spinner],
  template: `
    <div class="flex flex-wrap items-center gap-6">
      <vig-spinner />
      <vig-spinner variant="secondary" />
      <vig-spinner variant="info" />
      <vig-spinner variant="success" />
      <vig-spinner variant="warning" />
      <vig-spinner variant="error" />
    </div>
  `,
})
export class SpinnerVariantsDemo {}
```

## In context

Next to a visible status, give the spinner the same text as `ariaLabel` and hide the duplicate; as a panel placeholder, center it in the loading region. `ariaLabel` also translates the spinner's name.

```typescript title="spinner-inline.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Spinner } from '@vigdx/ui/spinner';

@Component({
  selector: 'app-spinner-inline',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Spinner],
  template: `
    <div class="flex flex-col gap-4 text-sm text-muted-foreground">
      <p class="flex items-center gap-2">
        <vig-spinner size="sm" variant="secondary" ariaLabel="Syncing calendar" />
        <span aria-hidden="true">Syncing calendar…</span>
      </p>
      <div
        class="flex h-32 max-w-md items-center justify-center rounded-card border border-dashed border-border"
      >
        <vig-spinner size="lg" ariaLabel="Lade Bestellungen" />
      </div>
    </div>
  `,
})
export class SpinnerInlineDemo {}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="spinner"][data-part="ring"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="spinner"]`

| Part | Element | data-state |
| --- | --- | --- |
| `ring` | The spinning ring. |   |

## Accessibility

- The spinner is an indeterminate `role="progressbar"` named by its `ariaLabel` (default: the `spinnerAriaLabel` label, “Loading”). It is not a live region, so it is read when users reach it rather than announced each time it appears.
- Name what is loading, e.g. “Loading orders”. If the start of a long load matters, announce it yourself through a polite status message.
- Render the spinner only while loading. Removing it does not announce completion; show the result or a message instead.
- With `prefers-reduced-motion` the ring keeps turning, much slower (6s per turn): a still ring would read as stalled.

## API

### Spinner

Selector: `vig-spinner` · Kind: component

Indeterminate loading indicator, sized relative to the surrounding font. Exposed as an indeterminate `progressbar` named by its label — a loading indicator is not a live region, so it is not announced each time it appears; announce completion separately if it matters. With reduced motion the ring keeps turning, much slower, so it still reads as busy.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `ariaLabel` | `string \| undefined` | `undefined` | Accessible name; defaults to the `spinnerAriaLabel` label. |
| `size` | `SpinnerSize` | `'md'` | — |
| `variant` | `SpinnerVariant` | `'primary'` | — |
