Debian Codegraph @

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

raw
1 import { __rest } from "tslib";
2 import { jsx as _jsx } from "react/jsx-runtime";
3 import { useEffect, useRef, useState } from 'react';
4 import * as ReactDOM from 'react-dom';
5 import { canUseDOM } from '../../helpers';
6 import { AlertGroupInline } from './AlertGroupInline';
7 import { useHasAnimations } from '../../helpers';
8 export const AlertGroup = (_a) => {
9 var { className, children, hasAnimations: hasAnimationsProp, isToast, isLiveRegion, onOverflowClick, overflowMessage, 'aria-label': ariaLabel, appendTo } = _a, props = __rest(_a, ["className", "children", "hasAnimations", "isToast", "isLiveRegion", "onOverflowClick", "overflowMessage", 'aria-label', "appendTo"]);
10 const containerRef = useRef(null);
11 const [isContainerReady, setIsContainerReady] = useState(false);
12 const hasAnimations = useHasAnimations(hasAnimationsProp);
13 const getTargetElement = () => {
14 if (typeof appendTo === 'function') {
15 return appendTo();
16 }
17 return appendTo || document.body;
18 };
19 useEffect(() => {
20 if (isToast && canUseDOM) {
21 const container = document.createElement('div');
22 const target = getTargetElement();
23 containerRef.current = container;
24 target.appendChild(container);
25 setIsContainerReady(true);
26 return () => {
27 if (containerRef.current) {
28 target.removeChild(containerRef.current);
29 containerRef.current = null;
30 }
31 setIsContainerReady(false);
32 };
33 }
34 }, [isToast, appendTo]);
35 const alertGroup = (_jsx(AlertGroupInline, Object.assign({ onOverflowClick: onOverflowClick, className: className, isToast: isToast, isLiveRegion: isLiveRegion, overflowMessage: overflowMessage, "aria-label": ariaLabel, hasAnimations: hasAnimations }, props, { children: children })));
36 if (!isToast) {
37 return alertGroup;
38 }
39 const container = containerRef.current;
40 if (!canUseDOM || !container || !isContainerReady) {
41 return null;
42 }
43 return ReactDOM.createPortal(alertGroup, container);
44 };
45 AlertGroup.displayName = 'AlertGroup';
46 //# sourceMappingURL=AlertGroup.js.map