-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSkeletonLoader.tsx
More file actions
74 lines (67 loc) · 2.11 KB
/
SkeletonLoader.tsx
File metadata and controls
74 lines (67 loc) · 2.11 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React from "react";
export interface SkeletonLoaderProps {
id?: string;
variant?: "text" | "circular" | "rectangular";
textLineCount?: number;
width?: string;
height?: string;
circleSize?: string;
showCircle?: boolean;
showRectangle?: boolean;
showTextLines?: boolean;
enableAnimation?: boolean;
}
export default function SkeletonLoader({
id,
variant = "text",
textLineCount = 3,
width = "100%",
height = "200px",
circleSize = "64px",
showCircle,
showRectangle,
showTextLines,
enableAnimation = true,
}: SkeletonLoaderProps) {
const clampedLineCount = Math.max(1, Math.min(6, textLineCount));
const lineWidths = ["100%", "95%", "90%", "85%", "92%", "88%"];
const shouldShowCircle = showCircle !== undefined ? showCircle : variant === "circular";
const shouldShowRectangle = showRectangle !== undefined ? showRectangle : variant === "rectangular";
const shouldShowTextLines = showTextLines !== undefined ? showTextLines : variant === "text";
return (
<div
id={id}
className={`wf-skeletonloader ${enableAnimation ? "wf-skeletonloader-animated" : ""}`}
style={
{
"--wf-skeletonloader-width": width,
"--wf-skeletonloader-height": height,
"--wf-skeletonloader-circle-size": circleSize,
} as React.CSSProperties
}
>
{shouldShowCircle && (
<div className="wf-skeletonloader-circle" aria-hidden="true"></div>
)}
{shouldShowRectangle && (
<div className="wf-skeletonloader-rectangle" aria-hidden="true"></div>
)}
{shouldShowTextLines && (
<div className="wf-skeletonloader-text-container">
{Array.from({ length: clampedLineCount }).map((_, index) => (
<div
key={index}
className="wf-skeletonloader-text-line"
style={
{
"--wf-skeletonloader-line-width": lineWidths[index % lineWidths.length],
} as React.CSSProperties
}
aria-hidden="true"
></div>
))}
</div>
)}
</div>
);
}