Spinner
A composable, accessible Spinner component for modern React applications.
tsx
import { Spinner } from '@nofinite/nui';Interactive Preview
Loading preview...
A visual loading indicator that communicates ongoing asynchronous activity. Designed for inline usage, button loading states, and page-level placeholders. Supports multiple sizes, color variants, and accessible status semantics.
Usage
Basic usage
tsx
import { Spinner } from '@nofinite/nui';
<Spinner />;Custom size
tsx
<Spinner size="lg" />Variant usage
tsx
<Spinner variant="muted" />
<Spinner variant="inverse" />Button loading pattern
tsx
<button disabled>
<Spinner size="sm" variant="inverse" />
</button>Variants
Size variants
tsx
<Spinner size="sm" />
<Spinner size="md" />
<Spinner size="lg" />
<Spinner size="xl" />Color variants
tsx
<Spinner variant="primary" />
<Spinner variant="muted" />
<Spinner variant="inverse" />Available variants
- Primary
- Muted
- Inverse
- Small
- Medium
- Large
- Extra large
Guidelines
- Use
primaryfor component-level loading - Use
mutedfor page-level or background loading - Use
inversefor dark surfaces and buttons - Prefer smaller sizes for inline usage
- Avoid oversized spinners in dense layouts
States
- Idle animation
- Reduced motion
- Button loading
- Inline loading
- Page loading
Accessibility
- Uses
role="status"for assistive announcement - Hidden descriptive label ensures screen reader clarity
- Supports custom loading message via
label - Respects
prefers-reduced-motion - Color variants maintain sufficient contrast
Best Practices
Do
- Pair spinner with contextual loading text for long operations
- Use inverse spinner inside buttons or dark surfaces
- Prefer skeleton loaders for complex layout loading
- Use spinner sparingly to avoid perceived latency
- Combine with optimistic UI where possible
Don’t
- Show spinner for ultra-fast operations (less than 300ms)
- Stack multiple spinners in one region
- Use spinner as the only feedback for long processes
- Place spinner without context in large empty layouts
- Ignore reduced motion preferences
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
size | enum | md | The predefined size of the spinner. Defaults to 'md'. |
variant | enum | primary | The color theme variant. Defaults to 'primary'. |
label | string | Loading... | WAI-ARIA label read by screen readers. Defaults to 'Loading...'. |