Debian Codegraph @

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

raw
1 import { __rest } from "tslib";
2 import { jsx as _jsx } from "react/jsx-runtime";
3 import { useRef, useContext } from 'react';
4 import { Button, ButtonVariant } from '../Button';
5 import RhMicronsCloseIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-close-icon';
6 import { AlertContext } from './AlertContext';
7 import { AlertGroupContext } from './AlertGroupContext';
8 import alertGroupStyles from '@patternfly/react-styles/css/components/Alert/alert-group.mjs';
9 export const AlertActionCloseButton = (_a) => {
10 var { className, onClose = () => undefined, 'aria-label': ariaLabel = '', variantLabel } = _a, props = __rest(_a, ["className", "onClose", 'aria-label', "variantLabel"]);
11 const closeButtonRef = useRef(null);
12 const { hasAnimations, updateTransitionEnd } = useContext(AlertGroupContext);
13 const { offstageRight } = alertGroupStyles.modifiers;
14 const getParentAlertGroupItem = () => { var _a; return (_a = closeButtonRef.current) === null || _a === void 0 ? void 0 : _a.closest(`.${alertGroupStyles.alertGroupItem}`); };
15 const handleOnClick = () => {
16 var _a;
17 if (hasAnimations) {
18 (_a = getParentAlertGroupItem()) === null || _a === void 0 ? void 0 : _a.classList.add(offstageRight);
19 updateTransitionEnd(onClose);
20 }
21 else {
22 onClose();
23 }
24 };
25 return (_jsx(AlertContext.Consumer, { children: ({ title, variantLabel: alertVariantLabel }) => (_jsx(Button, Object.assign({ ref: closeButtonRef, variant: ButtonVariant.plain, onClick: handleOnClick, "aria-label": ariaLabel === '' ? `Close ${variantLabel || alertVariantLabel} alert: ${title}` : ariaLabel, className: className, icon: _jsx(RhMicronsCloseIcon, {}) }, props))) }));
26 };
27 AlertActionCloseButton.displayName = 'AlertActionCloseButton';
28 //# sourceMappingURL=AlertActionCloseButton.js.map