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