| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; |
| 3 |
import { useRef, useState } from 'react'; |
| 4 |
import modalStyles from '@patternfly/react-styles/css/components/ModalBox/modal-box.mjs'; |
| 5 |
import { css } from '@patternfly/react-styles'; |
| 6 |
import { capitalize } from '../../helpers'; |
| 7 |
import { Tooltip } from '../Tooltip'; |
| 8 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 9 |
import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; |
| 10 |
import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon'; |
| 11 |
import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon'; |
| 12 |
import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon'; |
| 13 |
import { useIsomorphicLayoutEffect } from '../../helpers'; |
| 14 |
export const isVariantIcon = (icon) => ['success', 'danger', 'warning', 'info', 'custom'].includes(icon); |
| 15 |
export const ModalBoxTitle = (_a) => { |
| 16 |
var { className, id, title, titleIconVariant, titleScreenReaderText } = _a, props = __rest(_a, ["className", "id", "title", "titleIconVariant", "titleScreenReaderText"]); |
| 17 |
const [hasTooltip, setHasTooltip] = useState(false); |
| 18 |
const h1 = useRef(null); |
| 19 |
const label = titleScreenReaderText || |
| 20 |
(isVariantIcon(titleIconVariant) ? `${capitalize(titleIconVariant)} alert:` : titleScreenReaderText); |
| 21 |
const variantIcons = { |
| 22 |
success: _jsx(RhUiCheckCircleFillIcon, {}), |
| 23 |
danger: _jsx(RhUiErrorFillIcon, {}), |
| 24 |
warning: _jsx(RhUiWarningFillIcon, {}), |
| 25 |
info: _jsx(RhUiInformationFillIcon, {}), |
| 26 |
custom: _jsx(RhUiNotificationFillIcon, {}) |
| 27 |
}; |
| 28 |
const CustomIcon = !isVariantIcon(titleIconVariant) && titleIconVariant; |
| 29 |
useIsomorphicLayoutEffect(() => { |
| 30 |
setHasTooltip(h1.current && h1.current.offsetWidth < h1.current.scrollWidth); |
| 31 |
}, []); |
| 32 |
const content = (_jsxs("h1", Object.assign({ id: id, ref: h1, className: css(modalStyles.modalBoxTitle, titleIconVariant && modalStyles.modifiers.icon, isVariantIcon(titleIconVariant) && modalStyles.modifiers[titleIconVariant], className) }, props, { children: [titleIconVariant && (_jsx("span", { className: css(modalStyles.modalBoxTitleIcon), children: isVariantIcon(titleIconVariant) ? variantIcons[titleIconVariant] : _jsx(CustomIcon, {}) })), label && _jsx("span", { className: "pf-v6-screen-reader", children: label }), _jsx("span", { className: css(modalStyles.modalBoxTitleText), children: title })] }))); |
| 33 |
return hasTooltip ? _jsx(Tooltip, { content: title, children: content }) : content; |
| 34 |
}; |
| 35 |
ModalBoxTitle.displayName = 'ModalBoxTitle'; |
| 36 |
//# sourceMappingURL=ModalBoxTitle.js.map |