1 | import * as React from 'react';
|
2 | import progressStyle from '@patternfly/react-styles/css/components/Progress/progress';
|
3 | import { css } from '@patternfly/react-styles';
|
4 | import { Tooltip } from '../Tooltip';
|
5 | import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
|
6 | import TimesCircleIcon from '@patternfly/react-icons/dist/esm/icons/times-circle-icon';
|
7 | import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon';
|
8 | import { ProgressBar } from './ProgressBar';
|
9 | export var ProgressMeasureLocation;
|
10 | (function (ProgressMeasureLocation) {
|
11 | ProgressMeasureLocation["outside"] = "outside";
|
12 | ProgressMeasureLocation["inside"] = "inside";
|
13 | ProgressMeasureLocation["top"] = "top";
|
14 | ProgressMeasureLocation["none"] = "none";
|
15 | })(ProgressMeasureLocation || (ProgressMeasureLocation = {}));
|
16 | export var ProgressVariant;
|
17 | (function (ProgressVariant) {
|
18 | ProgressVariant["danger"] = "danger";
|
19 | ProgressVariant["success"] = "success";
|
20 | ProgressVariant["warning"] = "warning";
|
21 | })(ProgressVariant || (ProgressVariant = {}));
|
22 | const variantToIcon = {
|
23 | danger: TimesCircleIcon,
|
24 | success: CheckCircleIcon,
|
25 | warning: ExclamationTriangleIcon
|
26 | };
|
27 | export const ProgressContainer = ({ progressBarAriaProps, value, title = '', parentId, label = null, variant = null, measureLocation = ProgressMeasureLocation.top, isTitleTruncated = false, tooltipPosition }) => {
|
28 | const StatusIcon = variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
|
29 | const [tooltip, setTooltip] = React.useState('');
|
30 | const onMouseEnter = (event) => {
|
31 | if (event.target.offsetWidth < event.target.scrollWidth) {
|
32 | setTooltip(title || event.target.innerHTML);
|
33 | }
|
34 | else {
|
35 | setTooltip('');
|
36 | }
|
37 | };
|
38 | const Title = (React.createElement("div", { className: css(progressStyle.progressDescription, isTitleTruncated && typeof title === 'string' && progressStyle.modifiers.truncate), id: `${parentId}-description`, "aria-hidden": "true", onMouseEnter: isTitleTruncated && typeof title === 'string' ? onMouseEnter : null }, title));
|
39 | return (React.createElement(React.Fragment, null,
|
40 | tooltip ? (React.createElement(Tooltip, { position: tooltipPosition, content: tooltip, isVisible: true }, Title)) : (Title),
|
41 | React.createElement("div", { className: css(progressStyle.progressStatus), "aria-hidden": "true" },
|
42 | (measureLocation === ProgressMeasureLocation.top || measureLocation === ProgressMeasureLocation.outside) && (React.createElement("span", { className: css(progressStyle.progressMeasure) }, label || `${value}%`)),
|
43 | variantToIcon.hasOwnProperty(variant) && (React.createElement("span", { className: css(progressStyle.progressStatusIcon) },
|
44 | React.createElement(StatusIcon, null)))),
|
45 | React.createElement(ProgressBar, { role: "progressbar", progressBarAriaProps: progressBarAriaProps, value: value }, measureLocation === ProgressMeasureLocation.inside && `${value}%`)));
|
46 | };
|
47 | ProgressContainer.displayName = 'ProgressContainer';
|
48 |
|
\ | No newline at end of file |