ukelli-ui
Version:
Base on React's UI lib. Make frontend's dev simpler and faster.
51 lines (50 loc) • 1.92 kB
JavaScript
/* eslint-disable react/no-find-dom-node */
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { Component } from 'react';
import ReactDOM from 'react-dom';
var ClickAway = /** @class */ (function (_super) {
__extends(ClickAway, _super);
function ClickAway() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.__mounted = false;
_this.handleClick = function (event) {
if (event.defaultPrevented || !_this.node || !_this.__mounted)
return;
if (!_this.node.contains(event.target)) {
_this.props.onClickAway(event);
}
};
_this.updateNodeRef = function () {
_this.node = ReactDOM.findDOMNode(_this);
};
return _this;
}
ClickAway.prototype.componentDidMount = function () {
// this.node = ReactDOM.findDOMNode(this);
this.updateNodeRef();
this.__mounted = true;
document.addEventListener('click', this.handleClick);
};
ClickAway.prototype.componentWillUnmount = function () {
document.removeEventListener('click', this.handleClick);
this.__mounted = false;
};
ClickAway.prototype.render = function () {
var children = this.props.children;
return children;
};
return ClickAway;
}(Component));
export default ClickAway;