| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.AlertActionCloseButton = 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 Button_1 = require("../Button"); |
| 8 |
const rh_microns_close_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-microns-close-icon')); |
| 9 |
const AlertContext_1 = require("./AlertContext"); |
| 10 |
const AlertGroupContext_1 = require("./AlertGroupContext"); |
| 11 |
const alert_group_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Alert/alert-group")); |
| 12 |
const AlertActionCloseButton = (_a) => { |
| 13 |
var { className, onClose = () => undefined, 'aria-label': ariaLabel = '', variantLabel } = _a, props = tslib_1.__rest(_a, ["className", "onClose", 'aria-label', "variantLabel"]); |
| 14 |
const closeButtonRef = (0, react_1.useRef)(null); |
| 15 |
const { hasAnimations, updateTransitionEnd } = (0, react_1.useContext)(AlertGroupContext_1.AlertGroupContext); |
| 16 |
const { offstageRight } = alert_group_1.default.modifiers; |
| 17 |
const getParentAlertGroupItem = () => { var _a; return (_a = closeButtonRef.current) === null || _a === void 0 ? void 0 : _a.closest(`.${alert_group_1.default.alertGroupItem}`); }; |
| 18 |
const handleOnClick = () => { |
| 19 |
var _a; |
| 20 |
if (hasAnimations) { |
| 21 |
(_a = getParentAlertGroupItem()) === null || _a === void 0 ? void 0 : _a.classList.add(offstageRight); |
| 22 |
updateTransitionEnd(onClose); |
| 23 |
} |
| 24 |
else { |
| 25 |
onClose(); |
| 26 |
} |
| 27 |
}; |
| 28 |
return ((0, jsx_runtime_1.jsx)(AlertContext_1.AlertContext.Consumer, { children: ({ title, variantLabel: alertVariantLabel }) => ((0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ ref: closeButtonRef, variant: Button_1.ButtonVariant.plain, onClick: handleOnClick, "aria-label": ariaLabel === '' ? `Close ${variantLabel || alertVariantLabel} alert: ${title}` : ariaLabel, className: className, icon: (0, jsx_runtime_1.jsx)(rh_microns_close_icon_1.default, {}) }, props))) })); |
| 29 |
}; |
| 30 |
exports.AlertActionCloseButton = AlertActionCloseButton; |
| 31 |
exports.AlertActionCloseButton.displayName = 'AlertActionCloseButton'; |
| 32 |
//# sourceMappingURL=AlertActionCloseButton.js.map |