@up-group-ui/react-controls
Version:
Up shared react controls
73 lines • 3.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpTooltip = void 0;
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var react_2 = require("react");
var classnames_1 = (0, tslib_1.__importDefault)(require("classnames"));
var react_tooltip_1 = (0, tslib_1.__importDefault)(require("react-tooltip"));
var utils_1 = require("../../../Common/utils");
var styles_1 = require("./styles");
var theming_1 = (0, tslib_1.__importStar)(require("../../../Common/theming"));
var UpTooltip = (function (_super) {
(0, tslib_1.__extends)(UpTooltip, _super);
function UpTooltip(props) {
var _this = _super.call(this, props) || this;
_this.getContent = function () {
return ((0, jsx_runtime_1.jsxs)("div", (0, tslib_1.__assign)({ className: "up-tooltip-content" }, { children: [_this.props.title != null && (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: "up-tooltip-header" }, { children: _this.props.title }), void 0), (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: "up-tooltip-body" }, { children: _this.props.content }), void 0)] }), void 0));
};
return _this;
}
UpTooltip.prototype.componentDidUpdate = function () {
react_tooltip_1.default.rebuild();
};
UpTooltip.prototype.render = function () {
var _a = this.props, id = _a.id, children = _a.children, content = _a.content, type = _a.type, others = (0, tslib_1.__rest)(_a, ["id", "children", "content", "type"]);
var tooltipId = id;
if (!tooltipId) {
tooltipId = (0, utils_1.generateId)();
}
var childrenWithProps = null;
var childrenAsFunction = null;
if (children != null && (0, utils_1.isFunction)(children)) {
childrenAsFunction = children;
}
else {
childrenWithProps = react_1.default.Children.map(children, function (child) {
if (react_1.default.isValidElement(child)) {
return react_1.default.cloneElement(child, {
dataFor: tooltipId,
});
}
else {
return child;
}
});
}
var renderChildren = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [childrenWithProps && childrenWithProps, childrenAsFunction &&
childrenAsFunction({
id: tooltipId,
})] }, void 0));
if ((0, utils_1.isEmpty)(content)) {
return renderChildren;
}
return ((0, jsx_runtime_1.jsxs)("div", (0, tslib_1.__assign)({ className: styles_1.upToolTipWrapper }, { children: [renderChildren, (0, jsx_runtime_1.jsx)(react_tooltip_1.default, (0, tslib_1.__assign)({ offset: this.props.place === 'bottom' ? { right: 85, top: 5 } : {}, className: (0, classnames_1.default)('up-tooltip', (0, styles_1.getStyles)(this.props)), id: tooltipId, getContent: this.getContent, eventOff: "click", globalEventOff: "click" }, others), void 0)] }), void 0));
};
UpTooltip.defaultProps = {
content: '',
place: 'right',
effect: 'float',
type: 'light',
multiline: false,
html: false,
delayHide: 500,
delayShow: 500,
disable: false,
theme: theming_1.default,
};
return UpTooltip;
}(react_2.Component));
exports.UpTooltip = UpTooltip;
exports.default = (0, theming_1.withTheme)(UpTooltip);
//# sourceMappingURL=UpTooltip.js.map