Spinner

A loading indicator component for showing loading states.

Import

import { Spinner } from '@akitectio/aki-ui'

// TypeScript types
import type { SpinnerProps } from '@akitectio/aki-ui'

Basic Usage

Default Spinner

Loading...
import { Spinner } from '@akitectio/aki-ui'

function BasicSpinner() {
  return <Spinner />
}

Sizes

Different Sizes

Small

Medium

Large

Extra Large

// Different sizes
<Spinner size="sm" />   // Small
<Spinner size="md" />   // Medium (default)
<Spinner size="lg" />   // Large
<Spinner size="xl" />   // Extra Large

Colors

Different Colors

Primary

Success

Warning

Danger

Gray

// Different colors
<Spinner color="primary" />
<Spinner color="success" />
<Spinner color="warning" />
<Spinner color="danger" />
<Spinner color="gray" />

With Label

Spinner with Text

Loading...
Saving changes...
Processing your request...
// With label
<Spinner label="Loading..." />
<Spinner label="Saving changes..." color="success" />
<Spinner label="Processing your request..." color="purple" />

In Button

Loading Button States

function LoadingButton() {
  const [isLoading, setIsLoading] = useState(false)
  
  const handleSubmit = async () => {
    setIsLoading(true)
    try {
      await submitForm()
    } finally {
      setIsLoading(false)
    }
  }
  
  return (
    <button 
      onClick={handleSubmit}
      disabled={isLoading}
      className="flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white rounded"
    >
      {isLoading && <Spinner size="sm" color="white" />}
      <span>{isLoading ? 'Loading...' : 'Save Changes'}</span>
    </button>
  )
}

Overlay Spinner

Full Page Loading

Page Content

This is some page content that would be covered by the loading overlay.

Loading content...

function OverlaySpinner({ isLoading, children }) {
  return (
    <div className="relative">
      {children}
      {isLoading && (
        <div className="absolute inset-0 bg-white bg-opacity-75 flex items-center justify-center">
          <div className="text-center">
            <Spinner size="lg" />
            <p className="mt-2 text-gray-600">Loading content...</p>
          </div>
        </div>
      )}
    </div>
  )
}

API Reference

PropTypeDefaultDescription
size'sm' | 'md' | 'lg' | 'xl''md'Size of the spinner
colorstring'primary'Color of the spinner
labelstring-Accessible label for screen readers
thicknessstring'2px'Thickness of the spinner border
speedstring'0.65s'Animation duration
emptyColorstring'transparent'Color of the empty part

Accessibility

  • Uses role="status" for screen reader announcements
  • Includes aria-label for describing the loading state
  • Respects prefers-reduced-motion for users with motion sensitivity
  • Proper color contrast for visibility
  • Hidden from screen readers when not actively loading