Debian Codegraph @

node/@patternfly/react-core/dist/js/components/Alert/AlertGroup.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.AlertGroup = 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 ReactDOM = tslib_1.__importStar(require("react-dom"));
8 const helpers_1 = require("../../helpers");
9 const AlertGroupInline_1 = require("./AlertGroupInline");
10 const helpers_2 = require("../../helpers");
11 const AlertGroup = (_a) => {
12 var { className, children, hasAnimations: hasAnimationsProp, isToast, isLiveRegion, onOverflowClick, overflowMessage, 'aria-label': ariaLabel, appendTo } = _a, props = tslib_1.__rest(_a, ["className", "children", "hasAnimations", "isToast", "isLiveRegion", "onOverflowClick", "overflowMessage", 'aria-label', "appendTo"]);
13 const containerRef = (0, react_1.useRef)(null);
14 const [isContainerReady, setIsContainerReady] = (0, react_1.useState)(false);
15 const hasAnimations = (0, helpers_2.useHasAnimations)(hasAnimationsProp);
16 const getTargetElement = () => {
17 if (typeof appendTo === 'function') {
18 return appendTo();
19 }
20 return appendTo || document.body;
21 };
22 (0, react_1.useEffect)(() => {
23 if (isToast && helpers_1.canUseDOM) {
24 const container = document.createElement('div');
25 const target = getTargetElement();
26 containerRef.current = container;
27 target.appendChild(container);
28 setIsContainerReady(true);
29 return () => {
30 if (containerRef.current) {
31 target.removeChild(containerRef.current);
32 containerRef.current = null;
33 }
34 setIsContainerReady(false);
35 };
36 }
37 }, [isToast, appendTo]);
38 const alertGroup = ((0, jsx_runtime_1.jsx)(AlertGroupInline_1.AlertGroupInline, Object.assign({ onOverflowClick: onOverflowClick, className: className, isToast: isToast, isLiveRegion: isLiveRegion, overflowMessage: overflowMessage, "aria-label": ariaLabel, hasAnimations: hasAnimations }, props, { children: children })));
39 if (!isToast) {
40 return alertGroup;
41 }
42 const container = containerRef.current;
43 if (!helpers_1.canUseDOM || !container || !isContainerReady) {
44 return null;
45 }
46 return ReactDOM.createPortal(alertGroup, container);
47 };
48 exports.AlertGroup = AlertGroup;
49 exports.AlertGroup.displayName = 'AlertGroup';
50 //# sourceMappingURL=AlertGroup.js.map