| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.ProgressContainer = exports.ProgressVariant = exports.ProgressMeasureLocation = 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 Tooltip_1 = require("../Tooltip"); |
| 10 |
const rh_ui_check_circle_fill_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-ui-check-circle-fill-icon')); |
| 11 |
const rh_ui_error_fill_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-ui-error-fill-icon')); |
| 12 |
const rh_ui_warning_fill_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-ui-warning-fill-icon')); |
| 13 |
const ProgressBar_1 = require("./ProgressBar"); |
| 14 |
const ProgressHelperText_1 = require("./ProgressHelperText"); |
| 15 |
var ProgressMeasureLocation; |
| 16 |
(function (ProgressMeasureLocation) { |
| 17 |
ProgressMeasureLocation["outside"] = "outside"; |
| 18 |
ProgressMeasureLocation["inside"] = "inside"; |
| 19 |
ProgressMeasureLocation["top"] = "top"; |
| 20 |
ProgressMeasureLocation["none"] = "none"; |
| 21 |
})(ProgressMeasureLocation || (exports.ProgressMeasureLocation = ProgressMeasureLocation = {})); |
| 22 |
var ProgressVariant; |
| 23 |
(function (ProgressVariant) { |
| 24 |
ProgressVariant["danger"] = "danger"; |
| 25 |
ProgressVariant["success"] = "success"; |
| 26 |
ProgressVariant["warning"] = "warning"; |
| 27 |
})(ProgressVariant || (exports.ProgressVariant = ProgressVariant = {})); |
| 28 |
const variantToIcon = { |
| 29 |
danger: rh_ui_error_fill_icon_1.default, |
| 30 |
success: rh_ui_check_circle_fill_icon_1.default, |
| 31 |
warning: rh_ui_warning_fill_icon_1.default |
| 32 |
}; |
| 33 |
const ProgressContainer = ({ progressBarAriaProps, value, title = '', parentId, label = null, variant = null, measureLocation = ProgressMeasureLocation.top, isTitleTruncated = false, tooltipPosition, helperText, hideStatusIcon = false }) => { |
| 34 |
const StatusIcon = !hideStatusIcon && variantToIcon.hasOwnProperty(variant) && variantToIcon[variant]; |
| 35 |
const [tooltip, setTooltip] = (0, react_1.useState)(''); |
| 36 |
const titleRef = (0, react_1.useRef)(null); |
| 37 |
const updateTooltip = (event) => { |
| 38 |
if (event.target.offsetWidth < event.target.scrollWidth) { |
| 39 |
setTooltip(title || event.target.innerHTML); |
| 40 |
} |
| 41 |
else { |
| 42 |
setTooltip(''); |
| 43 |
} |
| 44 |
}; |
| 45 |
(0, react_1.useEffect)(() => { |
| 46 |
if (tooltip !== '') { |
| 47 |
titleRef.current.focus(); |
| 48 |
} |
| 49 |
}, [tooltip]); |
| 50 |
const _isTruncatedAndString = isTitleTruncated && typeof title === 'string'; |
| 51 |
const Title = ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, react_styles_1.css)(progress_1.default.progressDescription, _isTruncatedAndString && progress_1.default.modifiers.truncate), id: `${parentId}-description`, "aria-hidden": _isTruncatedAndString ? null : 'true', onMouseEnter: _isTruncatedAndString ? updateTooltip : null, onFocus: _isTruncatedAndString ? updateTooltip : null }, (_isTruncatedAndString && { tabIndex: 0 }), { ref: titleRef, children: title }))); |
| 52 |
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [title && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [tooltip && (0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { position: tooltipPosition, content: tooltip, isVisible: true, triggerRef: titleRef }), Title] })), (measureLocation !== ProgressMeasureLocation.none || StatusIcon) && ((0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(progress_1.default.progressStatus), "aria-hidden": "true", children: [(measureLocation === ProgressMeasureLocation.top || measureLocation === ProgressMeasureLocation.outside) && ((0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(progress_1.default.progressMeasure), children: label || `${value}%` })), StatusIcon && ((0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(progress_1.default.progressStatusIcon), children: (0, jsx_runtime_1.jsx)(StatusIcon, {}) }))] })), (0, jsx_runtime_1.jsx)(ProgressBar_1.ProgressBar, { progressBarAriaProps: progressBarAriaProps, value: value, children: measureLocation === ProgressMeasureLocation.inside && `${value}%` }), helperText && (0, jsx_runtime_1.jsx)(ProgressHelperText_1.ProgressHelperText, { children: helperText })] })); |
| 53 |
}; |
| 54 |
exports.ProgressContainer = ProgressContainer; |
| 55 |
exports.ProgressContainer.displayName = 'ProgressContainer'; |
| 56 |
//# sourceMappingURL=ProgressContainer.js.map |