forked from Nutlope/llamacoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspinner.tsx
More file actions
44 lines (38 loc) · 1.1 KB
/
Copy pathspinner.tsx
File metadata and controls
44 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use client";
import { ReactNode } from "react";
export default function Spinner({
loading = true,
children,
className = "size-3",
}: {
loading?: boolean;
children?: ReactNode;
className?: string;
}) {
if (!loading) return children;
const spinner = (
<>
<span className={`relative inline-flex ${className}`}>
{Array.from(Array(8).keys()).map((i) => (
<span
key={i}
className="before:bg-current absolute left-[calc(50%-12.5%/2)] top-0 h-[100%] w-[12.5%] animate-[spinner_800ms_linear_infinite] before:block before:h-[30%] before:w-[100%] before:rounded-full"
style={{
transform: `rotate(${45 * i}deg)`,
animationDelay: `calc(-${8 - i} / 8 * 800ms)`,
}}
/>
))}
</span>
</>
);
if (!children) return spinner;
return (
<span className="relative flex h-full items-center justify-center">
<span className="invisible flex">{children}</span>
<span className="absolute inset-0 flex items-center justify-center">
{spinner}
</span>
</span>
);
}