UNPKG

12.9 kBJavaScriptView Raw
1'use client';
2
3import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4import _extends from "@babel/runtime/helpers/esm/extends";
5import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
6var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
7import * as React from 'react';
8import PropTypes from 'prop-types';
9import clsx from 'clsx';
10import composeClasses from '@mui/utils/composeClasses';
11import { keyframes, css } from '@mui/system';
12import { darken, lighten } from '@mui/system/colorManipulator';
13import { useRtl } from '@mui/system/RtlProvider';
14import capitalize from '../utils/capitalize';
15import styled from '../styles/styled';
16import { useDefaultProps } from '../DefaultPropsProvider';
17import { getLinearProgressUtilityClass } from './linearProgressClasses';
18import { jsx as _jsx } from "react/jsx-runtime";
19import { jsxs as _jsxs } from "react/jsx-runtime";
20var TRANSITION_DURATION = 4; // seconds
21var indeterminate1Keyframe = keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n left: -35%;\n right: 100%;\n }\n\n 60% {\n left: 100%;\n right: -90%;\n }\n\n 100% {\n left: 100%;\n right: -90%;\n }\n"])));
22var indeterminate2Keyframe = keyframes(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n 0% {\n left: -200%;\n right: 100%;\n }\n\n 60% {\n left: 107%;\n right: -8%;\n }\n\n 100% {\n left: 107%;\n right: -8%;\n }\n"])));
23var bufferKeyframe = keyframes(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n 0% {\n opacity: 1;\n background-position: 0 -23px;\n }\n\n 60% {\n opacity: 0;\n background-position: 0 -23px;\n }\n\n 100% {\n opacity: 1;\n background-position: -200px -23px;\n }\n"])));
24var useUtilityClasses = function useUtilityClasses(ownerState) {
25 var classes = ownerState.classes,
26 variant = ownerState.variant,
27 color = ownerState.color;
28 var slots = {
29 root: ['root', "color".concat(capitalize(color)), variant],
30 dashed: ['dashed', "dashedColor".concat(capitalize(color))],
31 bar1: ['bar', "barColor".concat(capitalize(color)), (variant === 'indeterminate' || variant === 'query') && 'bar1Indeterminate', variant === 'determinate' && 'bar1Determinate', variant === 'buffer' && 'bar1Buffer'],
32 bar2: ['bar', variant !== 'buffer' && "barColor".concat(capitalize(color)), variant === 'buffer' && "color".concat(capitalize(color)), (variant === 'indeterminate' || variant === 'query') && 'bar2Indeterminate', variant === 'buffer' && 'bar2Buffer']
33 };
34 return composeClasses(slots, getLinearProgressUtilityClass, classes);
35};
36var getColorShade = function getColorShade(theme, color) {
37 if (color === 'inherit') {
38 return 'currentColor';
39 }
40 if (theme.vars) {
41 return theme.vars.palette.LinearProgress["".concat(color, "Bg")];
42 }
43 return theme.palette.mode === 'light' ? lighten(theme.palette[color].main, 0.62) : darken(theme.palette[color].main, 0.5);
44};
45var LinearProgressRoot = styled('span', {
46 name: 'MuiLinearProgress',
47 slot: 'Root',
48 overridesResolver: function overridesResolver(props, styles) {
49 var ownerState = props.ownerState;
50 return [styles.root, styles["color".concat(capitalize(ownerState.color))], styles[ownerState.variant]];
51 }
52})(function (_ref) {
53 var ownerState = _ref.ownerState,
54 theme = _ref.theme;
55 return _extends({
56 position: 'relative',
57 overflow: 'hidden',
58 display: 'block',
59 height: 4,
60 zIndex: 0,
61 // Fix Safari's bug during composition of different paint.
62 '@media print': {
63 colorAdjust: 'exact'
64 },
65 backgroundColor: getColorShade(theme, ownerState.color)
66 }, ownerState.color === 'inherit' && ownerState.variant !== 'buffer' && {
67 backgroundColor: 'none',
68 '&::before': {
69 content: '""',
70 position: 'absolute',
71 left: 0,
72 top: 0,
73 right: 0,
74 bottom: 0,
75 backgroundColor: 'currentColor',
76 opacity: 0.3
77 }
78 }, ownerState.variant === 'buffer' && {
79 backgroundColor: 'transparent'
80 }, ownerState.variant === 'query' && {
81 transform: 'rotate(180deg)'
82 });
83});
84var LinearProgressDashed = styled('span', {
85 name: 'MuiLinearProgress',
86 slot: 'Dashed',
87 overridesResolver: function overridesResolver(props, styles) {
88 var ownerState = props.ownerState;
89 return [styles.dashed, styles["dashedColor".concat(capitalize(ownerState.color))]];
90 }
91})(function (_ref2) {
92 var ownerState = _ref2.ownerState,
93 theme = _ref2.theme;
94 var backgroundColor = getColorShade(theme, ownerState.color);
95 return _extends({
96 position: 'absolute',
97 marginTop: 0,
98 height: '100%',
99 width: '100%'
100 }, ownerState.color === 'inherit' && {
101 opacity: 0.3
102 }, {
103 backgroundImage: "radial-gradient(".concat(backgroundColor, " 0%, ").concat(backgroundColor, " 16%, transparent 42%)"),
104 backgroundSize: '10px 10px',
105 backgroundPosition: '0 -23px'
106 });
107}, css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n animation: ", " 3s infinite linear;\n "])), bufferKeyframe));
108var LinearProgressBar1 = styled('span', {
109 name: 'MuiLinearProgress',
110 slot: 'Bar1',
111 overridesResolver: function overridesResolver(props, styles) {
112 var ownerState = props.ownerState;
113 return [styles.bar, styles["barColor".concat(capitalize(ownerState.color))], (ownerState.variant === 'indeterminate' || ownerState.variant === 'query') && styles.bar1Indeterminate, ownerState.variant === 'determinate' && styles.bar1Determinate, ownerState.variant === 'buffer' && styles.bar1Buffer];
114 }
115})(function (_ref3) {
116 var ownerState = _ref3.ownerState,
117 theme = _ref3.theme;
118 return _extends({
119 width: '100%',
120 position: 'absolute',
121 left: 0,
122 bottom: 0,
123 top: 0,
124 transition: 'transform 0.2s linear',
125 transformOrigin: 'left',
126 backgroundColor: ownerState.color === 'inherit' ? 'currentColor' : (theme.vars || theme).palette[ownerState.color].main
127 }, ownerState.variant === 'determinate' && {
128 transition: "transform .".concat(TRANSITION_DURATION, "s linear")
129 }, ownerState.variant === 'buffer' && {
130 zIndex: 1,
131 transition: "transform .".concat(TRANSITION_DURATION, "s linear")
132 });
133}, function (_ref4) {
134 var ownerState = _ref4.ownerState;
135 return (ownerState.variant === 'indeterminate' || ownerState.variant === 'query') && css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n width: auto;\n animation: ", " 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;\n "])), indeterminate1Keyframe);
136});
137var LinearProgressBar2 = styled('span', {
138 name: 'MuiLinearProgress',
139 slot: 'Bar2',
140 overridesResolver: function overridesResolver(props, styles) {
141 var ownerState = props.ownerState;
142 return [styles.bar, styles["barColor".concat(capitalize(ownerState.color))], (ownerState.variant === 'indeterminate' || ownerState.variant === 'query') && styles.bar2Indeterminate, ownerState.variant === 'buffer' && styles.bar2Buffer];
143 }
144})(function (_ref5) {
145 var ownerState = _ref5.ownerState,
146 theme = _ref5.theme;
147 return _extends({
148 width: '100%',
149 position: 'absolute',
150 left: 0,
151 bottom: 0,
152 top: 0,
153 transition: 'transform 0.2s linear',
154 transformOrigin: 'left'
155 }, ownerState.variant !== 'buffer' && {
156 backgroundColor: ownerState.color === 'inherit' ? 'currentColor' : (theme.vars || theme).palette[ownerState.color].main
157 }, ownerState.color === 'inherit' && {
158 opacity: 0.3
159 }, ownerState.variant === 'buffer' && {
160 backgroundColor: getColorShade(theme, ownerState.color),
161 transition: "transform .".concat(TRANSITION_DURATION, "s linear")
162 });
163}, function (_ref6) {
164 var ownerState = _ref6.ownerState;
165 return (ownerState.variant === 'indeterminate' || ownerState.variant === 'query') && css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n width: auto;\n animation: ", " 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) 1.15s infinite;\n "])), indeterminate2Keyframe);
166});
167
168/**
169 * ## ARIA
170 *
171 * If the progress bar is describing the loading progress of a particular region of a page,
172 * you should use `aria-describedby` to point to the progress bar, and set the `aria-busy`
173 * attribute to `true` on that region until it has finished loading.
174 */
175var LinearProgress = /*#__PURE__*/React.forwardRef(function LinearProgress(inProps, ref) {
176 var props = useDefaultProps({
177 props: inProps,
178 name: 'MuiLinearProgress'
179 });
180 var className = props.className,
181 _props$color = props.color,
182 color = _props$color === void 0 ? 'primary' : _props$color,
183 value = props.value,
184 valueBuffer = props.valueBuffer,
185 _props$variant = props.variant,
186 variant = _props$variant === void 0 ? 'indeterminate' : _props$variant,
187 other = _objectWithoutProperties(props, ["className", "color", "value", "valueBuffer", "variant"]);
188 var ownerState = _extends({}, props, {
189 color: color,
190 variant: variant
191 });
192 var classes = useUtilityClasses(ownerState);
193 var isRtl = useRtl();
194 var rootProps = {};
195 var inlineStyles = {
196 bar1: {},
197 bar2: {}
198 };
199 if (variant === 'determinate' || variant === 'buffer') {
200 if (value !== undefined) {
201 rootProps['aria-valuenow'] = Math.round(value);
202 rootProps['aria-valuemin'] = 0;
203 rootProps['aria-valuemax'] = 100;
204 var transform = value - 100;
205 if (isRtl) {
206 transform = -transform;
207 }
208 inlineStyles.bar1.transform = "translateX(".concat(transform, "%)");
209 } else if (process.env.NODE_ENV !== 'production') {
210 console.error('MUI: You need to provide a value prop ' + 'when using the determinate or buffer variant of LinearProgress .');
211 }
212 }
213 if (variant === 'buffer') {
214 if (valueBuffer !== undefined) {
215 var _transform = (valueBuffer || 0) - 100;
216 if (isRtl) {
217 _transform = -_transform;
218 }
219 inlineStyles.bar2.transform = "translateX(".concat(_transform, "%)");
220 } else if (process.env.NODE_ENV !== 'production') {
221 console.error('MUI: You need to provide a valueBuffer prop ' + 'when using the buffer variant of LinearProgress.');
222 }
223 }
224 return /*#__PURE__*/_jsxs(LinearProgressRoot, _extends({
225 className: clsx(classes.root, className),
226 ownerState: ownerState,
227 role: "progressbar"
228 }, rootProps, {
229 ref: ref
230 }, other, {
231 children: [variant === 'buffer' ? /*#__PURE__*/_jsx(LinearProgressDashed, {
232 className: classes.dashed,
233 ownerState: ownerState
234 }) : null, /*#__PURE__*/_jsx(LinearProgressBar1, {
235 className: classes.bar1,
236 ownerState: ownerState,
237 style: inlineStyles.bar1
238 }), variant === 'determinate' ? null : /*#__PURE__*/_jsx(LinearProgressBar2, {
239 className: classes.bar2,
240 ownerState: ownerState,
241 style: inlineStyles.bar2
242 })]
243 }));
244});
245process.env.NODE_ENV !== "production" ? LinearProgress.propTypes /* remove-proptypes */ = {
246 // ┌────────────────────────────── Warning ──────────────────────────────┐
247 // │ These PropTypes are generated from the TypeScript type definitions. │
248 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
249 // └─────────────────────────────────────────────────────────────────────┘
250 /**
251 * Override or extend the styles applied to the component.
252 */
253 classes: PropTypes.object,
254 /**
255 * @ignore
256 */
257 className: PropTypes.string,
258 /**
259 * The color of the component.
260 * It supports both default and custom theme colors, which can be added as shown in the
261 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
262 * @default 'primary'
263 */
264 color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['inherit', 'primary', 'secondary']), PropTypes.string]),
265 /**
266 * The system prop that allows defining system overrides as well as additional CSS styles.
267 */
268 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
269 /**
270 * The value of the progress indicator for the determinate and buffer variants.
271 * Value between 0 and 100.
272 */
273 value: PropTypes.number,
274 /**
275 * The value for the buffer variant.
276 * Value between 0 and 100.
277 */
278 valueBuffer: PropTypes.number,
279 /**
280 * The variant to use.
281 * Use indeterminate or query when there is no progress value.
282 * @default 'indeterminate'
283 */
284 variant: PropTypes.oneOf(['buffer', 'determinate', 'indeterminate', 'query'])
285} : void 0;
286export default LinearProgress;
\No newline at end of file