1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import * as React from 'react';
|
4 | import clsx from 'clsx';
|
5 | import PropTypes from 'prop-types';
|
6 | import { alpha, withStyles } from '@material-ui/core/styles';
|
7 | export const styles = theme => ({
|
8 |
|
9 | root: {
|
10 | display: 'block',
|
11 |
|
12 | backgroundColor: alpha(theme.palette.text.primary, theme.palette.type === 'light' ? 0.11 : 0.13),
|
13 | height: '1.2em'
|
14 | },
|
15 |
|
16 |
|
17 | text: {
|
18 | marginTop: 0,
|
19 | marginBottom: 0,
|
20 | height: 'auto',
|
21 | transformOrigin: '0 60%',
|
22 | transform: 'scale(1, 0.60)',
|
23 | borderRadius: theme.shape.borderRadius,
|
24 | '&:empty:before': {
|
25 | content: '"\\00a0"'
|
26 | }
|
27 | },
|
28 |
|
29 |
|
30 | rect: {},
|
31 |
|
32 |
|
33 | circle: {
|
34 | borderRadius: '50%'
|
35 | },
|
36 |
|
37 |
|
38 | pulse: {
|
39 | animation: '$pulse 1.5s ease-in-out 0.5s infinite'
|
40 | },
|
41 | '@keyframes pulse': {
|
42 | '0%': {
|
43 | opacity: 1
|
44 | },
|
45 | '50%': {
|
46 | opacity: 0.4
|
47 | },
|
48 | '100%': {
|
49 | opacity: 1
|
50 | }
|
51 | },
|
52 |
|
53 |
|
54 | wave: {
|
55 | position: 'relative',
|
56 | overflow: 'hidden',
|
57 | '&::after': {
|
58 | animation: '$wave 1.6s linear 0.5s infinite',
|
59 | background: `linear-gradient(90deg, transparent, ${theme.palette.action.hover}, transparent)`,
|
60 | content: '""',
|
61 | position: 'absolute',
|
62 | transform: 'translateX(-100%)',
|
63 |
|
64 | bottom: 0,
|
65 | left: 0,
|
66 | right: 0,
|
67 | top: 0
|
68 | }
|
69 | },
|
70 | '@keyframes wave': {
|
71 | '0%': {
|
72 | transform: 'translateX(-100%)'
|
73 | },
|
74 | '60%': {
|
75 |
|
76 | transform: 'translateX(100%)'
|
77 | },
|
78 | '100%': {
|
79 | transform: 'translateX(100%)'
|
80 | }
|
81 | },
|
82 |
|
83 |
|
84 | withChildren: {
|
85 | '& > *': {
|
86 | visibility: 'hidden'
|
87 | }
|
88 | },
|
89 |
|
90 |
|
91 | fitContent: {
|
92 | maxWidth: 'fit-content'
|
93 | },
|
94 |
|
95 |
|
96 | heightAuto: {
|
97 | height: 'auto'
|
98 | }
|
99 | });
|
100 | const Skeleton = React.forwardRef(function Skeleton(props, ref) {
|
101 | const {
|
102 | animation = 'pulse',
|
103 | classes,
|
104 | className,
|
105 | component: Component = 'span',
|
106 | height,
|
107 | variant = 'text',
|
108 | width
|
109 | } = props,
|
110 | other = _objectWithoutPropertiesLoose(props, ["animation", "classes", "className", "component", "height", "variant", "width"]);
|
111 |
|
112 | const hasChildren = Boolean(other.children);
|
113 | return React.createElement(Component, _extends({
|
114 | ref: ref,
|
115 | className: clsx(classes.root, classes[variant], className, hasChildren && [classes.withChildren, !width && classes.fitContent, !height && classes.heightAuto], animation !== false && classes[animation])
|
116 | }, other, {
|
117 | style: _extends({
|
118 | width,
|
119 | height
|
120 | }, other.style)
|
121 | }));
|
122 | });
|
123 | process.env.NODE_ENV !== "production" ? Skeleton.propTypes = {
|
124 | |
125 |
|
126 |
|
127 |
|
128 | animation: PropTypes.oneOf(['pulse', 'wave', false]),
|
129 |
|
130 | |
131 |
|
132 |
|
133 | children: PropTypes.node,
|
134 |
|
135 | |
136 |
|
137 |
|
138 |
|
139 | classes: PropTypes.object.isRequired,
|
140 |
|
141 | |
142 |
|
143 |
|
144 | className: PropTypes.string,
|
145 |
|
146 | |
147 |
|
148 |
|
149 |
|
150 | component: PropTypes
|
151 |
|
152 | .elementType,
|
153 |
|
154 | |
155 |
|
156 |
|
157 |
|
158 | height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
159 |
|
160 | |
161 |
|
162 |
|
163 | variant: PropTypes.oneOf(['text', 'rect', 'circle']),
|
164 |
|
165 | |
166 |
|
167 |
|
168 |
|
169 | width: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
170 | } : void 0;
|
171 | export default withStyles(styles, {
|
172 | name: 'MuiSkeleton'
|
173 | })(Skeleton); |
\ | No newline at end of file |