-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkeleton.tsx
More file actions
61 lines (56 loc) · 1.48 KB
/
Skeleton.tsx
File metadata and controls
61 lines (56 loc) · 1.48 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
import {
Skeleton as MuiSkeleton,
type SkeletonProps as MuiSkeletonProps,
} from "@mui/material";
import type { ComponentState } from "@/index";
import type { ReactElement } from "react";
interface SkeletonState extends Omit<ComponentState, "type" | "children"> {
variant?: MuiSkeletonProps["variant"];
width?: MuiSkeletonProps["width"];
height?: MuiSkeletonProps["height"];
animation?: MuiSkeletonProps["animation"];
opacity?: number;
isLoading: boolean;
children?: ReactElement;
}
export interface SkeletonProps extends SkeletonState {}
export const Skeleton = ({
id,
style,
children,
isLoading,
...props
}: SkeletonProps) => {
// Set default values if not available
const opacity: number = props.opacity ?? 0.7;
props.width = props.width ?? "100%";
props.height = props.height ?? "100%";
return (
<div style={{ position: "relative", ...style }} id={id}>
{children}
{isLoading && (
<div
style={{
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: `rgba(255, 255, 255, ${opacity})`,
display: "flex",
justifyContent: "center",
alignItems: "center",
zIndex: 1,
}}
>
<MuiSkeleton
id={id}
style={{ transform: "none" }}
{...props}
data-testid="skeleton-test-id"
/>
</div>
)}
</div>
);
};