# CircularLoader

Circular loader. Without `value` it is a spinning ring that says something is loading; with `value` it becomes a progress ring that fills up to `value / total`, with optional content in the middle (for example the percentage). It is a `role="progressbar"` named by `label`; `label=""` makes it decorative, for example next to a text that already says "Loading". The ring takes the theme gradient: `--circular-loader-color` sets any color or gradient (`currentColor` matches the surrounding text, for example inside a button). Its state is exposed as `data-indeterminate` for app CSS.

```ts
import { CircularLoader } from '@likable-hair/svelte';
```

Category: simple. Source: `src/lib/components/simple/loaders/CircularLoader.svelte`.

## Examples

### Loading

Without `value` the ring spins. `--circular-loader-size` sets the size and the thickness follows it. The ring takes the theme gradient; `--circular-loader-color` sets any color, and `currentColor` matches the text around it. Next to a text that already says what is happening, `label=""` hides the loader from screen readers.

```svelte
<script lang="ts">
	import { CircularLoader } from '@likable-hair/svelte';
</script>

<div class="rows">
	<div class="row">
		<CircularLoader --circular-loader-size="24px" />
		<CircularLoader />
		<CircularLoader --circular-loader-size="48px" />
		<CircularLoader --circular-loader-size="72px" />
	</div>
	<div class="row">
		<CircularLoader --circular-loader-color="var(--global-color-success)" />
		<CircularLoader --circular-loader-color="var(--global-color-warning)" />
		<span class="status">
			<CircularLoader label="" --circular-loader-size="16px" --circular-loader-color="currentColor" />
			Syncing appointments…
		</span>
	</div>
</div>

<style>
	.rows {
		display: grid;
		gap: 20px;
	}

	.row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 20px;
	}

	.status {
		display: inline-flex;
		align-items: center;
		gap: 8px;
		color: var(--global-color-text-2);
		font-size: 14px;
	}
</style>
```

### Progress

With `value` the ring fills up to `value / total` and the change is animated. The content in the middle comes from `children`, which receives the percentage.

```svelte
<script lang="ts">
	import { Button, CircularLoader } from '@likable-hair/svelte';

	let uploaded = $state(18);
</script>

<div class="row">
	<CircularLoader value={72} label="Monthly goal" --circular-loader-size="72px">
		{#snippet children({ percent })}{Math.round(percent)}%{/snippet}
	</CircularLoader>
	<CircularLoader value={uploaded} total={24} label="Uploaded photos" --circular-loader-size="72px">
		{#snippet children({ value, total })}{value}/{total}{/snippet}
	</CircularLoader>
	<CircularLoader value={uploaded} total={24} label="Uploaded photos" />
	<div class="actions">
		<Button variant="secondary" size="sm" onclick={() => (uploaded = Math.max(0, uploaded - 4))}>−4</Button>
		<Button variant="secondary" size="sm" onclick={() => (uploaded = Math.min(24, uploaded + 4))}>+4</Button>
	</div>
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 24px;
	}

	.actions {
		display: flex;
		gap: 8px;
	}
</style>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number` |  | Progress, from 0 to `total`. Without it the loader spins (indeterminate). |
| `total` | `number` | `100` | Value that fills the ring. With `0` the ring is full. |
| `label` | `string` |  | Accessible name. An empty string makes the loader decorative (hidden from screen readers). Defaults to "Loading", in the language of `locale`. |
| `locale` | `string` |  | BCP 47 locale of the texts: `it` and `en` are built in, other languages fall back to English. Defaults to the one set with `setDefaultLocale`, else `en`. |
| `class` | `string` | `''` | Extra classes on the root element. |

It also accepts the native attributes and events of `<span>` (for example `id`, `title`, `aria-label`, `onkeydown`), which are forwarded to the element.

## Snippets

| Name | Parameters | Description |
| --- | --- | --- |
| `children` | `{ value: number \| undefined; total: number; percent: number }` | Content in the middle of the ring, for example the percentage. Receives the value, the total and the percentage (0–100). |

## CSS variables

For a single instance, pass them as style props: `<CircularLoader --circular-loader-color="tomato">`. The `--circular-loader-default-*` defaults apply to the whole app: override them in `:root` or in a theme.

| Per-instance variable | Default |
| --- | --- |
| `--circular-loader-size` | `--circular-loader-default-size`: `32px` |
| `--circular-loader-value-duration` | `--circular-loader-default-value-duration`: `var(--global-duration-slow)` |
| `--circular-loader-thickness` | `--circular-loader-default-thickness`: `10cqi` |
| `--circular-loader-track-color` | `--circular-loader-default-track-color`: `var(--global-color-surface-3)` |
| `--circular-loader-color` | `--circular-loader-default-color`: `var(--global-gradient)` |
| `--circular-loader-duration` | `--circular-loader-default-duration`: `0.9s` |
| `--circular-loader-content-color` | `--circular-loader-default-content-color`: `var(--global-color-text)` |
| `--circular-loader-content-font-family` | `--circular-loader-default-content-font-family`: `var(--global-font-family-mono)` |
| `--circular-loader-content-font-size` | `--circular-loader-default-content-font-size`: `20cqi` |
| `--circular-loader-content-font-weight` | `--circular-loader-default-content-font-weight`: `500` |
