Tooltip.js
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _rcTrigger = _interopRequireDefault(require("rc-trigger"));
var _placements = require("./placements");
var _Content = _interopRequireDefault(require("./Content"));
var Tooltip = function Tooltip(props, ref) {
var overlayClassName = props.overlayClassName,
_props$trigger = props.trigger,
trigger = _props$trigger === void 0 ? ['hover'] : _props$trigger,
_props$mouseEnterDela = props.mouseEnterDelay,
mouseEnterDelay = _props$mouseEnterDela === void 0 ? 0 : _props$mouseEnterDela,
_props$mouseLeaveDela = props.mouseLeaveDelay,
mouseLeaveDelay = _props$mouseLeaveDela === void 0 ? 0.1 : _props$mouseLeaveDela,
overlayStyle = props.overlayStyle,
_props$prefixCls = props.prefixCls,
prefixCls = _props$prefixCls === void 0 ? 'rc-tooltip' : _props$prefixCls,
children = props.children,
onVisibleChange = props.onVisibleChange,
afterVisibleChange = props.afterVisibleChange,
transitionName = props.transitionName,
animation = props.animation,
_props$placement = props.placement,
placement = _props$placement === void 0 ? 'right' : _props$placement,
_props$align = props.align,
align = _props$align === void 0 ? {} : _props$align,
_props$destroyTooltip = props.destroyTooltipOnHide,
destroyTooltipOnHide = _props$destroyTooltip === void 0 ? false : _props$destroyTooltip,
defaultVisible = props.defaultVisible,
getTooltipContainer = props.getTooltipContainer,
overlayInnerStyle = props.overlayInnerStyle,
restProps = (0, _objectWithoutProperties2.default)(props, ["overlayClassName", "trigger", "mouseEnterDelay", "mouseLeaveDelay", "overlayStyle", "prefixCls", "children", "onVisibleChange", "afterVisibleChange", "transitionName", "animation", "placement", "align", "destroyTooltipOnHide", "defaultVisible", "getTooltipContainer", "overlayInnerStyle"]);
var domRef = (0, React.useRef)(null);
(0, React.useImperativeHandle)(ref, function () {
return domRef.current;
});
var extraProps = (0, _objectSpread2.default)({}, restProps);
if ('visible' in props) {
extraProps.popupVisible = props.visible;
}
var getPopupElement = function getPopupElement() {
var _props$arrowContent = props.arrowContent,
arrowContent = _props$arrowContent === void 0 ? null : _props$arrowContent,
overlay = props.overlay,
id = props.id;
return [React.createElement("div", {
className: "".concat(prefixCls, "-arrow"),
key: "arrow"
}, arrowContent), React.createElement(_Content.default, {
key: "content",
prefixCls: prefixCls,
id: id,
overlay: overlay,
overlayInnerStyle: overlayInnerStyle
})];
};
var destroyTooltip = false;
var autoDestroy = false;
if (typeof destroyTooltipOnHide === 'boolean') {
destroyTooltip = destroyTooltipOnHide;
} else if (destroyTooltipOnHide && (0, _typeof2.default)(destroyTooltipOnHide) === 'object') {
var keepParent = destroyTooltipOnHide.keepParent;
destroyTooltip = keepParent === true;
autoDestroy = keepParent === false;
}
return React.createElement(_rcTrigger.default, Object.assign({
popupClassName: overlayClassName,
prefixCls: prefixCls,
popup: getPopupElement,
action: trigger,
builtinPlacements: _placements.placements,
popupPlacement: placement,
ref: domRef,
popupAlign: align,
getPopupContainer: getTooltipContainer,
onPopupVisibleChange: onVisibleChange,
afterPopupVisibleChange: afterVisibleChange,
popupTransitionName: transitionName,
popupAnimation: animation,
defaultPopupVisible: defaultVisible,
destroyPopupOnHide: destroyTooltip,
autoDestroy: autoDestroy,
mouseLeaveDelay: mouseLeaveDelay,
popupStyle: overlayStyle,
mouseEnterDelay: mouseEnterDelay
}, extraProps), children);
};
var _default = (0, React.forwardRef)(Tooltip);
exports.default = _default;