/
index.tsx
94 lines (87 loc) · 2.53 KB
/
index.tsx
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import * as React from 'react';
import {useSpring, animated} from '@twilio-paste/animation-library';
import {css, styled} from '@twilio-paste/styling-library';
import {Box, safelySpreadBoxProps} from '@twilio-paste/box';
import type {BoxElementProps} from '@twilio-paste/box';
import type {LayoutProps, BorderRadiusProps} from '@twilio-paste/style-props';
const AnimatedSkeleton = animated(Box);
const StyledAnimatedSkeleton = styled(AnimatedSkeleton)(() =>
css({
background: `linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3) 40%, rgba(255, 255, 255, 0.3) 60%, transparent)`,
})
);
export interface SkeletonLoaderProps
extends React.HTMLAttributes<HTMLDivElement>,
Pick<BoxElementProps, 'element'>,
Omit<LayoutProps, 'verticalAlign'>,
BorderRadiusProps {}
const SkeletonLoader = React.forwardRef<HTMLDivElement, SkeletonLoaderProps>(
(
{
borderBottomLeftRadius,
borderBottomRightRadius,
borderRadius = 'borderRadius20',
borderTopLeftRadius,
borderTopRightRadius,
element = 'SKELETON_LOADER',
display,
height = 'sizeIcon20',
maxHeight,
maxWidth,
minHeight,
minWidth,
size = null,
width = null,
...props
},
ref
) => {
const animatedSkeletonStyles = useSpring({
loop: {delay: 700, reset: true},
from: {translateX: '-100%', skew: '155deg'},
to: {translateX: '100%', skew: '155deg'},
config: {
mass: 0.1,
tension: 80,
friction: 50,
},
});
return (
<Box
{...safelySpreadBoxProps(props)}
aria-busy="true"
backgroundColor="colorBackgroundStrong"
borderBottomLeftRadius={borderBottomLeftRadius}
borderBottomRightRadius={borderBottomRightRadius}
borderRadius={borderRadius}
borderTopLeftRadius={borderTopLeftRadius}
borderTopRightRadius={borderTopRightRadius}
display={display}
element={element}
height={height}
maxHeight={maxHeight}
maxWidth={maxWidth}
minHeight={minHeight}
minWidth={minWidth}
overflow="hidden"
pointerEvents="none"
position="relative"
userSelect="none"
size={size}
width={width}
ref={ref}
>
<StyledAnimatedSkeleton
bottom={0}
left={0}
position="absolute"
right={0}
top={0}
style={animatedSkeletonStyles}
/>
</Box>
);
}
);
SkeletonLoader.displayName = 'SkeletonLoader';
export {SkeletonLoader};