UNPKG

10.3 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.default = exports.styles = void 0;
9
10var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
14var _react = _interopRequireDefault(require("react"));
15
16var _propTypes = _interopRequireDefault(require("prop-types"));
17
18var _clsx = _interopRequireDefault(require("clsx"));
19
20var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
21
22var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
23
24var _colorManipulator = require("../styles/colorManipulator");
25
26var _useTheme = _interopRequireDefault(require("../styles/useTheme"));
27
28var TRANSITION_DURATION = 4; // seconds
29
30var styles = function styles(theme) {
31 var getColor = function getColor(color) {
32 return theme.palette.type === 'light' ? (0, _colorManipulator.lighten)(color, 0.62) : (0, _colorManipulator.darken)(color, 0.5);
33 };
34
35 var backgroundPrimary = getColor(theme.palette.primary.main);
36 var backgroundSecondary = getColor(theme.palette.secondary.main);
37 return {
38 /* Styles applied to the root element. */
39 root: {
40 position: 'relative',
41 overflow: 'hidden',
42 height: 4
43 },
44
45 /* Styles applied to the root and bar2 element if `color="primary"`; bar2 if `variant-"buffer"`. */
46 colorPrimary: {
47 backgroundColor: backgroundPrimary
48 },
49
50 /* Styles applied to the root and bar2 elements if `color="secondary"`; bar2 if `variant="buffer"`. */
51 colorSecondary: {
52 backgroundColor: backgroundSecondary
53 },
54
55 /* Styles applied to the root element if `variant="determinate"`. */
56 determinate: {},
57
58 /* Styles applied to the root element if `variant="indeterminate"`. */
59 indeterminate: {},
60
61 /* Styles applied to the root element if `variant="buffer"`. */
62 buffer: {
63 backgroundColor: 'transparent'
64 },
65
66 /* Styles applied to the root element if `variant="query"`. */
67 query: {
68 transform: 'rotate(180deg)'
69 },
70
71 /* Styles applied to the additional bar element if `variant="buffer"`. */
72 dashed: {
73 position: 'absolute',
74 marginTop: 0,
75 height: '100%',
76 width: '100%',
77 animation: '$buffer 3s infinite linear'
78 },
79
80 /* Styles applied to the additional bar element if `variant="buffer"` and `color="primary"`. */
81 dashedColorPrimary: {
82 backgroundImage: "radial-gradient(".concat(backgroundPrimary, " 0%, ").concat(backgroundPrimary, " 16%, transparent 42%)"),
83 backgroundSize: '10px 10px',
84 backgroundPosition: '0px -23px'
85 },
86
87 /* Styles applied to the additional bar element if `variant="buffer"` and `color="secondary"`. */
88 dashedColorSecondary: {
89 backgroundImage: "radial-gradient(".concat(backgroundSecondary, " 0%, ").concat(backgroundSecondary, " 16%, transparent 42%)"),
90 backgroundSize: '10px 10px',
91 backgroundPosition: '0px -23px'
92 },
93
94 /* Styles applied to the layered bar1 and bar2 elements. */
95 bar: {
96 width: '100%',
97 position: 'absolute',
98 left: 0,
99 bottom: 0,
100 top: 0,
101 transition: 'transform 0.2s linear',
102 transformOrigin: 'left'
103 },
104
105 /* Styles applied to the bar elements if `color="primary"`; bar2 if `variant` not "buffer". */
106 barColorPrimary: {
107 backgroundColor: theme.palette.primary.main
108 },
109
110 /* Styles applied to the bar elements if `color="secondary"`; bar2 if `variant` not "buffer". */
111 barColorSecondary: {
112 backgroundColor: theme.palette.secondary.main
113 },
114
115 /* Styles applied to the bar1 element if `variant="indeterminate or query"`. */
116 bar1Indeterminate: {
117 width: 'auto',
118 animation: '$indeterminate1 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite'
119 },
120
121 /* Styles applied to the bar1 element if `variant="determinate"`. */
122 bar1Determinate: {
123 transition: "transform .".concat(TRANSITION_DURATION, "s linear")
124 },
125
126 /* Styles applied to the bar1 element if `variant="buffer"`. */
127 bar1Buffer: {
128 zIndex: 1,
129 transition: "transform .".concat(TRANSITION_DURATION, "s linear")
130 },
131
132 /* Styles applied to the bar2 element if `variant="indeterminate or query"`. */
133 bar2Indeterminate: {
134 width: 'auto',
135 animation: '$indeterminate2 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite',
136 animationDelay: '1.15s'
137 },
138
139 /* Styles applied to the bar2 element if `variant="buffer"`. */
140 bar2Buffer: {
141 transition: "transform .".concat(TRANSITION_DURATION, "s linear")
142 },
143 // Legends:
144 // || represents the viewport
145 // - represents a light background
146 // x represents a dark background
147 '@keyframes indeterminate1': {
148 // |-----|---x-||-----||-----|
149 '0%': {
150 left: '-35%',
151 right: '100%'
152 },
153 // |-----|-----||-----||xxxx-|
154 '60%': {
155 left: '100%',
156 right: '-90%'
157 },
158 '100%': {
159 left: '100%',
160 right: '-90%'
161 }
162 },
163 '@keyframes indeterminate2': {
164 // |xxxxx|xxxxx||-----||-----|
165 '0%': {
166 left: '-200%',
167 right: '100%'
168 },
169 // |-----|-----||-----||-x----|
170 '60%': {
171 left: '107%',
172 right: '-8%'
173 },
174 '100%': {
175 left: '107%',
176 right: '-8%'
177 }
178 },
179 '@keyframes buffer': {
180 '0%': {
181 opacity: 1,
182 backgroundPosition: '0px -23px'
183 },
184 '50%': {
185 opacity: 0,
186 backgroundPosition: '0px -23px'
187 },
188 '100%': {
189 opacity: 1,
190 backgroundPosition: '-200px -23px'
191 }
192 }
193 };
194};
195/**
196 * ## ARIA
197 *
198 * If the progress bar is describing the loading progress of a particular region of a page,
199 * you should use `aria-describedby` to point to the progress bar, and set the `aria-busy`
200 * attribute to `true` on that region until it has finished loading.
201 */
202
203
204exports.styles = styles;
205
206var LinearProgress = _react.default.forwardRef(function LinearProgress(props, ref) {
207 var classes = props.classes,
208 className = props.className,
209 _props$color = props.color,
210 color = _props$color === void 0 ? 'primary' : _props$color,
211 value = props.value,
212 valueBuffer = props.valueBuffer,
213 _props$variant = props.variant,
214 variant = _props$variant === void 0 ? 'indeterminate' : _props$variant,
215 other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "color", "value", "valueBuffer", "variant"]);
216 var theme = (0, _useTheme.default)();
217 var rootProps = {};
218 var inlineStyles = {
219 bar1: {},
220 bar2: {}
221 };
222
223 if (variant === 'determinate' || variant === 'buffer') {
224 if (value !== undefined) {
225 rootProps['aria-valuenow'] = Math.round(value);
226 var transform = value - 100;
227
228 if (theme.direction === 'rtl') {
229 transform = -transform;
230 }
231
232 inlineStyles.bar1.transform = "translateX(".concat(transform, "%)");
233 } else if (process.env.NODE_ENV !== 'production') {
234 console.error('Material-UI: you need to provide a value prop ' + 'when using the determinate or buffer variant of LinearProgress .');
235 }
236 }
237
238 if (variant === 'buffer') {
239 if (valueBuffer !== undefined) {
240 var _transform = (valueBuffer || 0) - 100;
241
242 if (theme.direction === 'rtl') {
243 _transform = -_transform;
244 }
245
246 inlineStyles.bar2.transform = "translateX(".concat(_transform, "%)");
247 } else if (process.env.NODE_ENV !== 'production') {
248 console.error('Material-UI: you need to provide a valueBuffer prop ' + 'when using the buffer variant of LinearProgress.');
249 }
250 }
251
252 return _react.default.createElement("div", (0, _extends2.default)({
253 className: (0, _clsx.default)(classes.root, classes["color".concat((0, _capitalize.default)(color))], className, {
254 determinate: classes.determinate,
255 indeterminate: classes.indeterminate,
256 buffer: classes.buffer,
257 query: classes.query
258 }[variant]),
259 role: "progressbar"
260 }, rootProps, {
261 ref: ref
262 }, other), variant === 'buffer' ? _react.default.createElement("div", {
263 className: (0, _clsx.default)(classes.dashed, classes["dashedColor".concat((0, _capitalize.default)(color))])
264 }) : null, _react.default.createElement("div", {
265 className: (0, _clsx.default)(classes.bar, classes["barColor".concat((0, _capitalize.default)(color))], (variant === 'indeterminate' || variant === 'query') && classes.bar1Indeterminate, {
266 determinate: classes.bar1Determinate,
267 buffer: classes.bar1Buffer
268 }[variant]),
269 style: inlineStyles.bar1
270 }), variant === 'determinate' ? null : _react.default.createElement("div", {
271 className: (0, _clsx.default)(classes.bar, (variant === 'indeterminate' || variant === 'query') && classes.bar2Indeterminate, variant === 'buffer' ? [classes["color".concat((0, _capitalize.default)(color))], classes.bar2Buffer] : classes["barColor".concat((0, _capitalize.default)(color))]),
272 style: inlineStyles.bar2
273 }));
274});
275
276process.env.NODE_ENV !== "production" ? LinearProgress.propTypes = {
277 /**
278 * Override or extend the styles applied to the component.
279 * See [CSS API](#css) below for more details.
280 */
281 classes: _propTypes.default.object.isRequired,
282
283 /**
284 * @ignore
285 */
286 className: _propTypes.default.string,
287
288 /**
289 * The color of the component. It supports those theme colors that make sense for this component.
290 */
291 color: _propTypes.default.oneOf(['primary', 'secondary']),
292
293 /**
294 * The value of the progress indicator for the determinate and buffer variants.
295 * Value between 0 and 100.
296 */
297 value: _propTypes.default.number,
298
299 /**
300 * The value for the buffer variant.
301 * Value between 0 and 100.
302 */
303 valueBuffer: _propTypes.default.number,
304
305 /**
306 * The variant to use.
307 * Use indeterminate or query when there is no progress value.
308 */
309 variant: _propTypes.default.oneOf(['determinate', 'indeterminate', 'buffer', 'query'])
310} : void 0;
311
312var _default = (0, _withStyles.default)(styles, {
313 name: 'MuiLinearProgress'
314})(LinearProgress);
315
316exports.default = _default;
\No newline at end of file