-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
37 lines (31 loc) · 958 Bytes
/
index.tsx
File metadata and controls
37 lines (31 loc) · 958 Bytes
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
import type { FC, PropsWithChildren } from 'react';
import { isValidElement } from 'react';
import styles from './index.module.css';
type SkeletonProps = { hide?: boolean; loading?: boolean };
const Skeleton: FC<PropsWithChildren<SkeletonProps>> = ({
children,
hide = false,
loading = true,
}) => {
// This can be used to completely hide the children after the Skeleton has loaded
// If certain criterias do not match. This is useful for conditional rendering without
// changing the actual tree that the Skeleton is wrapping
if (!loading && hide) {
return null;
}
// If we finished loading, we can hide the Skeleton and render the children tree
if (!loading) {
return children;
}
return (
<span
tabIndex={-1}
aria-hidden="true"
className={styles.skeleton}
data-inline-skeleton={isValidElement(children) ? undefined : true}
>
{children}
</span>
);
};
export default Skeleton;