| 1 |
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; |
| 2 |
import { Fragment, useState, useRef, useEffect } from 'react'; |
| 3 |
import progressStyle from '@patternfly/react-styles/css/components/Progress/progress.mjs'; |
| 4 |
import { css } from '@patternfly/react-styles'; |
| 5 |
import { Tooltip } from '../Tooltip'; |
| 6 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 7 |
import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; |
| 8 |
import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon'; |
| 9 |
import { ProgressBar } from './ProgressBar'; |
| 10 |
import { ProgressHelperText } from './ProgressHelperText'; |
| 11 |
export var ProgressMeasureLocation; |
| 12 |
(function (ProgressMeasureLocation) { |
| 13 |
ProgressMeasureLocation["outside"] = "outside"; |
| 14 |
ProgressMeasureLocation["inside"] = "inside"; |
| 15 |
ProgressMeasureLocation["top"] = "top"; |
| 16 |
ProgressMeasureLocation["none"] = "none"; |
| 17 |
})(ProgressMeasureLocation || (ProgressMeasureLocation = {})); |
| 18 |
export var ProgressVariant; |
| 19 |
(function (ProgressVariant) { |
| 20 |
ProgressVariant["danger"] = "danger"; |
| 21 |
ProgressVariant["success"] = "success"; |
| 22 |
ProgressVariant["warning"] = "warning"; |
| 23 |
})(ProgressVariant || (ProgressVariant = {})); |
| 24 |
const variantToIcon = { |
| 25 |
danger: RhUiErrorFillIcon, |
| 26 |
success: RhUiCheckCircleFillIcon, |
| 27 |
warning: RhUiWarningFillIcon |
| 28 |
}; |
| 29 |
export const ProgressContainer = ({ progressBarAriaProps, value, title = '', parentId, label = null, variant = null, measureLocation = ProgressMeasureLocation.top, isTitleTruncated = false, tooltipPosition, helperText, hideStatusIcon = false }) => { |
| 30 |
const StatusIcon = !hideStatusIcon && variantToIcon.hasOwnProperty(variant) && variantToIcon[variant]; |
| 31 |
const [tooltip, setTooltip] = useState(''); |
| 32 |
const titleRef = useRef(null); |
| 33 |
const updateTooltip = (event) => { |
| 34 |
if (event.target.offsetWidth < event.target.scrollWidth) { |
| 35 |
setTooltip(title || event.target.innerHTML); |
| 36 |
} |
| 37 |
else { |
| 38 |
setTooltip(''); |
| 39 |
} |
| 40 |
}; |
| 41 |
useEffect(() => { |
| 42 |
if (tooltip !== '') { |
| 43 |
titleRef.current.focus(); |
| 44 |
} |
| 45 |
}, [tooltip]); |
| 46 |
const _isTruncatedAndString = isTitleTruncated && typeof title === 'string'; |
| 47 |
const Title = (_jsx("div", Object.assign({ className: css(progressStyle.progressDescription, _isTruncatedAndString && progressStyle.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 }))); |
| 48 |
return (_jsxs(Fragment, { children: [title && (_jsxs(_Fragment, { children: [tooltip && _jsx(Tooltip, { position: tooltipPosition, content: tooltip, isVisible: true, triggerRef: titleRef }), Title] })), (measureLocation !== ProgressMeasureLocation.none || StatusIcon) && (_jsxs("div", { className: css(progressStyle.progressStatus), "aria-hidden": "true", children: [(measureLocation === ProgressMeasureLocation.top || measureLocation === ProgressMeasureLocation.outside) && (_jsx("span", { className: css(progressStyle.progressMeasure), children: label || `${value}%` })), StatusIcon && (_jsx("span", { className: css(progressStyle.progressStatusIcon), children: _jsx(StatusIcon, {}) }))] })), _jsx(ProgressBar, { progressBarAriaProps: progressBarAriaProps, value: value, children: measureLocation === ProgressMeasureLocation.inside && `${value}%` }), helperText && _jsx(ProgressHelperText, { children: helperText })] })); |
| 49 |
}; |
| 50 |
ProgressContainer.displayName = 'ProgressContainer'; |
| 51 |
//# sourceMappingURL=ProgressContainer.js.map |