cosmo-ui
Version:
Common React components
52 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var react_redux_1 = require("react-redux");
var modal_1 = require("../../actions/modal");
var reducers_1 = require("../../reducers");
var styles = require('../../../src/styles/components/modal.scss');
var MODAL_COMPONENTS = {};
exports.registerModalComponent = function (id, component) {
MODAL_COMPONENTS[id] = component;
};
var _ModalRoot = (function (_super) {
tslib_1.__extends(_ModalRoot, _super);
function _ModalRoot(props) {
var _this = _super.call(this, props) || this;
_this.handleKeyDown = function (_a) {
var code = _a.code;
if (code.toLowerCase() === 'escape') {
_this.props.closeModal();
}
};
return _this;
}
_ModalRoot.prototype.componentDidMount = function () {
document.addEventListener('keydown', this.handleKeyDown);
};
_ModalRoot.prototype.componentWillUnmount = function () {
document.removeEventListener('keydown', this.handleKeyDown);
};
_ModalRoot.prototype.render = function () {
var state = this.props.state;
var modalProps = state.modalProps || {};
if (!state || state.modalType === '')
return null;
var SpecificModal = MODAL_COMPONENTS[state.modalType];
console.log('RENDERING SPECIFIC MODAL', MODAL_COMPONENTS, state.modalType, SpecificModal);
if (!SpecificModal)
return null;
return (React.createElement("div", { className: styles.modalContainer },
React.createElement(SpecificModal, tslib_1.__assign({}, this.props))));
};
return _ModalRoot;
}(React.Component));
var mapStateToProps = function (state, ownProps) { return ({
state: state[reducers_1.MODAL_REDUCER_KEY],
}); };
var mapActionsToProps = {
closeModal: modal_1.hideModal,
};
exports.ModalRoot = react_redux_1.connect(mapStateToProps, mapActionsToProps)(_ModalRoot);
//# sourceMappingURL=modal-root.js.map