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