UNPKG

8.91 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.default = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _clsx = _interopRequireDefault(require("clsx"));
12var _propTypes = _interopRequireDefault(require("prop-types"));
13var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
14var _styles = require("../styles");
15var _zeroStyled = require("../zero-styled");
16var _memoTheme = _interopRequireDefault(require("../utils/memoTheme"));
17var _DefaultPropsProvider = require("../DefaultPropsProvider");
18var _skeletonClasses = require("./skeletonClasses");
19var _jsxRuntime = require("react/jsx-runtime");
20const useUtilityClasses = ownerState => {
21 const {
22 classes,
23 variant,
24 animation,
25 hasChildren,
26 width,
27 height
28 } = ownerState;
29 const slots = {
30 root: ['root', variant, animation, hasChildren && 'withChildren', hasChildren && !width && 'fitContent', hasChildren && !height && 'heightAuto']
31 };
32 return (0, _composeClasses.default)(slots, _skeletonClasses.getSkeletonUtilityClass, classes);
33};
34const pulseKeyframe = (0, _zeroStyled.keyframes)`
35 0% {
36 opacity: 1;
37 }
38
39 50% {
40 opacity: 0.4;
41 }
42
43 100% {
44 opacity: 1;
45 }
46`;
47const waveKeyframe = (0, _zeroStyled.keyframes)`
48 0% {
49 transform: translateX(-100%);
50 }
51
52 50% {
53 /* +0.5s of delay between each loop */
54 transform: translateX(100%);
55 }
56
57 100% {
58 transform: translateX(100%);
59 }
60`;
61
62// This implementation is for supporting both Styled-components v4+ and Pigment CSS.
63// A global animation has to be created here for Styled-components v4+ (https://github.com/styled-components/styled-components/blob/main/packages/styled-components/src/utils/errors.md#12).
64// which can be done by checking typeof indeterminate1Keyframe !== 'string' (at runtime, Pigment CSS transform keyframes`` to a string).
65const pulseAnimation = typeof pulseKeyframe !== 'string' ? (0, _zeroStyled.css)`
66 animation: ${pulseKeyframe} 2s ease-in-out 0.5s infinite;
67 ` : null;
68const waveAnimation = typeof waveKeyframe !== 'string' ? (0, _zeroStyled.css)`
69 &::after {
70 animation: ${waveKeyframe} 2s linear 0.5s infinite;
71 }
72 ` : null;
73const SkeletonRoot = (0, _zeroStyled.styled)('span', {
74 name: 'MuiSkeleton',
75 slot: 'Root',
76 overridesResolver: (props, styles) => {
77 const {
78 ownerState
79 } = props;
80 return [styles.root, styles[ownerState.variant], ownerState.animation !== false && styles[ownerState.animation], ownerState.hasChildren && styles.withChildren, ownerState.hasChildren && !ownerState.width && styles.fitContent, ownerState.hasChildren && !ownerState.height && styles.heightAuto];
81 }
82})((0, _memoTheme.default)(({
83 theme
84}) => {
85 const radiusUnit = (0, _styles.unstable_getUnit)(theme.shape.borderRadius) || 'px';
86 const radiusValue = (0, _styles.unstable_toUnitless)(theme.shape.borderRadius);
87 return {
88 display: 'block',
89 // Create a "on paper" color with sufficient contrast retaining the color
90 backgroundColor: theme.vars ? theme.vars.palette.Skeleton.bg : (0, _styles.alpha)(theme.palette.text.primary, theme.palette.mode === 'light' ? 0.11 : 0.13),
91 height: '1.2em',
92 variants: [{
93 props: {
94 variant: 'text'
95 },
96 style: {
97 marginTop: 0,
98 marginBottom: 0,
99 height: 'auto',
100 transformOrigin: '0 55%',
101 transform: 'scale(1, 0.60)',
102 borderRadius: `${radiusValue}${radiusUnit}/${Math.round(radiusValue / 0.6 * 10) / 10}${radiusUnit}`,
103 '&:empty:before': {
104 content: '"\\00a0"'
105 }
106 }
107 }, {
108 props: {
109 variant: 'circular'
110 },
111 style: {
112 borderRadius: '50%'
113 }
114 }, {
115 props: {
116 variant: 'rounded'
117 },
118 style: {
119 borderRadius: (theme.vars || theme).shape.borderRadius
120 }
121 }, {
122 props: ({
123 ownerState
124 }) => ownerState.hasChildren,
125 style: {
126 '& > *': {
127 visibility: 'hidden'
128 }
129 }
130 }, {
131 props: ({
132 ownerState
133 }) => ownerState.hasChildren && !ownerState.width,
134 style: {
135 maxWidth: 'fit-content'
136 }
137 }, {
138 props: ({
139 ownerState
140 }) => ownerState.hasChildren && !ownerState.height,
141 style: {
142 height: 'auto'
143 }
144 }, {
145 props: {
146 animation: 'pulse'
147 },
148 style: pulseAnimation || {
149 animation: `${pulseKeyframe} 2s ease-in-out 0.5s infinite`
150 }
151 }, {
152 props: {
153 animation: 'wave'
154 },
155 style: {
156 position: 'relative',
157 overflow: 'hidden',
158 /* Fix bug in Safari https://bugs.webkit.org/show_bug.cgi?id=68196 */
159 WebkitMaskImage: '-webkit-radial-gradient(white, black)',
160 '&::after': {
161 background: `linear-gradient(
162 90deg,
163 transparent,
164 ${(theme.vars || theme).palette.action.hover},
165 transparent
166 )`,
167 content: '""',
168 position: 'absolute',
169 transform: 'translateX(-100%)' /* Avoid flash during server-side hydration */,
170 bottom: 0,
171 left: 0,
172 right: 0,
173 top: 0
174 }
175 }
176 }, {
177 props: {
178 animation: 'wave'
179 },
180 style: waveAnimation || {
181 '&::after': {
182 animation: `${waveKeyframe} 2s linear 0.5s infinite`
183 }
184 }
185 }]
186 };
187}));
188const Skeleton = /*#__PURE__*/React.forwardRef(function Skeleton(inProps, ref) {
189 const props = (0, _DefaultPropsProvider.useDefaultProps)({
190 props: inProps,
191 name: 'MuiSkeleton'
192 });
193 const {
194 animation = 'pulse',
195 className,
196 component = 'span',
197 height,
198 style,
199 variant = 'text',
200 width,
201 ...other
202 } = props;
203 const ownerState = {
204 ...props,
205 animation,
206 component,
207 variant,
208 hasChildren: Boolean(other.children)
209 };
210 const classes = useUtilityClasses(ownerState);
211 return /*#__PURE__*/(0, _jsxRuntime.jsx)(SkeletonRoot, {
212 as: component,
213 ref: ref,
214 className: (0, _clsx.default)(classes.root, className),
215 ownerState: ownerState,
216 ...other,
217 style: {
218 width,
219 height,
220 ...style
221 }
222 });
223});
224process.env.NODE_ENV !== "production" ? Skeleton.propTypes /* remove-proptypes */ = {
225 // ┌────────────────────────────── Warning ──────────────────────────────┐
226 // │ These PropTypes are generated from the TypeScript type definitions. │
227 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
228 // └─────────────────────────────────────────────────────────────────────┘
229 /**
230 * The animation.
231 * If `false` the animation effect is disabled.
232 * @default 'pulse'
233 */
234 animation: _propTypes.default.oneOf(['pulse', 'wave', false]),
235 /**
236 * Optional children to infer width and height from.
237 */
238 children: _propTypes.default.node,
239 /**
240 * Override or extend the styles applied to the component.
241 */
242 classes: _propTypes.default.object,
243 /**
244 * @ignore
245 */
246 className: _propTypes.default.string,
247 /**
248 * The component used for the root node.
249 * Either a string to use a HTML element or a component.
250 */
251 component: _propTypes.default.elementType,
252 /**
253 * Height of the skeleton.
254 * Useful when you don't want to adapt the skeleton to a text element but for instance a card.
255 */
256 height: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
257 /**
258 * @ignore
259 */
260 style: _propTypes.default.object,
261 /**
262 * The system prop that allows defining system overrides as well as additional CSS styles.
263 */
264 sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
265 /**
266 * The type of content that will be rendered.
267 * @default 'text'
268 */
269 variant: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['circular', 'rectangular', 'rounded', 'text']), _propTypes.default.string]),
270 /**
271 * Width of the skeleton.
272 * Useful when the skeleton is inside an inline element with no width of its own.
273 */
274 width: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
275} : void 0;
276var _default = exports.default = Skeleton;
\No newline at end of file