| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.ModalContent = void 0; |
| 4 |
const tslib_1 = require("tslib"); |
| 5 |
const jsx_runtime_1 = require("react/jsx-runtime"); |
| 6 |
const helpers_1 = require("../../../helpers"); |
| 7 |
const modal_box_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/ModalBox/modal-box")); |
| 8 |
const bullseye_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/layouts/Bullseye/bullseye")); |
| 9 |
const react_styles_1 = require("@patternfly/react-styles"); |
| 10 |
const helpers_2 = require("../../../helpers"); |
| 11 |
const Backdrop_1 = require("../../../components/Backdrop/Backdrop"); |
| 12 |
const ModalBoxBody_1 = require("./ModalBoxBody"); |
| 13 |
const ModalBoxCloseButton_1 = require("./ModalBoxCloseButton"); |
| 14 |
const ModalBox_1 = require("./ModalBox"); |
| 15 |
const ModalBoxFooter_1 = require("./ModalBoxFooter"); |
| 16 |
const ModalBoxDescription_1 = require("./ModalBoxDescription"); |
| 17 |
const ModalBoxHeader_1 = require("./ModalBoxHeader"); |
| 18 |
const ModalBoxTitle_1 = require("./ModalBoxTitle"); |
| 19 |
const ModalContent = (_a) => { |
| 20 |
var { children, className = '', isOpen = false, header = null, help = null, description = null, title = '', titleIconVariant = null, titleLabel = '', 'aria-label': ariaLabel = '', 'aria-describedby': ariaDescribedby, 'aria-labelledby': ariaLabelledby, bodyAriaLabel, bodyAriaRole, showClose = true, footer = null, actions = [], onClose = () => undefined, variant = 'default', position, positionOffset, width, maxWidth, boxId, labelId, backdropId, descriptorId, disableFocusTrap = false, hasNoBodyWrapper = false, ouiaId, ouiaSafe = true, elementToFocus } = _a, props = tslib_1.__rest(_a, ["children", "className", "isOpen", "header", "help", "description", "title", "titleIconVariant", "titleLabel", 'aria-label', 'aria-describedby', 'aria-labelledby', "bodyAriaLabel", "bodyAriaRole", "showClose", "footer", "actions", "onClose", "variant", "position", "positionOffset", "width", "maxWidth", "boxId", "labelId", "backdropId", "descriptorId", "disableFocusTrap", "hasNoBodyWrapper", "ouiaId", "ouiaSafe", "elementToFocus"]); |
| 21 |
if (!isOpen) { |
| 22 |
return null; |
| 23 |
} |
| 24 |
const modalBoxHeader = header ? ((0, jsx_runtime_1.jsx)(ModalBoxHeader_1.ModalBoxHeader, { help: help, children: header })) : (title && ((0, jsx_runtime_1.jsxs)(ModalBoxHeader_1.ModalBoxHeader, { help: help, children: [(0, jsx_runtime_1.jsx)(ModalBoxTitle_1.ModalBoxTitle, { title: title, titleIconVariant: titleIconVariant, titleLabel: titleLabel, id: labelId }), description && (0, jsx_runtime_1.jsx)(ModalBoxDescription_1.ModalBoxDescription, { id: descriptorId, children: description })] }))); |
| 25 |
const modalBoxFooter = footer ? ((0, jsx_runtime_1.jsx)(ModalBoxFooter_1.ModalBoxFooter, { children: footer })) : (actions.length > 0 && (0, jsx_runtime_1.jsx)(ModalBoxFooter_1.ModalBoxFooter, { children: actions })); |
| 26 |
const defaultModalBodyAriaRole = bodyAriaLabel ? 'region' : undefined; |
| 27 |
const hasNoDescription = !description && !ariaDescribedby; |
| 28 |
const id = hasNoDescription ? descriptorId : undefined; |
| 29 |
const modalBody = hasNoBodyWrapper ? (children) : ((0, jsx_runtime_1.jsx)(ModalBoxBody_1.ModalBoxBody, Object.assign({ "aria-label": bodyAriaLabel, role: bodyAriaRole || defaultModalBodyAriaRole }, props, { id: id, children: children }))); |
| 30 |
const ariaLabelledbyFormatted = () => { |
| 31 |
if (ariaLabelledby === null) { |
| 32 |
return null; |
| 33 |
} |
| 34 |
const idRefList = []; |
| 35 |
if ((ariaLabel && boxId) !== '') { |
| 36 |
idRefList.push(ariaLabel && boxId); |
| 37 |
} |
| 38 |
if (ariaLabelledby) { |
| 39 |
idRefList.push(ariaLabelledby); |
| 40 |
} |
| 41 |
if (title) { |
| 42 |
idRefList.push(labelId); |
| 43 |
} |
| 44 |
return idRefList.join(' '); |
| 45 |
}; |
| 46 |
const modalBox = ((0, jsx_runtime_1.jsxs)(ModalBox_1.ModalBox, Object.assign({ id: boxId, className: (0, react_styles_1.css)(className, (0, ModalBoxTitle_1.isVariantIcon)(titleIconVariant) && modal_box_1.default.modifiers[titleIconVariant]), variant: variant, position: position, positionOffset: positionOffset, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledbyFormatted(), "aria-describedby": ariaDescribedby || (hasNoBodyWrapper ? null : descriptorId) }, (0, helpers_2.getOUIAProps)(exports.ModalContent.displayName, ouiaId, ouiaSafe), { style: Object.assign(Object.assign({}, (width && { '--pf-v6-c-modal-box--Width': typeof width !== 'number' ? width : `${width}px` })), (maxWidth && { |
| 47 |
'--pf-v6-c-modal-box--MaxWidth': typeof maxWidth !== 'number' ? maxWidth : `${maxWidth}px` |
| 48 |
})), children: [showClose && (0, jsx_runtime_1.jsx)(ModalBoxCloseButton_1.ModalBoxCloseButton, { onClose: (event) => onClose(event), ouiaId: ouiaId }), modalBoxHeader, modalBody, modalBoxFooter] }))); |
| 49 |
return ((0, jsx_runtime_1.jsx)(Backdrop_1.Backdrop, { id: backdropId, children: (0, jsx_runtime_1.jsx)(helpers_1.FocusTrap, { active: !disableFocusTrap, focusTrapOptions: { |
| 50 |
clickOutsideDeactivates: true, |
| 51 |
tabbableOptions: { displayCheck: 'none' }, |
| 52 |
// FocusTrap's initialFocus can accept false as a value to prevent initial focus. |
| 53 |
// We want to prevent this in case false is ever passed in. |
| 54 |
initialFocus: elementToFocus || undefined |
| 55 |
}, className: (0, react_styles_1.css)(bullseye_1.default.bullseye), children: modalBox }) })); |
| 56 |
}; |
| 57 |
exports.ModalContent = ModalContent; |
| 58 |
exports.ModalContent.displayName = 'ModalContent'; |
| 59 |
//# sourceMappingURL=ModalContent.js.map |