UNPKG

2.02 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.AlertGroup = void 0;
4const tslib_1 = require("tslib");
5const React = tslib_1.__importStar(require("react"));
6const ReactDOM = tslib_1.__importStar(require("react-dom"));
7const helpers_1 = require("../../helpers");
8const AlertGroupInline_1 = require("./AlertGroupInline");
9class AlertGroup extends React.Component {
10 constructor() {
11 super(...arguments);
12 this.state = {
13 container: undefined
14 };
15 }
16 componentDidMount() {
17 const container = document.createElement('div');
18 const target = this.getTargetElement();
19 this.setState({ container });
20 target.appendChild(container);
21 }
22 componentWillUnmount() {
23 const target = this.getTargetElement();
24 if (this.state.container) {
25 target.removeChild(this.state.container);
26 }
27 }
28 getTargetElement() {
29 const appendTo = this.props.appendTo;
30 if (typeof appendTo === 'function') {
31 return appendTo();
32 }
33 return appendTo || document.body;
34 }
35 render() {
36 const _a = this.props, { className, children, isToast, isLiveRegion, onOverflowClick, overflowMessage } = _a, props = tslib_1.__rest(_a, ["className", "children", "isToast", "isLiveRegion", "onOverflowClick", "overflowMessage"]);
37 const alertGroup = (React.createElement(AlertGroupInline_1.AlertGroupInline, Object.assign({ onOverflowClick: onOverflowClick, className: className, isToast: isToast, isLiveRegion: isLiveRegion, overflowMessage: overflowMessage }, props), children));
38 if (!this.props.isToast) {
39 return alertGroup;
40 }
41 const container = this.state.container;
42 if (!helpers_1.canUseDOM || !container) {
43 return null;
44 }
45 return ReactDOM.createPortal(alertGroup, container);
46 }
47}
48exports.AlertGroup = AlertGroup;
49AlertGroup.displayName = 'AlertGroup';
50//# sourceMappingURL=AlertGroup.js.map
\No newline at end of file