Debian Codegraph @

node/@patternfly/react-core/dist/js/components/Progress/Progress.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.Progress = exports.ProgressSize = void 0;
4 const tslib_1 = require("tslib");
5 const jsx_runtime_1 = require("react/jsx-runtime");
6 const react_1 = require("react");
7 const progress_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Progress/progress"));
8 const react_styles_1 = require("@patternfly/react-styles");
9 const ProgressContainer_1 = require("./ProgressContainer");
10 const helpers_1 = require("../../helpers");
11 var ProgressSize;
12 (function (ProgressSize) {
13 ProgressSize["sm"] = "sm";
14 ProgressSize["md"] = "md";
15 ProgressSize["lg"] = "lg";
16 })(ProgressSize || (exports.ProgressSize = ProgressSize = {}));
17 class Progress extends react_1.Component {
18 render() {
19 const _a = this.props, { id: idProp, size, className, value, title, label, variant, measureLocation, min, max, valueText, isTitleTruncated, tooltipPosition, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, helperText, hideStatusIcon } = _a, props = tslib_1.__rest(_a, ["id", "size", "className", "value", "title", "label", "variant", "measureLocation", "min", "max", "valueText", "isTitleTruncated", "tooltipPosition", 'aria-label', 'aria-labelledby', 'aria-describedby', "helperText", "hideStatusIcon"]);
20 if (!title && !ariaLabelledBy && !ariaLabel) {
21 /* eslint-disable no-console */
22 console.warn('One of aria-label or aria-labelledby properties should be passed when using the progress component without a title.');
23 }
24 return ((0, jsx_runtime_1.jsx)(helpers_1.GenerateId, { prefix: "pf-progress-", children: (generatedId) => {
25 const id = idProp || generatedId;
26 const progressBarAriaProps = {
27 'aria-valuemin': min,
28 'aria-valuenow': value,
29 'aria-valuemax': max
30 };
31 if (title || ariaLabelledBy) {
32 progressBarAriaProps['aria-labelledby'] = title ? `${id}-description` : ariaLabelledBy;
33 }
34 if (ariaLabel) {
35 progressBarAriaProps['aria-label'] = ariaLabel;
36 }
37 if (ariaDescribedBy) {
38 progressBarAriaProps['aria-describedby'] = ariaDescribedBy;
39 }
40 if (valueText) {
41 progressBarAriaProps['aria-valuetext'] = valueText;
42 }
43 const scaledValue = Math.min(100, Math.max(0, Math.floor(((value - min) / (max - min)) * 100))) || 0;
44 return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, props, { className: (0, react_styles_1.css)(progress_1.default.progress, progress_1.default.modifiers[variant], ['inside', 'outside'].includes(measureLocation) &&
45 progress_1.default.modifiers[measureLocation], measureLocation === 'inside'
46 ? progress_1.default.modifiers[ProgressSize.lg]
47 : progress_1.default.modifiers[size], !title && progress_1.default.modifiers.singleline, className), id: id, children: (0, jsx_runtime_1.jsx)(ProgressContainer_1.ProgressContainer, { parentId: id, value: scaledValue, title: title, label: label, variant: variant, measureLocation: measureLocation, progressBarAriaProps: progressBarAriaProps, isTitleTruncated: isTitleTruncated, tooltipPosition: tooltipPosition, helperText: helperText, hideStatusIcon: hideStatusIcon }) })));
48 } }));
49 }
50 }
51 exports.Progress = Progress;
52 Progress.displayName = 'Progress';
53 Progress.defaultProps = {
54 className: '',
55 measureLocation: ProgressContainer_1.ProgressMeasureLocation.top,
56 variant: null,
57 id: '',
58 title: '',
59 min: 0,
60 max: 100,
61 size: null,
62 label: null,
63 value: 0,
64 valueText: null,
65 isTitleTruncated: false,
66 tooltipPosition: 'top',
67 'aria-label': null,
68 'aria-labelledby': null,
69 'aria-describedby': null
70 };
71 //# sourceMappingURL=Progress.js.map