Debian Codegraph @

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

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.AlertGroupInline = 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 react_styles_1 = require("@patternfly/react-styles");
8 const alert_group_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Alert/alert-group"));
9 const AlertGroupContext_1 = require("./AlertGroupContext");
10 const helpers_1 = require("../../helpers");
11 const AlertGroupInline = (_a) => {
12 var { className, children, hasAnimations: hasAnimationsProp, isToast, isLiveRegion, onOverflowClick, overflowMessage } = _a, props = tslib_1.__rest(_a, ["className", "children", "hasAnimations", "isToast", "isLiveRegion", "onOverflowClick", "overflowMessage"]);
13 const hasAnimations = (0, helpers_1.useHasAnimations)(hasAnimationsProp);
14 const [handleTransitionEnd, setHandleTransitionEnd] = (0, react_1.useState)(() => () => { });
15 const updateTransitionEnd = (onTransitionEnd) => {
16 setHandleTransitionEnd(() => onTransitionEnd);
17 };
18 // Clear transition callback on unmount to prevent memory leaks
19 (0, react_1.useEffect)(() => () => {
20 setHandleTransitionEnd(() => () => { });
21 }, []);
22 const onTransitionEnd = (event) => {
23 var _a;
24 if (!hasAnimations) {
25 return;
26 }
27 const prefersReducedMotion = !((_a = window.matchMedia('(prefers-reduced-motion: no-preference)')) === null || _a === void 0 ? void 0 : _a.matches);
28 if (
29 // If a user has no motion preference, we want to target the grid template rows transition
30 // so that the onClose is called after the "slide up" animation of other alerts finishes.
31 // If they have motion preference, we don't need to check for a specific transition since only opacity should fire.
32 (prefersReducedMotion || (!prefersReducedMotion && event.propertyName === 'grid-template-rows')) &&
33 event.target.className.includes(alert_group_1.default.modifiers.offstageRight)) {
34 handleTransitionEnd();
35 // Clear the callback after execution to prevent memory retention
36 setHandleTransitionEnd(() => () => { });
37 }
38 };
39 return ((0, jsx_runtime_1.jsx)(AlertGroupContext_1.AlertGroupContext.Provider, { value: { hasAnimations, updateTransitionEnd }, children: (0, jsx_runtime_1.jsxs)("ul", Object.assign({ role: "list", "aria-live": isLiveRegion ? 'polite' : null, "aria-atomic": isLiveRegion ? false : null, className: (0, react_styles_1.css)(alert_group_1.default.alertGroup, className, isToast ? alert_group_1.default.modifiers.toast : '') }, props, { children: [react_1.Children.toArray(children).map((alert, index) => {
40 var _a;
41 return ((0, jsx_runtime_1.jsx)("li", { onTransitionEnd: onTransitionEnd, className: (0, react_styles_1.css)(alert_group_1.default.alertGroupItem, hasAnimations && alert_group_1.default.modifiers.offstageTop), children: alert }, ((_a = alert.props) === null || _a === void 0 ? void 0 : _a.id) ||
42 `alertGroupItem-${alert.key}` ||
43 index));
44 }), overflowMessage && ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)("button", { onClick: onOverflowClick, className: (0, react_styles_1.css)(alert_group_1.default.alertGroupOverflowButton), children: overflowMessage }) }))] })) }));
45 };
46 exports.AlertGroupInline = AlertGroupInline;
47 exports.AlertGroupInline.displayName = 'AlertGroupInline';
48 //# sourceMappingURL=AlertGroupInline.js.map