UNPKG

10.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 _chainPropTypes = _interopRequireDefault(require("@mui/utils/chainPropTypes"));
14var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
15var _zeroStyled = require("../zero-styled");
16var _memoTheme = _interopRequireDefault(require("../utils/memoTheme"));
17var _DefaultPropsProvider = require("../DefaultPropsProvider");
18var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
19var _createSimplePaletteValueFilter = _interopRequireDefault(require("../utils/createSimplePaletteValueFilter"));
20var _circularProgressClasses = require("./circularProgressClasses");
21var _jsxRuntime = require("react/jsx-runtime");
22const SIZE = 44;
23const circularRotateKeyframe = (0, _zeroStyled.keyframes)`
24 0% {
25 transform: rotate(0deg);
26 }
27
28 100% {
29 transform: rotate(360deg);
30 }
31`;
32const circularDashKeyframe = (0, _zeroStyled.keyframes)`
33 0% {
34 stroke-dasharray: 1px, 200px;
35 stroke-dashoffset: 0;
36 }
37
38 50% {
39 stroke-dasharray: 100px, 200px;
40 stroke-dashoffset: -15px;
41 }
42
43 100% {
44 stroke-dasharray: 100px, 200px;
45 stroke-dashoffset: -125px;
46 }
47`;
48
49// This implementation is for supporting both Styled-components v4+ and Pigment CSS.
50// 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).
51// which can be done by checking typeof indeterminate1Keyframe !== 'string' (at runtime, Pigment CSS transform keyframes`` to a string).
52const rotateAnimation = typeof circularRotateKeyframe !== 'string' ? (0, _zeroStyled.css)`
53 animation: ${circularRotateKeyframe} 1.4s linear infinite;
54 ` : null;
55const dashAnimation = typeof circularDashKeyframe !== 'string' ? (0, _zeroStyled.css)`
56 animation: ${circularDashKeyframe} 1.4s ease-in-out infinite;
57 ` : null;
58const useUtilityClasses = ownerState => {
59 const {
60 classes,
61 variant,
62 color,
63 disableShrink
64 } = ownerState;
65 const slots = {
66 root: ['root', variant, `color${(0, _capitalize.default)(color)}`],
67 svg: ['svg'],
68 circle: ['circle', `circle${(0, _capitalize.default)(variant)}`, disableShrink && 'circleDisableShrink']
69 };
70 return (0, _composeClasses.default)(slots, _circularProgressClasses.getCircularProgressUtilityClass, classes);
71};
72const CircularProgressRoot = (0, _zeroStyled.styled)('span', {
73 name: 'MuiCircularProgress',
74 slot: 'Root',
75 overridesResolver: (props, styles) => {
76 const {
77 ownerState
78 } = props;
79 return [styles.root, styles[ownerState.variant], styles[`color${(0, _capitalize.default)(ownerState.color)}`]];
80 }
81})((0, _memoTheme.default)(({
82 theme
83}) => ({
84 display: 'inline-block',
85 variants: [{
86 props: {
87 variant: 'determinate'
88 },
89 style: {
90 transition: theme.transitions.create('transform')
91 }
92 }, {
93 props: {
94 variant: 'indeterminate'
95 },
96 style: rotateAnimation || {
97 animation: `${circularRotateKeyframe} 1.4s linear infinite`
98 }
99 }, ...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => ({
100 props: {
101 color
102 },
103 style: {
104 color: (theme.vars || theme).palette[color].main
105 }
106 }))]
107})));
108const CircularProgressSVG = (0, _zeroStyled.styled)('svg', {
109 name: 'MuiCircularProgress',
110 slot: 'Svg',
111 overridesResolver: (props, styles) => styles.svg
112})({
113 display: 'block' // Keeps the progress centered
114});
115const CircularProgressCircle = (0, _zeroStyled.styled)('circle', {
116 name: 'MuiCircularProgress',
117 slot: 'Circle',
118 overridesResolver: (props, styles) => {
119 const {
120 ownerState
121 } = props;
122 return [styles.circle, styles[`circle${(0, _capitalize.default)(ownerState.variant)}`], ownerState.disableShrink && styles.circleDisableShrink];
123 }
124})((0, _memoTheme.default)(({
125 theme
126}) => ({
127 stroke: 'currentColor',
128 variants: [{
129 props: {
130 variant: 'determinate'
131 },
132 style: {
133 transition: theme.transitions.create('stroke-dashoffset')
134 }
135 }, {
136 props: {
137 variant: 'indeterminate'
138 },
139 style: {
140 // Some default value that looks fine waiting for the animation to kicks in.
141 strokeDasharray: '80px, 200px',
142 strokeDashoffset: 0 // Add the unit to fix a Edge 16 and below bug.
143 }
144 }, {
145 props: ({
146 ownerState
147 }) => ownerState.variant === 'indeterminate' && !ownerState.disableShrink,
148 style: dashAnimation || {
149 // At runtime for Pigment CSS, `bufferAnimation` will be null and the generated keyframe will be used.
150 animation: `${circularDashKeyframe} 1.4s ease-in-out infinite`
151 }
152 }]
153})));
154
155/**
156 * ## ARIA
157 *
158 * If the progress bar is describing the loading progress of a particular region of a page,
159 * you should use `aria-describedby` to point to the progress bar, and set the `aria-busy`
160 * attribute to `true` on that region until it has finished loading.
161 */
162const CircularProgress = /*#__PURE__*/React.forwardRef(function CircularProgress(inProps, ref) {
163 const props = (0, _DefaultPropsProvider.useDefaultProps)({
164 props: inProps,
165 name: 'MuiCircularProgress'
166 });
167 const {
168 className,
169 color = 'primary',
170 disableShrink = false,
171 size = 40,
172 style,
173 thickness = 3.6,
174 value = 0,
175 variant = 'indeterminate',
176 ...other
177 } = props;
178 const ownerState = {
179 ...props,
180 color,
181 disableShrink,
182 size,
183 thickness,
184 value,
185 variant
186 };
187 const classes = useUtilityClasses(ownerState);
188 const circleStyle = {};
189 const rootStyle = {};
190 const rootProps = {};
191 if (variant === 'determinate') {
192 const circumference = 2 * Math.PI * ((SIZE - thickness) / 2);
193 circleStyle.strokeDasharray = circumference.toFixed(3);
194 rootProps['aria-valuenow'] = Math.round(value);
195 circleStyle.strokeDashoffset = `${((100 - value) / 100 * circumference).toFixed(3)}px`;
196 rootStyle.transform = 'rotate(-90deg)';
197 }
198 return /*#__PURE__*/(0, _jsxRuntime.jsx)(CircularProgressRoot, {
199 className: (0, _clsx.default)(classes.root, className),
200 style: {
201 width: size,
202 height: size,
203 ...rootStyle,
204 ...style
205 },
206 ownerState: ownerState,
207 ref: ref,
208 role: "progressbar",
209 ...rootProps,
210 ...other,
211 children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CircularProgressSVG, {
212 className: classes.svg,
213 ownerState: ownerState,
214 viewBox: `${SIZE / 2} ${SIZE / 2} ${SIZE} ${SIZE}`,
215 children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CircularProgressCircle, {
216 className: classes.circle,
217 style: circleStyle,
218 ownerState: ownerState,
219 cx: SIZE,
220 cy: SIZE,
221 r: (SIZE - thickness) / 2,
222 fill: "none",
223 strokeWidth: thickness
224 })
225 })
226 });
227});
228process.env.NODE_ENV !== "production" ? CircularProgress.propTypes /* remove-proptypes */ = {
229 // ┌────────────────────────────── Warning ──────────────────────────────┐
230 // │ These PropTypes are generated from the TypeScript type definitions. │
231 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
232 // └─────────────────────────────────────────────────────────────────────┘
233 /**
234 * Override or extend the styles applied to the component.
235 */
236 classes: _propTypes.default.object,
237 /**
238 * @ignore
239 */
240 className: _propTypes.default.string,
241 /**
242 * The color of the component.
243 * It supports both default and custom theme colors, which can be added as shown in the
244 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
245 * @default 'primary'
246 */
247 color: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['inherit', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), _propTypes.default.string]),
248 /**
249 * If `true`, the shrink animation is disabled.
250 * This only works if variant is `indeterminate`.
251 * @default false
252 */
253 disableShrink: (0, _chainPropTypes.default)(_propTypes.default.bool, props => {
254 if (props.disableShrink && props.variant && props.variant !== 'indeterminate') {
255 return new Error('MUI: You have provided the `disableShrink` prop ' + 'with a variant other than `indeterminate`. This will have no effect.');
256 }
257 return null;
258 }),
259 /**
260 * The size of the component.
261 * If using a number, the pixel unit is assumed.
262 * If using a string, you need to provide the CSS unit, for example '3rem'.
263 * @default 40
264 */
265 size: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
266 /**
267 * @ignore
268 */
269 style: _propTypes.default.object,
270 /**
271 * The system prop that allows defining system overrides as well as additional CSS styles.
272 */
273 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]),
274 /**
275 * The thickness of the circle.
276 * @default 3.6
277 */
278 thickness: _propTypes.default.number,
279 /**
280 * The value of the progress indicator for the determinate variant.
281 * Value between 0 and 100.
282 * @default 0
283 */
284 value: _propTypes.default.number,
285 /**
286 * The variant to use.
287 * Use indeterminate when there is no progress value.
288 * @default 'indeterminate'
289 */
290 variant: _propTypes.default.oneOf(['determinate', 'indeterminate'])
291} : void 0;
292var _default = exports.default = CircularProgress;
\No newline at end of file