react-popup-manager
Version:
Manage react popups, Modals, Lightboxes, Notifications, etc. easily
92 lines • 4.12 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PopupsWrapper = void 0;
var React = require("react");
var SinglePopupLifeCycle = /** @class */ (function (_super) {
__extends(SinglePopupLifeCycle, _super);
function SinglePopupLifeCycle(props) {
var _this = _super.call(this, props) || this;
_this.state = { isOpen: false };
_this.onClose = _this.onClose.bind(_this);
return _this;
}
SinglePopupLifeCycle.prototype.componentDidMount = function () {
if (this.props.isOpen === true) {
this.setState({ isOpen: true });
}
};
SinglePopupLifeCycle.getDerivedStateFromProps = function (nextProps, prevState) {
if (nextProps.isOpen === false) {
return { isOpen: false };
}
return null;
};
SinglePopupLifeCycle.prototype.onClose = function () {
var _a;
var closeArgs = [];
for (var _i = 0; _i < arguments.length; _i++) {
closeArgs[_i] = arguments[_i];
}
var _b = this.props, currentPopup = _b.currentPopup, onClose = _b.onClose;
if ((_a = currentPopup.props) === null || _a === void 0 ? void 0 : _a.onClose) {
onClose(currentPopup.guid, function () { var _a; return (_a = currentPopup.props) === null || _a === void 0 ? void 0 : _a.onClose.apply(_a, closeArgs); }, closeArgs);
}
else {
onClose(currentPopup.guid, undefined, closeArgs);
}
};
SinglePopupLifeCycle.prototype.render = function () {
var currentPopup = this.props.currentPopup;
return (React.createElement(currentPopup.ComponentClass, __assign({ isOpen: this.state.isOpen }, currentPopup.props, { onClose: this.onClose })));
};
return SinglePopupLifeCycle;
}(React.Component));
var PopupsWrapper = /** @class */ (function (_super) {
__extends(PopupsWrapper, _super);
function PopupsWrapper(props) {
var _this = _super.call(this, props) || this;
_this.onClose = _this.onClose.bind(_this);
return _this;
}
PopupsWrapper.prototype.componentDidMount = function () {
var _this = this;
this.props.popupManager.subscribeOnPopupsChange(function () { return _this.forceUpdate(); });
};
PopupsWrapper.prototype.onClose = function (guid, onConsumerOnCloseCallback, closedArgs) {
this.props.popupManager.close(guid, onConsumerOnCloseCallback, closedArgs);
};
PopupsWrapper.prototype.render = function () {
var _this = this;
var popupManager = this.props.popupManager;
return popupManager.popups.map(function (currentPopup) { return (React.createElement(SinglePopupLifeCycle, { currentPopup: currentPopup, key: currentPopup.guid, isOpen: currentPopup.isOpen, onClose: _this.onClose })); });
};
return PopupsWrapper;
}(React.Component));
exports.PopupsWrapper = PopupsWrapper;
//# sourceMappingURL=PopupsWrapper.js.map