Debian Codegraph @

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

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