A simple spinner for displaying loading state
1import { cn } from '@/lib/utils';
2import { VariantProps, cva } from 'class-variance-authority';
3import { Loader2 } from 'lucide-react';
4import React from 'react';
5
6const spinnerVariants = cva('flex-col items-center justify-center', {
7 variants: {
8 show: {
9 true: 'flex',
10 false: 'hidden',
11 },
12 },
13 defaultVariants: {
14 show: true,
15 },
16});
17
18const loaderVariants = cva('animate-spin text-primary', {
19 variants: {
20 size: {
21 small: 'size-6',
22 medium: 'size-8',
23 large: 'size-12',
24 },
25 },
26 defaultVariants: {
27 size: 'medium',
28 },
29});
30
31interface SpinnerContentProps
32 extends VariantProps<typeof spinnerVariants>,
33 VariantProps<typeof loaderVariants> {
34 className?: string;
35 children?: React.ReactNode;
36}
37
38export function Spinner({ size, show, children, className }: SpinnerContentProps) {
39 return (
40 <span className={spinnerVariants({ show })}>
41 <Loader2 className={cn(loaderVariants({ size }), className)} />
42 {children}
43 </span>
44 );
45}
46