Tooltip.js
3.97 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
import _typeof from "@babel/runtime/helpers/esm/typeof";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import * as React from 'react';
import { useRef, useImperativeHandle, forwardRef } from 'react';
import Trigger from 'rc-trigger';
import { placements } from './placements';
import Content from './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 = _objectWithoutProperties(props, ["overlayClassName", "trigger", "mouseEnterDelay", "mouseLeaveDelay", "overlayStyle", "prefixCls", "children", "onVisibleChange", "afterVisibleChange", "transitionName", "animation", "placement", "align", "destroyTooltipOnHide", "defaultVisible", "getTooltipContainer", "overlayInnerStyle"]);
var domRef = useRef(null);
useImperativeHandle(ref, function () {
return domRef.current;
});
var extraProps = _objectSpread({}, 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, {
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 && _typeof(destroyTooltipOnHide) === 'object') {
var keepParent = destroyTooltipOnHide.keepParent;
destroyTooltip = keepParent === true;
autoDestroy = keepParent === false;
}
return React.createElement(Trigger, Object.assign({
popupClassName: overlayClassName,
prefixCls: prefixCls,
popup: getPopupElement,
action: trigger,
builtinPlacements: 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);
};
export default forwardRef(Tooltip);