1 | "use strict";
|
2 | "use client";
|
3 |
|
4 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
5 | exports.__esModule = true;
|
6 | exports.default = void 0;
|
7 | var _classnames = _interopRequireDefault(require("classnames"));
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 | var _ThemeProvider = require("./ThemeProvider");
|
10 | var _ElementChildren = require("./ElementChildren");
|
11 | var _jsxRuntime = require("react/jsx-runtime");
|
12 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
13 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
14 | const ROUND_PRECISION = 1000;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function onlyProgressBar(props, propName, componentName) {
|
20 | const children = props[propName];
|
21 | if (!children) {
|
22 | return null;
|
23 | }
|
24 | let error = null;
|
25 | React.Children.forEach(children, child => {
|
26 | if (error) {
|
27 | return;
|
28 | }
|
29 |
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | const element = (0, _jsxRuntime.jsx)(ProgressBar, {});
|
38 | if (child.type === element.type) return;
|
39 | const childType = child.type;
|
40 | const childIdentifier = React.isValidElement(child) ? childType.displayName || childType.name || childType : child;
|
41 | error = new Error(`Children of ${componentName} can contain only ProgressBar ` + `components. Found ${childIdentifier}.`);
|
42 | });
|
43 | return error;
|
44 | }
|
45 | function getPercentage(now, min, max) {
|
46 | const percentage = (now - min) / (max - min) * 100;
|
47 | return Math.round(percentage * ROUND_PRECISION) / ROUND_PRECISION;
|
48 | }
|
49 | function renderProgressBar({
|
50 | min,
|
51 | now,
|
52 | max,
|
53 | label,
|
54 | visuallyHidden,
|
55 | striped,
|
56 | animated,
|
57 | className,
|
58 | style,
|
59 | variant,
|
60 | bsPrefix,
|
61 | ...props
|
62 | }, ref) {
|
63 | return (0, _jsxRuntime.jsx)("div", {
|
64 | ref: ref,
|
65 | ...props,
|
66 | role: "progressbar",
|
67 | className: (0, _classnames.default)(className, `${bsPrefix}-bar`, {
|
68 | [`bg-${variant}`]: variant,
|
69 | [`${bsPrefix}-bar-animated`]: animated,
|
70 | [`${bsPrefix}-bar-striped`]: animated || striped
|
71 | }),
|
72 | style: {
|
73 | width: `${getPercentage(now, min, max)}%`,
|
74 | ...style
|
75 | },
|
76 | "aria-valuenow": now,
|
77 | "aria-valuemin": min,
|
78 | "aria-valuemax": max,
|
79 | children: visuallyHidden ? (0, _jsxRuntime.jsx)("span", {
|
80 | className: "visually-hidden",
|
81 | children: label
|
82 | }) : label
|
83 | });
|
84 | }
|
85 | const ProgressBar = React.forwardRef(({
|
86 | isChild = false,
|
87 | ...rest
|
88 | }, ref) => {
|
89 | const props = {
|
90 | min: 0,
|
91 | max: 100,
|
92 | animated: false,
|
93 | visuallyHidden: false,
|
94 | striped: false,
|
95 | ...rest
|
96 | };
|
97 | props.bsPrefix = (0, _ThemeProvider.useBootstrapPrefix)(props.bsPrefix, 'progress');
|
98 | if (isChild) {
|
99 | return renderProgressBar(props, ref);
|
100 | }
|
101 | const {
|
102 | min,
|
103 | now,
|
104 | max,
|
105 | label,
|
106 | visuallyHidden,
|
107 | striped,
|
108 | animated,
|
109 | bsPrefix,
|
110 | variant,
|
111 | className,
|
112 | children,
|
113 | ...wrapperProps
|
114 | } = props;
|
115 | return (0, _jsxRuntime.jsx)("div", {
|
116 | ref: ref,
|
117 | ...wrapperProps,
|
118 | className: (0, _classnames.default)(className, bsPrefix),
|
119 | children: children ? (0, _ElementChildren.map)(children, child => (0, React.cloneElement)(child, {
|
120 | isChild: true
|
121 | })) : renderProgressBar({
|
122 | min,
|
123 | now,
|
124 | max,
|
125 | label,
|
126 | visuallyHidden,
|
127 | striped,
|
128 | animated,
|
129 | bsPrefix,
|
130 | variant
|
131 | }, ref)
|
132 | });
|
133 | });
|
134 | ProgressBar.displayName = 'ProgressBar';
|
135 | var _default = ProgressBar;
|
136 | exports.default = _default;
|
137 | module.exports = exports.default; |
\ | No newline at end of file |