UNPKG

15.3 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 _propTypes = _interopRequireDefault(require("prop-types"));
12var _clsx = _interopRequireDefault(require("clsx"));
13var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
14var _colorManipulator = require("@mui/system/colorManipulator");
15var _RtlProvider = require("@mui/system/RtlProvider");
16var _zeroStyled = require("../zero-styled");
17var _memoTheme = _interopRequireDefault(require("../utils/memoTheme"));
18var _createSimplePaletteValueFilter = _interopRequireDefault(require("../utils/createSimplePaletteValueFilter"));
19var _DefaultPropsProvider = require("../DefaultPropsProvider");
20var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
21var _linearProgressClasses = require("./linearProgressClasses");
22var _jsxRuntime = require("react/jsx-runtime");
23const TRANSITION_DURATION = 4; // seconds
24const indeterminate1Keyframe = (0, _zeroStyled.keyframes)`
25 0% {
26 left: -35%;
27 right: 100%;
28 }
29
30 60% {
31 left: 100%;
32 right: -90%;
33 }
34
35 100% {
36 left: 100%;
37 right: -90%;
38 }
39`;
40
41// This implementation is for supporting both Styled-components v4+ and Pigment CSS.
42// 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).
43// which can be done by checking typeof indeterminate1Keyframe !== 'string' (at runtime, Pigment CSS transform keyframes`` to a string).
44const indeterminate1Animation = typeof indeterminate1Keyframe !== 'string' ? (0, _zeroStyled.css)`
45 animation: ${indeterminate1Keyframe} 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
46 ` : null;
47const indeterminate2Keyframe = (0, _zeroStyled.keyframes)`
48 0% {
49 left: -200%;
50 right: 100%;
51 }
52
53 60% {
54 left: 107%;
55 right: -8%;
56 }
57
58 100% {
59 left: 107%;
60 right: -8%;
61 }
62`;
63const indeterminate2Animation = typeof indeterminate2Keyframe !== 'string' ? (0, _zeroStyled.css)`
64 animation: ${indeterminate2Keyframe} 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) 1.15s infinite;
65 ` : null;
66const bufferKeyframe = (0, _zeroStyled.keyframes)`
67 0% {
68 opacity: 1;
69 background-position: 0 -23px;
70 }
71
72 60% {
73 opacity: 0;
74 background-position: 0 -23px;
75 }
76
77 100% {
78 opacity: 1;
79 background-position: -200px -23px;
80 }
81`;
82const bufferAnimation = typeof bufferKeyframe !== 'string' ? (0, _zeroStyled.css)`
83 animation: ${bufferKeyframe} 3s infinite linear;
84 ` : null;
85const useUtilityClasses = ownerState => {
86 const {
87 classes,
88 variant,
89 color
90 } = ownerState;
91 const slots = {
92 root: ['root', `color${(0, _capitalize.default)(color)}`, variant],
93 dashed: ['dashed', `dashedColor${(0, _capitalize.default)(color)}`],
94 bar1: ['bar', `barColor${(0, _capitalize.default)(color)}`, (variant === 'indeterminate' || variant === 'query') && 'bar1Indeterminate', variant === 'determinate' && 'bar1Determinate', variant === 'buffer' && 'bar1Buffer'],
95 bar2: ['bar', variant !== 'buffer' && `barColor${(0, _capitalize.default)(color)}`, variant === 'buffer' && `color${(0, _capitalize.default)(color)}`, (variant === 'indeterminate' || variant === 'query') && 'bar2Indeterminate', variant === 'buffer' && 'bar2Buffer']
96 };
97 return (0, _composeClasses.default)(slots, _linearProgressClasses.getLinearProgressUtilityClass, classes);
98};
99const getColorShade = (theme, color) => {
100 if (theme.vars) {
101 return theme.vars.palette.LinearProgress[`${color}Bg`];
102 }
103 return theme.palette.mode === 'light' ? (0, _colorManipulator.lighten)(theme.palette[color].main, 0.62) : (0, _colorManipulator.darken)(theme.palette[color].main, 0.5);
104};
105const LinearProgressRoot = (0, _zeroStyled.styled)('span', {
106 name: 'MuiLinearProgress',
107 slot: 'Root',
108 overridesResolver: (props, styles) => {
109 const {
110 ownerState
111 } = props;
112 return [styles.root, styles[`color${(0, _capitalize.default)(ownerState.color)}`], styles[ownerState.variant]];
113 }
114})((0, _memoTheme.default)(({
115 theme
116}) => ({
117 position: 'relative',
118 overflow: 'hidden',
119 display: 'block',
120 height: 4,
121 // Fix Safari's bug during composition of different paint.
122 zIndex: 0,
123 '@media print': {
124 colorAdjust: 'exact'
125 },
126 variants: [...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => ({
127 props: {
128 color
129 },
130 style: {
131 backgroundColor: getColorShade(theme, color)
132 }
133 })), {
134 props: ({
135 ownerState
136 }) => ownerState.color === 'inherit' && ownerState.variant !== 'buffer',
137 style: {
138 '&::before': {
139 content: '""',
140 position: 'absolute',
141 left: 0,
142 top: 0,
143 right: 0,
144 bottom: 0,
145 backgroundColor: 'currentColor',
146 opacity: 0.3
147 }
148 }
149 }, {
150 props: {
151 variant: 'buffer'
152 },
153 style: {
154 backgroundColor: 'transparent'
155 }
156 }, {
157 props: {
158 variant: 'query'
159 },
160 style: {
161 transform: 'rotate(180deg)'
162 }
163 }]
164})));
165const LinearProgressDashed = (0, _zeroStyled.styled)('span', {
166 name: 'MuiLinearProgress',
167 slot: 'Dashed',
168 overridesResolver: (props, styles) => {
169 const {
170 ownerState
171 } = props;
172 return [styles.dashed, styles[`dashedColor${(0, _capitalize.default)(ownerState.color)}`]];
173 }
174})((0, _memoTheme.default)(({
175 theme
176}) => ({
177 position: 'absolute',
178 marginTop: 0,
179 height: '100%',
180 width: '100%',
181 backgroundSize: '10px 10px',
182 backgroundPosition: '0 -23px',
183 variants: [{
184 props: {
185 color: 'inherit'
186 },
187 style: {
188 opacity: 0.3,
189 backgroundImage: `radial-gradient(currentColor 0%, currentColor 16%, transparent 42%)`
190 }
191 }, ...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => {
192 const backgroundColor = getColorShade(theme, color);
193 return {
194 props: {
195 color
196 },
197 style: {
198 backgroundImage: `radial-gradient(${backgroundColor} 0%, ${backgroundColor} 16%, transparent 42%)`
199 }
200 };
201 })]
202})), bufferAnimation || {
203 // At runtime for Pigment CSS, `bufferAnimation` will be null and the generated keyframe will be used.
204 animation: `${bufferKeyframe} 3s infinite linear`
205});
206const LinearProgressBar1 = (0, _zeroStyled.styled)('span', {
207 name: 'MuiLinearProgress',
208 slot: 'Bar1',
209 overridesResolver: (props, styles) => {
210 const {
211 ownerState
212 } = props;
213 return [styles.bar, styles[`barColor${(0, _capitalize.default)(ownerState.color)}`], (ownerState.variant === 'indeterminate' || ownerState.variant === 'query') && styles.bar1Indeterminate, ownerState.variant === 'determinate' && styles.bar1Determinate, ownerState.variant === 'buffer' && styles.bar1Buffer];
214 }
215})((0, _memoTheme.default)(({
216 theme
217}) => ({
218 width: '100%',
219 position: 'absolute',
220 left: 0,
221 bottom: 0,
222 top: 0,
223 transition: 'transform 0.2s linear',
224 transformOrigin: 'left',
225 variants: [{
226 props: {
227 color: 'inherit'
228 },
229 style: {
230 backgroundColor: 'currentColor'
231 }
232 }, ...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => ({
233 props: {
234 color
235 },
236 style: {
237 backgroundColor: (theme.vars || theme).palette[color].main
238 }
239 })), {
240 props: {
241 variant: 'determinate'
242 },
243 style: {
244 transition: `transform .${TRANSITION_DURATION}s linear`
245 }
246 }, {
247 props: {
248 variant: 'buffer'
249 },
250 style: {
251 zIndex: 1,
252 transition: `transform .${TRANSITION_DURATION}s linear`
253 }
254 }, {
255 props: ({
256 ownerState
257 }) => ownerState.variant === 'indeterminate' || ownerState.variant === 'query',
258 style: {
259 width: 'auto'
260 }
261 }, {
262 props: ({
263 ownerState
264 }) => ownerState.variant === 'indeterminate' || ownerState.variant === 'query',
265 style: indeterminate1Animation || {
266 animation: `${indeterminate1Keyframe} 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite`
267 }
268 }]
269})));
270const LinearProgressBar2 = (0, _zeroStyled.styled)('span', {
271 name: 'MuiLinearProgress',
272 slot: 'Bar2',
273 overridesResolver: (props, styles) => {
274 const {
275 ownerState
276 } = props;
277 return [styles.bar, styles[`barColor${(0, _capitalize.default)(ownerState.color)}`], (ownerState.variant === 'indeterminate' || ownerState.variant === 'query') && styles.bar2Indeterminate, ownerState.variant === 'buffer' && styles.bar2Buffer];
278 }
279})((0, _memoTheme.default)(({
280 theme
281}) => ({
282 width: '100%',
283 position: 'absolute',
284 left: 0,
285 bottom: 0,
286 top: 0,
287 transition: 'transform 0.2s linear',
288 transformOrigin: 'left',
289 variants: [...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => ({
290 props: {
291 color
292 },
293 style: {
294 '--LinearProgressBar2-barColor': (theme.vars || theme).palette[color].main
295 }
296 })), {
297 props: ({
298 ownerState
299 }) => ownerState.variant !== 'buffer' && ownerState.color !== 'inherit',
300 style: {
301 backgroundColor: 'var(--LinearProgressBar2-barColor, currentColor)'
302 }
303 }, {
304 props: ({
305 ownerState
306 }) => ownerState.variant !== 'buffer' && ownerState.color === 'inherit',
307 style: {
308 backgroundColor: 'currentColor'
309 }
310 }, {
311 props: {
312 color: 'inherit'
313 },
314 style: {
315 opacity: 0.3
316 }
317 }, ...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => ({
318 props: {
319 color,
320 variant: 'buffer'
321 },
322 style: {
323 backgroundColor: getColorShade(theme, color),
324 transition: `transform .${TRANSITION_DURATION}s linear`
325 }
326 })), {
327 props: ({
328 ownerState
329 }) => ownerState.variant === 'indeterminate' || ownerState.variant === 'query',
330 style: {
331 width: 'auto'
332 }
333 }, {
334 props: ({
335 ownerState
336 }) => ownerState.variant === 'indeterminate' || ownerState.variant === 'query',
337 style: indeterminate2Animation || {
338 animation: `${indeterminate2Keyframe} 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) 1.15s infinite`
339 }
340 }]
341})));
342
343/**
344 * ## ARIA
345 *
346 * If the progress bar is describing the loading progress of a particular region of a page,
347 * you should use `aria-describedby` to point to the progress bar, and set the `aria-busy`
348 * attribute to `true` on that region until it has finished loading.
349 */
350const LinearProgress = /*#__PURE__*/React.forwardRef(function LinearProgress(inProps, ref) {
351 const props = (0, _DefaultPropsProvider.useDefaultProps)({
352 props: inProps,
353 name: 'MuiLinearProgress'
354 });
355 const {
356 className,
357 color = 'primary',
358 value,
359 valueBuffer,
360 variant = 'indeterminate',
361 ...other
362 } = props;
363 const ownerState = {
364 ...props,
365 color,
366 variant
367 };
368 const classes = useUtilityClasses(ownerState);
369 const isRtl = (0, _RtlProvider.useRtl)();
370 const rootProps = {};
371 const inlineStyles = {
372 bar1: {},
373 bar2: {}
374 };
375 if (variant === 'determinate' || variant === 'buffer') {
376 if (value !== undefined) {
377 rootProps['aria-valuenow'] = Math.round(value);
378 rootProps['aria-valuemin'] = 0;
379 rootProps['aria-valuemax'] = 100;
380 let transform = value - 100;
381 if (isRtl) {
382 transform = -transform;
383 }
384 inlineStyles.bar1.transform = `translateX(${transform}%)`;
385 } else if (process.env.NODE_ENV !== 'production') {
386 console.error('MUI: You need to provide a value prop ' + 'when using the determinate or buffer variant of LinearProgress .');
387 }
388 }
389 if (variant === 'buffer') {
390 if (valueBuffer !== undefined) {
391 let transform = (valueBuffer || 0) - 100;
392 if (isRtl) {
393 transform = -transform;
394 }
395 inlineStyles.bar2.transform = `translateX(${transform}%)`;
396 } else if (process.env.NODE_ENV !== 'production') {
397 console.error('MUI: You need to provide a valueBuffer prop ' + 'when using the buffer variant of LinearProgress.');
398 }
399 }
400 return /*#__PURE__*/(0, _jsxRuntime.jsxs)(LinearProgressRoot, {
401 className: (0, _clsx.default)(classes.root, className),
402 ownerState: ownerState,
403 role: "progressbar",
404 ...rootProps,
405 ref: ref,
406 ...other,
407 children: [variant === 'buffer' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(LinearProgressDashed, {
408 className: classes.dashed,
409 ownerState: ownerState
410 }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(LinearProgressBar1, {
411 className: classes.bar1,
412 ownerState: ownerState,
413 style: inlineStyles.bar1
414 }), variant === 'determinate' ? null : /*#__PURE__*/(0, _jsxRuntime.jsx)(LinearProgressBar2, {
415 className: classes.bar2,
416 ownerState: ownerState,
417 style: inlineStyles.bar2
418 })]
419 });
420});
421process.env.NODE_ENV !== "production" ? LinearProgress.propTypes /* remove-proptypes */ = {
422 // ┌────────────────────────────── Warning ──────────────────────────────┐
423 // │ These PropTypes are generated from the TypeScript type definitions. │
424 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
425 // └─────────────────────────────────────────────────────────────────────┘
426 /**
427 * Override or extend the styles applied to the component.
428 */
429 classes: _propTypes.default.object,
430 /**
431 * @ignore
432 */
433 className: _propTypes.default.string,
434 /**
435 * The color of the component.
436 * It supports both default and custom theme colors, which can be added as shown in the
437 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
438 * @default 'primary'
439 */
440 color: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['inherit', 'primary', 'secondary']), _propTypes.default.string]),
441 /**
442 * The system prop that allows defining system overrides as well as additional CSS styles.
443 */
444 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]),
445 /**
446 * The value of the progress indicator for the determinate and buffer variants.
447 * Value between 0 and 100.
448 */
449 value: _propTypes.default.number,
450 /**
451 * The value for the buffer variant.
452 * Value between 0 and 100.
453 */
454 valueBuffer: _propTypes.default.number,
455 /**
456 * The variant to use.
457 * Use indeterminate or query when there is no progress value.
458 * @default 'indeterminate'
459 */
460 variant: _propTypes.default.oneOf(['buffer', 'determinate', 'indeterminate', 'query'])
461} : void 0;
462var _default = exports.default = LinearProgress;
\No newline at end of file