Loading States
Various loading animations and indicators
Installation
Basic Usage
1import { Loader } from "@/components/ui/loader";2 3function MyComponent() {4 return (5 <div>6 <Loader variant="spinner" size="md" />7 </div>8 );9}
Variants
A classic spinning loader with customizable colors.
1<Loader variant="spinner" />
Bouncing dots that animate in a wave pattern.
1<Loader variant="bounce" />
A pulsing circle with fade effects.
1<Loader variant="pulse" />
A morphing loader that changes shape and color.
1<Loader variant="morph" />
Sizes
Loaders come in four sizes:
1<Loader size="sm" /> // Small2<Loader size="md" /> // Medium (default)3<Loader size="lg" /> // Large4<Loader size="xl" /> // Extra large
Props
Examples
1function LoadingButton() {2 const [isLoading, setIsLoading] = useState(false);3 4 return (5 <Button onClick={() => setIsLoading(true)} disabled={isLoading}>6 {isLoading ? (7 <>8 <Loader size="sm" className="mr-2" />9 Loading...10 </>11 ) : (12 "Submit"13 )}14 </Button>15 );16}
Best Practices
- Appropriate Size: Use smaller loaders for buttons, larger for page loads
- Consistent Placement: Keep loaders in consistent locations across your app
- Meaningful Text: Include descriptive text with loaders when appropriate
- Accessibility: Always provide ARIA labels for screen readers
- Performance: Use lightweight animations for better performance
Accessibility
- ARIA Labels: Proper labels for screen readers
- Reduced Motion: Respect user's motion preferences
- Focus Management: Proper focus handling during loading states
- Color Contrast: Sufficient contrast for visibility
Performance Tips
- CSS Animations: Use CSS animations when possible for better performance
- Reduced Motion: Respect prefers-reduced-motion media query
- Optimized Bundles: Tree-shake unused loader variants
- Lazy Loading: Load heavy animations only when needed
Troubleshooting
Check if Framer Motion is properly installed and the component is wrapped in a motion provider.
Consider using CSS-only animations for better performance on low-end devices.
Ensure proper ARIA labels and test with screen readers.
Check for conflicting CSS classes or Tailwind CSS purging issues.