UNPKG

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