createSliderWithTooltip.js
4.07 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
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import React from 'react';
import Tooltip from './common/SliderTooltip';
import Handle from './Handle';
export default function createSliderWithTooltip(Component) {
var _a; // eslint-disable-next-line @typescript-eslint/no-unused-vars
return _a = /*#__PURE__*/function (_React$Component) {
_inherits(ComponentWrapper, _React$Component);
var _super = _createSuper(ComponentWrapper);
function ComponentWrapper() {
var _this;
_classCallCheck(this, ComponentWrapper);
_this = _super.apply(this, arguments);
_this.state = {
visibles: {}
};
_this.handleTooltipVisibleChange = function (index, visible) {
_this.setState(function (prevState) {
return {
visibles: _objectSpread(_objectSpread({}, prevState.visibles), {}, _defineProperty({}, index, visible))
};
});
};
_this.handleWithTooltip = function (_ref) {
var value = _ref.value,
dragging = _ref.dragging,
index = _ref.index,
disabled = _ref.disabled,
restProps = _objectWithoutProperties(_ref, ["value", "dragging", "index", "disabled"]);
var _this$props = _this.props,
tipFormatter = _this$props.tipFormatter,
tipProps = _this$props.tipProps,
handleStyle = _this$props.handleStyle,
getTooltipContainer = _this$props.getTooltipContainer;
var _tipProps$prefixCls = tipProps.prefixCls,
prefixCls = _tipProps$prefixCls === void 0 ? 'rc-slider-tooltip' : _tipProps$prefixCls,
_tipProps$overlay = tipProps.overlay,
overlay = _tipProps$overlay === void 0 ? tipFormatter(value) : _tipProps$overlay,
_tipProps$placement = tipProps.placement,
placement = _tipProps$placement === void 0 ? 'top' : _tipProps$placement,
_tipProps$visible = tipProps.visible,
visible = _tipProps$visible === void 0 ? false : _tipProps$visible,
restTooltipProps = _objectWithoutProperties(tipProps, ["prefixCls", "overlay", "placement", "visible"]);
var handleStyleWithIndex;
if (Array.isArray(handleStyle)) {
handleStyleWithIndex = handleStyle[index] || handleStyle[0];
} else {
handleStyleWithIndex = handleStyle;
}
return React.createElement(Tooltip, Object.assign({}, restTooltipProps, {
getTooltipContainer: getTooltipContainer,
prefixCls: prefixCls,
overlay: overlay,
placement: placement,
visible: !disabled && (_this.state.visibles[index] || dragging) || visible,
key: index
}), React.createElement(Handle, Object.assign({}, restProps, {
style: _objectSpread({}, handleStyleWithIndex),
value: value,
onMouseEnter: function onMouseEnter() {
return _this.handleTooltipVisibleChange(index, true);
},
onMouseLeave: function onMouseLeave() {
return _this.handleTooltipVisibleChange(index, false);
}
})));
};
return _this;
}
_createClass(ComponentWrapper, [{
key: "render",
value: function render() {
return React.createElement(Component, Object.assign({}, this.props, {
handle: this.handleWithTooltip
}));
}
}]);
return ComponentWrapper;
}(React.Component), _a.defaultProps = {
tipFormatter: function tipFormatter(value) {
return value;
},
handleStyle: [{}],
tipProps: {},
getTooltipContainer: function getTooltipContainer(node) {
return node.parentNode;
}
}, _a;
}