UNPKG

cosmo-ui

Version:
30 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var OpenableComponent = (function (_super) { tslib_1.__extends(OpenableComponent, _super); function OpenableComponent(props) { var _this = _super.call(this, props) || this; _this.setContainerRef = function (e) { return _this.container = e; }; _this.handleClickAway = function (event) { // clicking away from the component should close it // console.log('HANDLE CLICK AWAY', this.props, this.container) if (_this.isActive() && !_this.container.contains(event.target)) { _this.handleClose(); } }; _this.isActive = _this.isActive.bind(_this); _this.handleClose = _this.handleClose.bind(_this); return _this; } OpenableComponent.prototype.componentDidMount = function () { document.addEventListener('click', this.handleClickAway); }; OpenableComponent.prototype.componentWillUnmount = function () { document.removeEventListener('click', this.handleClickAway); }; return OpenableComponent; }(React.Component)); exports.OpenableComponent = OpenableComponent; //# sourceMappingURL=openable-component.js.map