beyond-components
Version:
react prototype components
45 lines (43 loc) • 1.58 kB
JavaScript
;
/*
<TooltipTrigger tooltip={<Tooltip duration={3}>hello world<Tooltip/>} >
<button>hover</button>
</TooltipTrigger>
*/
exports.__esModule = true;
var tslib_1 = require("tslib");
var React = require("react");
var ReactDom = require("react-dom");
var tooltipFactory_1 = require("./tooltipFactory");
var mergeFuncs = require("beyond-lib/lib/utilities/mergeFuncs");
var Trigger = /** @class */ (function (_super) {
tslib_1.__extends(Trigger, _super);
function Trigger() {
return _super !== null && _super.apply(this, arguments) || this;
}
Trigger.prototype.componentDidMount = function () {
var tooltip = this.props.tooltip;
this.tooltip = tooltipFactory_1.getNewInstance(tooltip.props, tooltip.props.children);
this.target = ReactDom.findDOMNode(this);
};
Trigger.prototype.render = function () {
var children = this.props.children;
var props = {
onMouseEnter: mergeFuncs(children.props.onMouseEnter, this.show.bind(this)),
onMouseLeave: mergeFuncs(children.props.onMouseLeave, this.hide.bind(this))
};
return React.cloneElement(children, props);
};
Trigger.prototype.show = function () {
if (this.tooltip && this.target) {
this.tooltip.show(this.target);
}
};
Trigger.prototype.hide = function () {
if (this.tooltip && this.target) {
this.tooltip.hide();
}
};
return Trigger;
}(React.Component));
exports["default"] = Trigger;