UNPKG

8.77 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _utils = require("@material-ui/utils");
23
24var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
25
26var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
27
28var SIZE = 44;
29
30var styles = function styles(theme) {
31 return {
32 /* Styles applied to the root element. */
33 root: {
34 display: 'inline-block'
35 },
36
37 /* Styles applied to the root element if `variant="static"`. */
38 static: {
39 transition: theme.transitions.create('transform')
40 },
41
42 /* Styles applied to the root element if `variant="indeterminate"`. */
43 indeterminate: {
44 animation: '$circular-rotate 1.4s linear infinite'
45 },
46
47 /* Styles applied to the root element if `variant="determinate"`. */
48 determinate: {
49 transition: theme.transitions.create('transform')
50 },
51
52 /* Styles applied to the root element if `color="primary"`. */
53 colorPrimary: {
54 color: theme.palette.primary.main
55 },
56
57 /* Styles applied to the root element if `color="secondary"`. */
58 colorSecondary: {
59 color: theme.palette.secondary.main
60 },
61
62 /* Styles applied to the `svg` element. */
63 svg: {
64 display: 'block' // Keeps the progress centered
65
66 },
67
68 /* Styles applied to the `circle` svg path. */
69 circle: {
70 stroke: 'currentColor' // Use butt to follow the specification, by chance, it's already the default CSS value.
71 // strokeLinecap: 'butt',
72
73 },
74
75 /* Styles applied to the `circle` svg path if `variant="static"`. */
76 circleStatic: {
77 transition: theme.transitions.create('stroke-dashoffset')
78 },
79
80 /* Styles applied to the `circle` svg path if `variant="indeterminate"`. */
81 circleIndeterminate: {
82 animation: '$circular-dash 1.4s ease-in-out infinite',
83 // Some default value that looks fine waiting for the animation to kicks in.
84 strokeDasharray: '80px, 200px',
85 strokeDashoffset: '0px' // Add the unit to fix a Edge 16 and below bug.
86
87 },
88
89 /* Styles applied to the `circle` svg path if `variant="determinate"`. */
90 circleDeterminate: {
91 transition: theme.transitions.create('stroke-dashoffset')
92 },
93 '@keyframes circular-rotate': {
94 '0%': {
95 // Fix IE 11 wobbly
96 transformOrigin: '50% 50%'
97 },
98 '100%': {
99 transform: 'rotate(360deg)'
100 }
101 },
102 '@keyframes circular-dash': {
103 '0%': {
104 strokeDasharray: '1px, 200px',
105 strokeDashoffset: '0px'
106 },
107 '50%': {
108 strokeDasharray: '100px, 200px',
109 strokeDashoffset: '-15px'
110 },
111 '100%': {
112 strokeDasharray: '100px, 200px',
113 strokeDashoffset: '-125px'
114 }
115 },
116
117 /* Styles applied to the `circle` svg path if `disableShrink={true}`. */
118 circleDisableShrink: {
119 animation: 'none'
120 }
121 };
122};
123/**
124 * ## ARIA
125 *
126 * If the progress bar is describing the loading progress of a particular region of a page,
127 * you should use `aria-describedby` to point to the progress bar, and set the `aria-busy`
128 * attribute to `true` on that region until it has finished loading.
129 */
130
131
132exports.styles = styles;
133var CircularProgress = /*#__PURE__*/React.forwardRef(function CircularProgress(props, ref) {
134 var classes = props.classes,
135 className = props.className,
136 _props$color = props.color,
137 color = _props$color === void 0 ? 'primary' : _props$color,
138 _props$disableShrink = props.disableShrink,
139 disableShrink = _props$disableShrink === void 0 ? false : _props$disableShrink,
140 _props$size = props.size,
141 size = _props$size === void 0 ? 40 : _props$size,
142 style = props.style,
143 _props$thickness = props.thickness,
144 thickness = _props$thickness === void 0 ? 3.6 : _props$thickness,
145 _props$value = props.value,
146 value = _props$value === void 0 ? 0 : _props$value,
147 _props$variant = props.variant,
148 variant = _props$variant === void 0 ? 'indeterminate' : _props$variant,
149 other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "color", "disableShrink", "size", "style", "thickness", "value", "variant"]);
150 var circleStyle = {};
151 var rootStyle = {};
152 var rootProps = {};
153
154 if (variant === 'determinate' || variant === 'static') {
155 var circumference = 2 * Math.PI * ((SIZE - thickness) / 2);
156 circleStyle.strokeDasharray = circumference.toFixed(3);
157 rootProps['aria-valuenow'] = Math.round(value);
158 circleStyle.strokeDashoffset = "".concat(((100 - value) / 100 * circumference).toFixed(3), "px");
159 rootStyle.transform = 'rotate(-90deg)';
160 }
161
162 return /*#__PURE__*/React.createElement("div", (0, _extends2.default)({
163 className: (0, _clsx.default)(classes.root, className, color !== 'inherit' && classes["color".concat((0, _capitalize.default)(color))], {
164 'determinate': classes.determinate,
165 'indeterminate': classes.indeterminate,
166 'static': classes.static
167 }[variant]),
168 style: (0, _extends2.default)({
169 width: size,
170 height: size
171 }, rootStyle, style),
172 ref: ref,
173 role: "progressbar"
174 }, rootProps, other), /*#__PURE__*/React.createElement("svg", {
175 className: classes.svg,
176 viewBox: "".concat(SIZE / 2, " ").concat(SIZE / 2, " ").concat(SIZE, " ").concat(SIZE)
177 }, /*#__PURE__*/React.createElement("circle", {
178 className: (0, _clsx.default)(classes.circle, disableShrink && classes.circleDisableShrink, {
179 'determinate': classes.circleDeterminate,
180 'indeterminate': classes.circleIndeterminate,
181 'static': classes.circleStatic
182 }[variant]),
183 style: circleStyle,
184 cx: SIZE,
185 cy: SIZE,
186 r: (SIZE - thickness) / 2,
187 fill: "none",
188 strokeWidth: thickness
189 })));
190});
191process.env.NODE_ENV !== "production" ? CircularProgress.propTypes = {
192 // ----------------------------- Warning --------------------------------
193 // | These PropTypes are generated from the TypeScript type definitions |
194 // | To update them edit the d.ts file and run "yarn proptypes" |
195 // ----------------------------------------------------------------------
196
197 /**
198 * Override or extend the styles applied to the component.
199 * See [CSS API](#css) below for more details.
200 */
201 classes: _propTypes.default.object,
202
203 /**
204 * @ignore
205 */
206 className: _propTypes.default.string,
207
208 /**
209 * The color of the component. It supports those theme colors that make sense for this component.
210 */
211 color: _propTypes.default.oneOf(['inherit', 'primary', 'secondary']),
212
213 /**
214 * If `true`, the shrink animation is disabled.
215 * This only works if variant is `indeterminate`.
216 */
217 disableShrink: (0, _utils.chainPropTypes)(_propTypes.default.bool, function (props) {
218 if (props.disableShrink && props.variant && props.variant !== 'indeterminate') {
219 return new Error('Material-UI: You have provided the `disableShrink` prop ' + 'with a variant other than `indeterminate`. This will have no effect.');
220 }
221
222 return null;
223 }),
224
225 /**
226 * The size of the circle.
227 * If using a number, the pixel unit is assumed.
228 * If using a string, you need to provide the CSS unit, e.g '3rem'.
229 */
230 size: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
231
232 /**
233 * @ignore
234 */
235 style: _propTypes.default.object,
236
237 /**
238 * The thickness of the circle.
239 */
240 thickness: _propTypes.default.number,
241
242 /**
243 * The value of the progress indicator for the determinate variant.
244 * Value between 0 and 100.
245 */
246 value: _propTypes.default.number,
247
248 /**
249 * The variant to use.
250 * Use indeterminate when there is no progress value.
251 */
252 variant: (0, _utils.chainPropTypes)(_propTypes.default.oneOf(['determinate', 'indeterminate', 'static']), function (props) {
253 var variant = props.variant;
254
255 if (variant === 'static') {
256 throw new Error('Material-UI: `variant="static"` was deprecated. Use `variant="determinate"` instead.');
257 }
258
259 return null;
260 })
261} : void 0;
262
263var _default = (0, _withStyles.default)(styles, {
264 name: 'MuiCircularProgress',
265 flip: false
266})(CircularProgress);
267
268exports.default = _default;
\No newline at end of file