# Spinner
Animated loading spinner indicator. Uses CSS animations with a rotating circle
and multiple size and color variants.
## Installation
```bash
deno run -A jsr:@lockness/ui add spinner
```
## Usage
```tsx
import { Spinner } from '@lockness/ui/components'
```
## Props
| Prop | Type | Default | Description |
| ------- | ---------------------------------------------------------------------------------------- | --------- | ------------------------------------- |
| size | `sm` \| `md` \| `lg` \| `xl` | `md` | Size of the spinner |
| variant | `primary` \| `secondary` \| `muted` \| `destructive` \| `success` \| `warning` \| `info` | `primary` | Color variant |
| label | `string` | `Loading` | Screen reader label for accessibility |
| class | `string` | - | Additional CSS class names |
| id | `string` | - | Element id attribute |
## Sizes
### Small (sm)
```tsx
// 16px with 2px border
```
### Medium (md) - Default
```tsx
// 24px with 3px border
```
### Large (lg)
```tsx
// 32px with 3px border
```
### Extra Large (xl)
```tsx
// 48px with 4px border
```
### All Sizes
```tsx
```
## Variants
### Primary (default)
Uses the primary theme color.
```tsx
```
### Secondary
Uses the secondary foreground color.
```tsx
```
### Muted
Uses the muted foreground color for subtle loading indicators.
```tsx
```
### Destructive
Red color for error or critical loading states.
```tsx
```
### Success
Green color for success-related loading states.
```tsx
```
### Warning
Yellow/amber color for warning-related loading states.
```tsx
```
### Info
Blue color for informational loading states.
```tsx
```
### All Variants
```tsx
```
## Accessibility
The Spinner includes proper ARIA attributes for screen readers:
- `role="status"` announces the loading state
- `aria-label` provides a descriptive label (customizable via `label` prop)
- Hidden text content for screen readers
```tsx
// Custom accessibility label
```
## Examples
### Loading Button
```tsx
```
### Page Loading State
```tsx
Loading your content...
```
### Inline Loading
```tsx
Updating...
```
### Card Loading State
```tsx
```
## Theming
The Spinner component can be customized using CSS variables. This allows you to
change the appearance of spinners, including size, colors, border width, and
animation duration globally or override specific instances.
### Available CSS Variables
| Variable | Default | Description |
| ------------------------------ | ------------------ | ------------------------------------ |
| `--spinner-size-sm` | `1rem` | Size for small spinner |
| `--spinner-size-md` | `1.5rem` | Size for medium spinner |
| `--spinner-size-lg` | `2rem` | Size for large spinner |
| `--spinner-size-xl` | `3rem` | Size for extra large spinner |
| `--spinner-border-width-sm` | `2px` | Border width for small spinner |
| `--spinner-border-width-md` | `3px` | Border width for medium spinner |
| `--spinner-border-width-lg` | `3px` | Border width for large spinner |
| `--spinner-border-width-xl` | `4px` | Border width for extra large spinner |
| `--spinner-default-color` | `var(--primary)` | Default spinner color |
| `--spinner-success-color` | `hsl(142 76% 36%)` | Success variant color |
| `--spinner-warning-color` | `hsl(38 92% 50%)` | Warning variant color |
| `--spinner-info-color` | `hsl(221 83% 53%)` | Info variant color |
| `--spinner-animation-duration` | `0.75s` | Duration of the rotation animation |
### Theming Examples
#### Global Customization
Customize all spinners by setting CSS variables in your theme:
```css
/* app/view/assets/app.css */
@theme {
--spinner-size-md: 2rem;
--spinner-border-width-md: 4px;
--spinner-default-color: hsl(280 70% 50%);
--spinner-animation-duration: 1s;
}
```
#### Local Overrides
Override CSS variables for specific spinner instances:
```tsx
```
#### Component-Specific Theming
Create themed sections with different spinner styles:
```tsx
```
## Styling
The spinner uses a CSS keyframe animation for smooth rotation:
```css
@keyframes spin {
to {
transform: rotate(360deg);
}
}
```
Customize with additional classes:
```tsx
// Slower animation
// Custom size
```