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