UNPKG

9.48 kBJavaScriptView Raw
1import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2import _extends from "@babel/runtime/helpers/esm/extends";
3import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
4
5var _templateObject, _templateObject2, _templateObject3, _templateObject4;
6
7import * as React from 'react';
8import PropTypes from 'prop-types';
9import clsx from 'clsx';
10import { chainPropTypes } from '@mui/utils';
11import { unstable_composeClasses as composeClasses } from '@mui/base';
12import { keyframes, css } from '@mui/system';
13import capitalize from '../utils/capitalize';
14import useThemeProps from '../styles/useThemeProps';
15import styled from '../styles/styled';
16import { getCircularProgressUtilityClass } from './circularProgressClasses';
17import { jsx as _jsx } from "react/jsx-runtime";
18var SIZE = 44;
19var circularRotateKeyframe = keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n transform: rotate(0deg);\n }\n\n 100% {\n transform: rotate(360deg);\n }\n"])));
20var circularDashKeyframe = keyframes(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n 0% {\n stroke-dasharray: 1px, 200px;\n stroke-dashoffset: 0;\n }\n\n 50% {\n stroke-dasharray: 100px, 200px;\n stroke-dashoffset: -15px;\n }\n\n 100% {\n stroke-dasharray: 100px, 200px;\n stroke-dashoffset: -125px;\n }\n"])));
21
22var useUtilityClasses = function useUtilityClasses(ownerState) {
23 var classes = ownerState.classes,
24 variant = ownerState.variant,
25 color = ownerState.color,
26 disableShrink = ownerState.disableShrink;
27 var slots = {
28 root: ['root', variant, "color".concat(capitalize(color))],
29 svg: ['svg'],
30 circle: ['circle', "circle".concat(capitalize(variant)), disableShrink && 'circleDisableShrink']
31 };
32 return composeClasses(slots, getCircularProgressUtilityClass, classes);
33};
34
35var CircularProgressRoot = styled('span', {
36 name: 'MuiCircularProgress',
37 slot: 'Root',
38 overridesResolver: function overridesResolver(props, styles) {
39 var ownerState = props.ownerState;
40 return [styles.root, styles[ownerState.variant], styles["color".concat(capitalize(ownerState.color))]];
41 }
42})(function (_ref) {
43 var ownerState = _ref.ownerState,
44 theme = _ref.theme;
45 return _extends({
46 display: 'inline-block'
47 }, ownerState.variant === 'determinate' && {
48 transition: theme.transitions.create('transform')
49 }, ownerState.color !== 'inherit' && {
50 color: (theme.vars || theme).palette[ownerState.color].main
51 });
52}, function (_ref2) {
53 var ownerState = _ref2.ownerState;
54 return ownerState.variant === 'indeterminate' && css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n animation: ", " 1.4s linear infinite;\n "])), circularRotateKeyframe);
55});
56var CircularProgressSVG = styled('svg', {
57 name: 'MuiCircularProgress',
58 slot: 'Svg',
59 overridesResolver: function overridesResolver(props, styles) {
60 return styles.svg;
61 }
62})({
63 display: 'block' // Keeps the progress centered
64
65});
66var CircularProgressCircle = styled('circle', {
67 name: 'MuiCircularProgress',
68 slot: 'Circle',
69 overridesResolver: function overridesResolver(props, styles) {
70 var ownerState = props.ownerState;
71 return [styles.circle, styles["circle".concat(capitalize(ownerState.variant))], ownerState.disableShrink && styles.circleDisableShrink];
72 }
73})(function (_ref3) {
74 var ownerState = _ref3.ownerState,
75 theme = _ref3.theme;
76 return _extends({
77 stroke: 'currentColor'
78 }, ownerState.variant === 'determinate' && {
79 transition: theme.transitions.create('stroke-dashoffset')
80 }, ownerState.variant === 'indeterminate' && {
81 // Some default value that looks fine waiting for the animation to kicks in.
82 strokeDasharray: '80px, 200px',
83 strokeDashoffset: 0 // Add the unit to fix a Edge 16 and below bug.
84
85 });
86}, function (_ref4) {
87 var ownerState = _ref4.ownerState;
88 return ownerState.variant === 'indeterminate' && !ownerState.disableShrink && css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n animation: ", " 1.4s ease-in-out infinite;\n "])), circularDashKeyframe);
89});
90/**
91 * ## ARIA
92 *
93 * If the progress bar is describing the loading progress of a particular region of a page,
94 * you should use `aria-describedby` to point to the progress bar, and set the `aria-busy`
95 * attribute to `true` on that region until it has finished loading.
96 */
97
98var CircularProgress = /*#__PURE__*/React.forwardRef(function CircularProgress(inProps, ref) {
99 var props = useThemeProps({
100 props: inProps,
101 name: 'MuiCircularProgress'
102 });
103
104 var className = props.className,
105 _props$color = props.color,
106 color = _props$color === void 0 ? 'primary' : _props$color,
107 _props$disableShrink = props.disableShrink,
108 disableShrink = _props$disableShrink === void 0 ? false : _props$disableShrink,
109 _props$size = props.size,
110 size = _props$size === void 0 ? 40 : _props$size,
111 style = props.style,
112 _props$thickness = props.thickness,
113 thickness = _props$thickness === void 0 ? 3.6 : _props$thickness,
114 _props$value = props.value,
115 value = _props$value === void 0 ? 0 : _props$value,
116 _props$variant = props.variant,
117 variant = _props$variant === void 0 ? 'indeterminate' : _props$variant,
118 other = _objectWithoutProperties(props, ["className", "color", "disableShrink", "size", "style", "thickness", "value", "variant"]);
119
120 var ownerState = _extends({}, props, {
121 color: color,
122 disableShrink: disableShrink,
123 size: size,
124 thickness: thickness,
125 value: value,
126 variant: variant
127 });
128
129 var classes = useUtilityClasses(ownerState);
130 var circleStyle = {};
131 var rootStyle = {};
132 var rootProps = {};
133
134 if (variant === 'determinate') {
135 var circumference = 2 * Math.PI * ((SIZE - thickness) / 2);
136 circleStyle.strokeDasharray = circumference.toFixed(3);
137 rootProps['aria-valuenow'] = Math.round(value);
138 circleStyle.strokeDashoffset = "".concat(((100 - value) / 100 * circumference).toFixed(3), "px");
139 rootStyle.transform = 'rotate(-90deg)';
140 }
141
142 return /*#__PURE__*/_jsx(CircularProgressRoot, _extends({
143 className: clsx(classes.root, className),
144 style: _extends({
145 width: size,
146 height: size
147 }, rootStyle, style),
148 ownerState: ownerState,
149 ref: ref,
150 role: "progressbar"
151 }, rootProps, other, {
152 children: /*#__PURE__*/_jsx(CircularProgressSVG, {
153 className: classes.svg,
154 ownerState: ownerState,
155 viewBox: "".concat(SIZE / 2, " ").concat(SIZE / 2, " ").concat(SIZE, " ").concat(SIZE),
156 children: /*#__PURE__*/_jsx(CircularProgressCircle, {
157 className: classes.circle,
158 style: circleStyle,
159 ownerState: ownerState,
160 cx: SIZE,
161 cy: SIZE,
162 r: (SIZE - thickness) / 2,
163 fill: "none",
164 strokeWidth: thickness
165 })
166 })
167 }));
168});
169process.env.NODE_ENV !== "production" ? CircularProgress.propTypes
170/* remove-proptypes */
171= {
172 // ----------------------------- Warning --------------------------------
173 // | These PropTypes are generated from the TypeScript type definitions |
174 // | To update them edit the d.ts file and run "yarn proptypes" |
175 // ----------------------------------------------------------------------
176
177 /**
178 * Override or extend the styles applied to the component.
179 */
180 classes: PropTypes.object,
181
182 /**
183 * @ignore
184 */
185 className: PropTypes.string,
186
187 /**
188 * The color of the component.
189 * It supports both default and custom theme colors, which can be added as shown in the
190 * [palette customization guide](https://mui.com/material-ui/customization/palette/#adding-new-colors).
191 * @default 'primary'
192 */
193 color: PropTypes
194 /* @typescript-to-proptypes-ignore */
195 .oneOfType([PropTypes.oneOf(['inherit', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
196
197 /**
198 * If `true`, the shrink animation is disabled.
199 * This only works if variant is `indeterminate`.
200 * @default false
201 */
202 disableShrink: chainPropTypes(PropTypes.bool, function (props) {
203 if (props.disableShrink && props.variant && props.variant !== 'indeterminate') {
204 return new Error('MUI: You have provided the `disableShrink` prop ' + 'with a variant other than `indeterminate`. This will have no effect.');
205 }
206
207 return null;
208 }),
209
210 /**
211 * The size of the component.
212 * If using a number, the pixel unit is assumed.
213 * If using a string, you need to provide the CSS unit, e.g '3rem'.
214 * @default 40
215 */
216 size: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
217
218 /**
219 * @ignore
220 */
221 style: PropTypes.object,
222
223 /**
224 * The system prop that allows defining system overrides as well as additional CSS styles.
225 */
226 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
227
228 /**
229 * The thickness of the circle.
230 * @default 3.6
231 */
232 thickness: PropTypes.number,
233
234 /**
235 * The value of the progress indicator for the determinate variant.
236 * Value between 0 and 100.
237 * @default 0
238 */
239 value: PropTypes.number,
240
241 /**
242 * The variant to use.
243 * Use indeterminate when there is no progress value.
244 * @default 'indeterminate'
245 */
246 variant: PropTypes.oneOf(['determinate', 'indeterminate'])
247} : void 0;
248export default CircularProgress;
\No newline at end of file