UNPKG

3.88 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
5function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
6
7function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
9import React from 'react';
10import PropTypes from 'prop-types';
11import classNames from 'classnames';
12import { mapToCssModules, tagPropType, toNumber } from './utils';
13var propTypes = {
14 children: PropTypes.node,
15 bar: PropTypes.bool,
16 multi: PropTypes.bool,
17 tag: tagPropType,
18 value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
19 min: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
20 max: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
21 animated: PropTypes.bool,
22 striped: PropTypes.bool,
23 color: PropTypes.string,
24 className: PropTypes.string,
25 barClassName: PropTypes.string,
26 cssModule: PropTypes.object,
27 style: PropTypes.object,
28 barAriaValueText: PropTypes.string,
29 barAriaLabelledBy: PropTypes.string
30};
31var defaultProps = {
32 tag: 'div',
33 value: 0,
34 min: 0,
35 max: 100,
36 style: {}
37};
38
39var Progress = function Progress(props) {
40 var children = props.children,
41 className = props.className,
42 barClassName = props.barClassName,
43 cssModule = props.cssModule,
44 value = props.value,
45 min = props.min,
46 max = props.max,
47 animated = props.animated,
48 striped = props.striped,
49 color = props.color,
50 bar = props.bar,
51 multi = props.multi,
52 Tag = props.tag,
53 style = props.style,
54 barAriaValueText = props.barAriaValueText,
55 barAriaLabelledBy = props.barAriaLabelledBy,
56 attributes = _objectWithoutPropertiesLoose(props, ["children", "className", "barClassName", "cssModule", "value", "min", "max", "animated", "striped", "color", "bar", "multi", "tag", "style", "barAriaValueText", "barAriaLabelledBy"]);
57
58 var percent = toNumber(value) / toNumber(max) * 100;
59 var progressClasses = mapToCssModules(classNames(className, 'progress'), cssModule);
60 var progressBarClasses = mapToCssModules(classNames('progress-bar', bar ? className || barClassName : barClassName, animated ? 'progress-bar-animated' : null, color ? "bg-" + color : null, striped || animated ? 'progress-bar-striped' : null), cssModule);
61 var ProgressBar = multi ? children : /*#__PURE__*/React.createElement("div", _extends({}, attributes, {
62 className: progressBarClasses,
63 style: _objectSpread(_objectSpread({}, style), {}, {
64 width: percent + "%"
65 }),
66 role: "progressbar",
67 "aria-valuenow": value,
68 "aria-valuemin": min,
69 "aria-valuemax": max,
70 "aria-valuetext": barAriaValueText,
71 "aria-labelledby": barAriaLabelledBy,
72 children: children
73 }));
74
75 if (bar) {
76 return ProgressBar;
77 }
78
79 return /*#__PURE__*/React.createElement(Tag, _extends({}, attributes, {
80 className: progressClasses,
81 children: ProgressBar
82 }));
83};
84
85Progress.propTypes = propTypes;
86Progress.defaultProps = defaultProps;
87export default Progress;
\No newline at end of file