@rescui/tooltip 0.8.13 → 0.8.15-RUI-226-Update-card-cn-6e43cc89.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/css-vars-utils.js +8 -9
- package/lib/index.css +31 -47
- package/lib/index.js +1 -1
- package/lib/index.p.module.css.js +7 -7
- package/lib/tooltip.d.ts +6 -0
- package/lib/tooltip.js +119 -139
- package/lib/use-tooltip-state.js +9 -15
- package/package.json +8 -8
package/lib/css-vars-utils.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
var PRIMARY_COLORS = ['--rs-color-primary-light-theme', '--rs-color-primary-dim-light-theme', '--rs-color-primary-fog-light-theme', '--rs-color-primary-t-dim-light-theme', '--rs-color-primary-t-fog-light-theme', '--rs-color-primary-dark-theme', '--rs-color-primary-dim-dark-theme', '--rs-color-primary-fog-dark-theme', '--rs-color-primary-t-dim-dark-theme', '--rs-color-primary-t-fog-dark-theme'];
|
|
1
|
+
const PRIMARY_COLORS = ['--rs-color-primary-light-theme', '--rs-color-primary-dim-light-theme', '--rs-color-primary-fog-light-theme', '--rs-color-primary-t-dim-light-theme', '--rs-color-primary-t-fog-light-theme', '--rs-color-primary-dark-theme', '--rs-color-primary-dim-dark-theme', '--rs-color-primary-fog-dark-theme', '--rs-color-primary-t-dim-dark-theme', '--rs-color-primary-t-fog-dark-theme'];
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
PRIMARY_COLORS.forEach(
|
|
3
|
+
const extractPrimaryColors = styles => {
|
|
4
|
+
const colors = {};
|
|
5
|
+
PRIMARY_COLORS.forEach(varName => {
|
|
7
6
|
colors[varName] = styles.getPropertyValue(varName) || 'initial';
|
|
8
7
|
});
|
|
9
8
|
return colors;
|
|
@@ -11,10 +10,10 @@ var extractPrimaryColors = function extractPrimaryColors(styles) {
|
|
|
11
10
|
/** Check out `@rescui/colors/src/public-api.p.css` file */
|
|
12
11
|
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const extractThemeFromCss = styles => {
|
|
14
|
+
const themeDark = parseInt(styles.getPropertyValue('--rs-theme-dark'), 10) || 0;
|
|
15
|
+
const themeFlip = parseInt(styles.getPropertyValue('--rs-theme-flip'), 10) || 0;
|
|
16
|
+
const themeDarkCoefficient = themeDark * (1 - themeFlip) + themeFlip * (1 - themeDark);
|
|
18
17
|
return themeDarkCoefficient === 1 ? 'dark' : 'light';
|
|
19
18
|
};
|
|
20
19
|
|
package/lib/index.css
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
.
|
|
1
|
+
._tooltip_1kpucek_5{
|
|
2
2
|
position:relative;
|
|
3
3
|
}
|
|
4
|
-
.
|
|
4
|
+
._closing_1kpucek_9{
|
|
5
5
|
pointer-events:none;
|
|
6
6
|
}
|
|
7
|
-
.
|
|
7
|
+
._content_1kpucek_13{
|
|
8
8
|
--rs-theme-dark:1;
|
|
9
9
|
--_rs-tooltip-border-width:1px;
|
|
10
10
|
|
|
@@ -28,9 +28,8 @@
|
|
|
28
28
|
font-weight:var(--_rs-typography-font-weight);
|
|
29
29
|
line-height:var(--_rs-typography-line-height);
|
|
30
30
|
font-variant-numeric:var(--_rs-typography-font-variant-numeric);
|
|
31
|
-
-webkit-font-feature-settings:'kern', 'liga', 'calt';
|
|
32
31
|
font-feature-settings:'kern', 'liga', 'calt';
|
|
33
|
-
--_rs-typography-letter-spacing:0.0045em;
|
|
32
|
+
--_rs-typography-letter-spacing:var(--rs-text-3-letter-spacing, 0.0045em);
|
|
34
33
|
--_rs-typography-text-transform:initial;
|
|
35
34
|
--_rs-typography-font-variant-numeric:initial;
|
|
36
35
|
--_rs-typography-font-family:var(
|
|
@@ -73,45 +72,36 @@
|
|
|
73
72
|
color:#FFFFFF;
|
|
74
73
|
background-color:#303033;
|
|
75
74
|
|
|
76
|
-
-webkit-transition:opacity 300ms, -webkit-transform 300ms;
|
|
77
|
-
|
|
78
|
-
transition:opacity 300ms, -webkit-transform 300ms;
|
|
79
|
-
|
|
80
75
|
transition:opacity 300ms, transform 300ms;
|
|
81
|
-
|
|
82
|
-
transition:opacity 300ms, transform 300ms, -webkit-transform 300ms;
|
|
83
|
-
-webkit-transform:translate(0, 0);
|
|
84
|
-
transform:translate(0, 0);
|
|
76
|
+
transform:translate(0, 0);
|
|
85
77
|
}
|
|
86
|
-
[data-real-placement='top-end'] .
|
|
87
|
-
[data-real-placement='bottom-end'] .
|
|
78
|
+
[data-real-placement='top-end'] ._content_1kpucek_13,
|
|
79
|
+
[data-real-placement='bottom-end'] ._content_1kpucek_13{
|
|
88
80
|
margin-right:0;
|
|
89
81
|
}
|
|
90
|
-
[data-real-placement='top-start'] .
|
|
91
|
-
[data-real-placement='bottom-start'] .
|
|
82
|
+
[data-real-placement='top-start'] ._content_1kpucek_13,
|
|
83
|
+
[data-real-placement='bottom-start'] ._content_1kpucek_13{
|
|
92
84
|
margin-left:0;
|
|
93
85
|
}
|
|
94
|
-
[data-real-placement='left-end'] .
|
|
95
|
-
[data-real-placement='right-end'] .
|
|
86
|
+
[data-real-placement='left-end'] ._content_1kpucek_13,
|
|
87
|
+
[data-real-placement='right-end'] ._content_1kpucek_13{
|
|
96
88
|
margin-bottom:0;
|
|
97
89
|
}
|
|
98
|
-
[data-real-placement='left-start'] .
|
|
99
|
-
[data-real-placement='right-start'] .
|
|
90
|
+
[data-real-placement='left-start'] ._content_1kpucek_13,
|
|
91
|
+
[data-real-placement='right-start'] ._content_1kpucek_13{
|
|
100
92
|
margin-top:0;
|
|
101
93
|
}
|
|
102
|
-
.
|
|
103
|
-
-webkit-transition:none;
|
|
94
|
+
._initial_1kpucek_54 ._content_1kpucek_13{
|
|
104
95
|
transition:none;
|
|
105
96
|
}
|
|
106
|
-
.
|
|
107
|
-
|
|
108
|
-
transition-duration:200ms, 200ms;
|
|
97
|
+
._closing_1kpucek_9 ._content_1kpucek_13{
|
|
98
|
+
transition-duration:200ms, 200ms;
|
|
109
99
|
}
|
|
110
|
-
.
|
|
111
|
-
.
|
|
100
|
+
._initial_1kpucek_54 ._content_1kpucek_13,
|
|
101
|
+
._closing_1kpucek_9 ._content_1kpucek_13{
|
|
112
102
|
opacity:0;
|
|
113
103
|
}
|
|
114
|
-
.
|
|
104
|
+
._outerThemeLight_1kpucek_68 ._content_1kpucek_13{
|
|
115
105
|
--rs-color-primary-dark-theme:var(--rs-color-primary-light-theme);
|
|
116
106
|
--rs-color-primary-dim-dark-theme:var(--rs-color-primary-dim-light-theme);
|
|
117
107
|
--rs-color-primary-fog-dark-theme:var(--rs-color-primary-fog-light-theme);
|
|
@@ -122,7 +112,7 @@
|
|
|
122
112
|
--rs-color-primary-t-fog-light-theme
|
|
123
113
|
);
|
|
124
114
|
}
|
|
125
|
-
.
|
|
115
|
+
._outerThemeDark_1kpucek_81 ._content_1kpucek_13{
|
|
126
116
|
--rs-color-primary-light-theme:var(--rs-color-primary-dark-theme);
|
|
127
117
|
--rs-color-primary-dim-light-theme:var(--rs-color-primary-dim-dark-theme);
|
|
128
118
|
--rs-color-primary-fog-light-theme:var(--rs-color-primary-fog-dark-theme);
|
|
@@ -133,27 +123,21 @@
|
|
|
133
123
|
--rs-color-primary-t-fog-dark-theme
|
|
134
124
|
);
|
|
135
125
|
}
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
transform:translate(0, 10px);
|
|
126
|
+
._initial_1kpucek_54[data-real-placement^='top'] ._content_1kpucek_13, ._closing_1kpucek_9[data-real-placement^='top'] ._content_1kpucek_13{
|
|
127
|
+
transform:translate(0, 10px);
|
|
139
128
|
}
|
|
140
|
-
.
|
|
141
|
-
|
|
142
|
-
transform:translate(-10px, 0);
|
|
129
|
+
._initial_1kpucek_54[data-real-placement^='right'] ._content_1kpucek_13, ._closing_1kpucek_9[data-real-placement^='right'] ._content_1kpucek_13{
|
|
130
|
+
transform:translate(-10px, 0);
|
|
143
131
|
}
|
|
144
|
-
.
|
|
145
|
-
|
|
146
|
-
transform:translate(0, -10px);
|
|
132
|
+
._initial_1kpucek_54[data-real-placement^='bottom'] ._content_1kpucek_13, ._closing_1kpucek_9[data-real-placement^='bottom'] ._content_1kpucek_13{
|
|
133
|
+
transform:translate(0, -10px);
|
|
147
134
|
}
|
|
148
|
-
.
|
|
149
|
-
|
|
150
|
-
transform:translate(10px, 0);
|
|
135
|
+
._initial_1kpucek_54[data-real-placement^='left'] ._content_1kpucek_13, ._closing_1kpucek_9[data-real-placement^='left'] ._content_1kpucek_13{
|
|
136
|
+
transform:translate(10px, 0);
|
|
151
137
|
}
|
|
152
|
-
.
|
|
153
|
-
.
|
|
138
|
+
._trigger_1kpucek_113:focus-visible,
|
|
139
|
+
._trigger_1kpucek_113:focus[data-focus-method='key']{
|
|
154
140
|
outline:none;
|
|
155
141
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
box-shadow:var(--rs-color-primary-t-dim-light-theme) 0 0 0 4px;
|
|
142
|
+
box-shadow:var(--rs-color-primary-t-dim-light-theme) 0 0 0 4px;
|
|
159
143
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"tooltip": "
|
|
3
|
-
"closing": "
|
|
4
|
-
"content": "
|
|
5
|
-
"initial": "
|
|
6
|
-
"outerThemeLight": "
|
|
7
|
-
"outerThemeDark": "
|
|
8
|
-
"trigger": "
|
|
2
|
+
"tooltip": "_tooltip_1kpucek_5",
|
|
3
|
+
"closing": "_closing_1kpucek_9",
|
|
4
|
+
"content": "_content_1kpucek_13",
|
|
5
|
+
"initial": "_initial_1kpucek_54",
|
|
6
|
+
"outerThemeLight": "_outerThemeLight_1kpucek_68",
|
|
7
|
+
"outerThemeDark": "_outerThemeDark_1kpucek_81",
|
|
8
|
+
"trigger": "_trigger_1kpucek_113"
|
|
9
9
|
};
|
|
10
10
|
export { styles as default };
|
package/lib/tooltip.d.ts
CHANGED
|
@@ -57,6 +57,12 @@ export interface TooltipProps {
|
|
|
57
57
|
disableHideDelay?: boolean;
|
|
58
58
|
/** increase offset from the target */
|
|
59
59
|
sparse?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* If set to true, the tooltip will be rendered adjacent to its triggering element.
|
|
62
|
+
* If false or undefined, the tooltip will render at the end of the `document.body` element.
|
|
63
|
+
* Should be used when the tooltip content contains interactive elements (e.g. links).
|
|
64
|
+
*/
|
|
65
|
+
renderBesideTrigger?: boolean;
|
|
60
66
|
}
|
|
61
67
|
export declare const Tooltip: React.FC<TooltipProps>;
|
|
62
68
|
export default Tooltip;
|
package/lib/tooltip.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
6
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
|
|
7
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
8
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
9
|
-
import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
|
10
|
-
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
|
|
15
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
16
1
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
17
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
18
|
-
import "core-js/modules/es.object.to-string.js";
|
|
19
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
20
2
|
import React, { cloneElement, createElement, useState, useRef, useEffect, useCallback, useContext, isValidElement } from 'react';
|
|
21
3
|
import { Element, ForwardRef, typeOf } from 'react-is';
|
|
22
4
|
import cn from 'classnames';
|
|
@@ -27,19 +9,20 @@ import { ThemeContext, LayeringConsumer, ThemeProvider } from '@rescui/ui-contex
|
|
|
27
9
|
import styles from './index.p.module.css.js';
|
|
28
10
|
import { useTooltipState, TOOLTIP_STATES } from './use-tooltip-state.js';
|
|
29
11
|
import { extractThemeFromCss, extractPrimaryColors } from './css-vars-utils.js';
|
|
30
|
-
|
|
12
|
+
const HIDE_TIMEOUT = 500; // it should in sync with the transition-duration css-property
|
|
31
13
|
|
|
32
|
-
|
|
14
|
+
const CLOSING_TIMEOUT = 300;
|
|
33
15
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
16
|
+
const Portal = _ref => {
|
|
17
|
+
let {
|
|
18
|
+
children,
|
|
19
|
+
target = document.body
|
|
20
|
+
} = _ref;
|
|
38
21
|
return /*#__PURE__*/ReactDOM.createPortal(children, target);
|
|
39
22
|
};
|
|
40
23
|
|
|
41
|
-
|
|
42
|
-
switch (
|
|
24
|
+
const isNode = maybeNode => {
|
|
25
|
+
switch (typeof maybeNode) {
|
|
43
26
|
case 'string':
|
|
44
27
|
case 'number':
|
|
45
28
|
return true;
|
|
@@ -60,30 +43,31 @@ var isNode = function isNode(maybeNode) {
|
|
|
60
43
|
}
|
|
61
44
|
};
|
|
62
45
|
|
|
63
|
-
|
|
46
|
+
const OUTER_THEME_STYLES = {
|
|
64
47
|
light: styles.outerThemeLight,
|
|
65
48
|
dark: styles.outerThemeDark
|
|
66
49
|
};
|
|
67
|
-
|
|
68
|
-
var _children$
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
50
|
+
const TriggerRenderer = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
51
|
+
var _children$props, _context;
|
|
52
|
+
|
|
53
|
+
let {
|
|
54
|
+
setTriggerRef,
|
|
55
|
+
targetComponent,
|
|
56
|
+
isControlled,
|
|
57
|
+
handleMouseEnterTarget,
|
|
58
|
+
handleMouseLeaveTarget,
|
|
59
|
+
children
|
|
60
|
+
} = _ref2;
|
|
61
|
+
const eventListeners = !isControlled ? {
|
|
77
62
|
onMouseEnter: handleMouseEnterTarget,
|
|
78
63
|
onMouseLeave: handleMouseLeaveTarget,
|
|
79
64
|
onFocus: handleMouseEnterTarget,
|
|
80
65
|
onBlur: handleMouseLeaveTarget,
|
|
81
66
|
tabIndex: 0
|
|
82
67
|
} : {};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
ref: function ref(el) {
|
|
68
|
+
const childrenRef = (children === null || children === void 0 ? void 0 : children.ref) ?? (children === null || children === void 0 || (_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props.ref);
|
|
69
|
+
const tooltipTargetProps = Object.assign({}, {
|
|
70
|
+
ref: el => {
|
|
87
71
|
setTriggerRef(el);
|
|
88
72
|
|
|
89
73
|
if (childrenRef) {
|
|
@@ -94,11 +78,11 @@ var TriggerRenderer = /*#__PURE__*/React.forwardRef(function (_ref2, _ref3) {
|
|
|
94
78
|
}
|
|
95
79
|
}
|
|
96
80
|
|
|
97
|
-
if (
|
|
98
|
-
if (typeof
|
|
99
|
-
|
|
81
|
+
if (ref) {
|
|
82
|
+
if (typeof ref === 'function') {
|
|
83
|
+
ref(el);
|
|
100
84
|
} else {
|
|
101
|
-
|
|
85
|
+
ref.current = el;
|
|
102
86
|
}
|
|
103
87
|
}
|
|
104
88
|
}
|
|
@@ -109,62 +93,51 @@ var TriggerRenderer = /*#__PURE__*/React.forwardRef(function (_ref2, _ref3) {
|
|
|
109
93
|
targetProps: tooltipTargetProps
|
|
110
94
|
});
|
|
111
95
|
} else if (_includesInstanceProperty(_context = [Element, ForwardRef]).call(_context, typeOf(children))) {
|
|
112
|
-
return /*#__PURE__*/cloneElement(children,
|
|
113
|
-
className: cn(styles.trigger, children.props.className)
|
|
114
|
-
|
|
96
|
+
return /*#__PURE__*/cloneElement(children, {
|
|
97
|
+
className: cn(styles.trigger, children.props.className),
|
|
98
|
+
...tooltipTargetProps
|
|
99
|
+
});
|
|
115
100
|
} // create trigger-wrapper to bind tooltip
|
|
116
101
|
|
|
117
102
|
|
|
118
|
-
return /*#__PURE__*/createElement(targetComponent,
|
|
119
|
-
className: styles.trigger
|
|
120
|
-
|
|
103
|
+
return /*#__PURE__*/createElement(targetComponent, {
|
|
104
|
+
className: styles.trigger,
|
|
105
|
+
...tooltipTargetProps
|
|
106
|
+
}, children);
|
|
121
107
|
});
|
|
122
|
-
TriggerRenderer.displayName = 'TriggerRenderer';
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
isVisibleState = _useState4[0],
|
|
150
|
-
setIsVisibleState = _useState4[1];
|
|
151
|
-
|
|
152
|
-
var _useState5 = useState(false),
|
|
153
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
154
|
-
isTooltipHovered = _useState6[0],
|
|
155
|
-
setIsTooltipHovered = _useState6[1];
|
|
156
|
-
|
|
157
|
-
var schedulePopperUpdateRef = useRef(null);
|
|
158
|
-
var hideTimeoutRef = useRef(null);
|
|
159
|
-
var isVisible = isControlled ? isVisibleFromProps : isVisibleState;
|
|
160
|
-
var isOpen = isVisible || isTooltipHovered;
|
|
161
|
-
useEffect(function () {
|
|
108
|
+
TriggerRenderer.displayName = 'TriggerRenderer'; // eslint-disable-next-line complexity
|
|
109
|
+
|
|
110
|
+
const Tooltip = _ref3 => {
|
|
111
|
+
let {
|
|
112
|
+
children,
|
|
113
|
+
targetComponent = 'span',
|
|
114
|
+
content,
|
|
115
|
+
className,
|
|
116
|
+
isVisible: isVisibleFromProps,
|
|
117
|
+
modifiers,
|
|
118
|
+
placement = 'auto',
|
|
119
|
+
sparse = true,
|
|
120
|
+
fallbackPlacements = ['top', 'bottom'],
|
|
121
|
+
disableHideDelay,
|
|
122
|
+
renderBesideTrigger = false
|
|
123
|
+
} = _ref3;
|
|
124
|
+
const [triggerRef, setTriggerRef] = useState(null);
|
|
125
|
+
const isControlled = typeof isVisibleFromProps !== 'undefined';
|
|
126
|
+
const [isVisibleState, setIsVisibleState] = useState(false);
|
|
127
|
+
const [isTooltipHovered, setIsTooltipHovered] = useState(false);
|
|
128
|
+
const schedulePopperUpdateRef = useRef(null);
|
|
129
|
+
const contentRef = useRef(null);
|
|
130
|
+
const hideTimeoutRef = useRef(null);
|
|
131
|
+
const isVisible = isControlled ? isVisibleFromProps : isVisibleState;
|
|
132
|
+
const isOpen = isVisible || isTooltipHovered;
|
|
133
|
+
const PortalResolved = renderBesideTrigger ? React.Fragment : Portal;
|
|
134
|
+
useEffect(() => {
|
|
162
135
|
if (schedulePopperUpdateRef.current) {
|
|
163
136
|
schedulePopperUpdateRef.current();
|
|
164
137
|
}
|
|
165
138
|
}, [content]);
|
|
166
139
|
|
|
167
|
-
|
|
140
|
+
const handleMouseEnterTarget = () => {
|
|
168
141
|
if (hideTimeoutRef.current) {
|
|
169
142
|
clearTimeout(hideTimeoutRef.current);
|
|
170
143
|
hideTimeoutRef.current = null;
|
|
@@ -173,65 +146,65 @@ var Tooltip = function Tooltip(_ref4) {
|
|
|
173
146
|
setIsVisibleState(true);
|
|
174
147
|
};
|
|
175
148
|
|
|
176
|
-
|
|
149
|
+
const handleMouseLeaveTarget = () => {
|
|
177
150
|
if (disableHideDelay) {
|
|
178
151
|
setIsVisibleState(false);
|
|
179
152
|
} else {
|
|
180
|
-
hideTimeoutRef.current = setTimeout(
|
|
153
|
+
hideTimeoutRef.current = setTimeout(() => {
|
|
181
154
|
setIsVisibleState(false);
|
|
182
155
|
}, HIDE_TIMEOUT);
|
|
183
156
|
}
|
|
184
157
|
};
|
|
185
158
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
159
|
+
const tooltipState = useTooltipState(isOpen, CLOSING_TIMEOUT);
|
|
160
|
+
const isClosing = tooltipState === TOOLTIP_STATES.CLOSING;
|
|
161
|
+
const isExists = tooltipState !== TOOLTIP_STATES.CLOSED; // a state to toggle the starting transition
|
|
189
162
|
|
|
190
|
-
|
|
191
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
192
|
-
isInitial = _useState8[0],
|
|
193
|
-
setIsInitial = _useState8[1]; // reset the initial flag when the closing transition ends and the state switches to CLOSED
|
|
163
|
+
const [isInitial, setIsInitial] = useState(true); // reset the initial flag when the closing transition ends and the state switches to CLOSED
|
|
194
164
|
|
|
195
|
-
|
|
196
|
-
useEffect(function () {
|
|
165
|
+
useEffect(() => {
|
|
197
166
|
if (!isExists) {
|
|
198
167
|
setIsInitial(true);
|
|
199
168
|
}
|
|
200
169
|
}, [isExists]);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
170
|
+
const disableInitialFlag = useCallback(_ref4 => {
|
|
171
|
+
let {
|
|
172
|
+
state
|
|
173
|
+
} = _ref4;
|
|
174
|
+
const el = state.elements.popper; // force layout phase
|
|
204
175
|
// to make sure that the dom has registered the initial
|
|
205
176
|
// styles with resolved placement (for `auto` placement)
|
|
206
177
|
|
|
207
178
|
el.getBoundingClientRect();
|
|
208
179
|
setIsInitial(false);
|
|
209
180
|
}, []);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
181
|
+
const tooltipShouldBeRendered = isExists && isNode(content);
|
|
182
|
+
let primaryColors = {};
|
|
183
|
+
let themeFromCss = 'light';
|
|
213
184
|
|
|
214
185
|
if (triggerRef && tooltipShouldBeRendered) {
|
|
215
186
|
// In theory this part of the code might cause issues with SSR.
|
|
216
187
|
// But in this specific context, because of the nature of the state-ref "triggerRef",
|
|
217
188
|
// we are sure that the tooltip wouldn't be rendered on the first client render.
|
|
218
189
|
// Therefore, the first render on the client will be the same as on the server.
|
|
219
|
-
|
|
190
|
+
const triggerStyles = getComputedStyle(triggerRef);
|
|
220
191
|
themeFromCss = extractThemeFromCss(triggerStyles);
|
|
221
192
|
primaryColors = extractPrimaryColors(triggerStyles);
|
|
222
193
|
}
|
|
223
194
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return /*#__PURE__*/React.createElement(LayeringConsumer, null,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return /*#__PURE__*/React.createElement(Manager, null, /*#__PURE__*/React.createElement(Reference, null,
|
|
234
|
-
|
|
195
|
+
const {
|
|
196
|
+
theme: themeFromContext,
|
|
197
|
+
noProvider
|
|
198
|
+
} = useContext(ThemeContext);
|
|
199
|
+
const theme = noProvider ? themeFromCss : themeFromContext;
|
|
200
|
+
return /*#__PURE__*/React.createElement(LayeringConsumer, null, _ref5 => {
|
|
201
|
+
let {
|
|
202
|
+
tooltipZIndex
|
|
203
|
+
} = _ref5;
|
|
204
|
+
return /*#__PURE__*/React.createElement(Manager, null, /*#__PURE__*/React.createElement(Reference, null, _ref6 => {
|
|
205
|
+
let {
|
|
206
|
+
ref
|
|
207
|
+
} = _ref6;
|
|
235
208
|
return /*#__PURE__*/React.createElement(TriggerRenderer, {
|
|
236
209
|
ref: ref,
|
|
237
210
|
setTriggerRef: setTriggerRef,
|
|
@@ -240,9 +213,9 @@ var Tooltip = function Tooltip(_ref4) {
|
|
|
240
213
|
handleMouseEnterTarget: handleMouseEnterTarget,
|
|
241
214
|
handleMouseLeaveTarget: handleMouseLeaveTarget
|
|
242
215
|
}, children);
|
|
243
|
-
}), tooltipShouldBeRendered && /*#__PURE__*/React.createElement(
|
|
216
|
+
}), tooltipShouldBeRendered && /*#__PURE__*/React.createElement(PortalResolved, null, /*#__PURE__*/React.createElement(Popper, {
|
|
244
217
|
placement: placement,
|
|
245
|
-
modifiers:
|
|
218
|
+
modifiers: [// the modifier to trigger starting animation
|
|
246
219
|
{
|
|
247
220
|
name: 'disableInitialFlag',
|
|
248
221
|
enabled: true,
|
|
@@ -252,13 +225,15 @@ var Tooltip = function Tooltip(_ref4) {
|
|
|
252
225
|
}, {
|
|
253
226
|
name: 'flip',
|
|
254
227
|
options: {
|
|
255
|
-
fallbackPlacements
|
|
228
|
+
fallbackPlacements
|
|
256
229
|
}
|
|
257
230
|
}, {
|
|
258
231
|
name: 'offset',
|
|
259
232
|
options: {
|
|
260
|
-
offset:
|
|
261
|
-
|
|
233
|
+
offset: _ref7 => {
|
|
234
|
+
let {
|
|
235
|
+
placement: offsetPlacement
|
|
236
|
+
} = _ref7;
|
|
262
237
|
|
|
263
238
|
if (_includesInstanceProperty(offsetPlacement).call(offsetPlacement, 'left') || _includesInstanceProperty(offsetPlacement).call(offsetPlacement, 'right')) {
|
|
264
239
|
return [0, sparse ? 16 : 8];
|
|
@@ -267,23 +242,24 @@ var Tooltip = function Tooltip(_ref4) {
|
|
|
267
242
|
}
|
|
268
243
|
}
|
|
269
244
|
}
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
245
|
+
}, ...(modifiers || [])]
|
|
246
|
+
}, _ref8 => {
|
|
247
|
+
let {
|
|
248
|
+
ref,
|
|
249
|
+
style,
|
|
250
|
+
update,
|
|
251
|
+
placement: realPlacement
|
|
252
|
+
} = _ref8;
|
|
276
253
|
schedulePopperUpdateRef.current = update;
|
|
277
254
|
return /*#__PURE__*/React.createElement("span", {
|
|
278
255
|
className: cn(styles.tooltip, isInitial && styles.initial, isClosing && styles.closing, OUTER_THEME_STYLES[theme], className),
|
|
279
256
|
ref: ref,
|
|
280
|
-
style:
|
|
257
|
+
style: { ...style,
|
|
258
|
+
...primaryColors,
|
|
281
259
|
zIndex: tooltipZIndex
|
|
282
|
-
}),
|
|
283
|
-
onMouseEnter: function onMouseEnter() {
|
|
284
|
-
return setIsTooltipHovered(true);
|
|
285
260
|
},
|
|
286
|
-
|
|
261
|
+
onMouseEnter: () => setIsTooltipHovered(true),
|
|
262
|
+
onMouseLeave: () => {
|
|
287
263
|
setIsVisibleState(false);
|
|
288
264
|
setIsTooltipHovered(false);
|
|
289
265
|
},
|
|
@@ -294,7 +270,10 @@ var Tooltip = function Tooltip(_ref4) {
|
|
|
294
270
|
theme: "dark",
|
|
295
271
|
ignoreThemeValueForCSSApi: noProvider
|
|
296
272
|
}, /*#__PURE__*/React.createElement("div", {
|
|
297
|
-
className: cn(styles.content)
|
|
273
|
+
className: cn(styles.content),
|
|
274
|
+
onBlur: handleMouseLeaveTarget,
|
|
275
|
+
onFocus: handleMouseEnterTarget,
|
|
276
|
+
ref: contentRef
|
|
298
277
|
}, content)));
|
|
299
278
|
})));
|
|
300
279
|
});
|
|
@@ -310,6 +289,7 @@ Tooltip.propTypes = {
|
|
|
310
289
|
placement: PropTypes.oneOf(['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start']),
|
|
311
290
|
fallbackPlacements: PropTypes.arrayOf(PropTypes.oneOf(['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start'])),
|
|
312
291
|
sparse: PropTypes.bool,
|
|
313
|
-
disableHideDelay: PropTypes.bool
|
|
292
|
+
disableHideDelay: PropTypes.bool,
|
|
293
|
+
renderBesideTrigger: PropTypes.bool
|
|
314
294
|
};
|
|
315
295
|
export { Tooltip, Tooltip as default };
|
package/lib/use-tooltip-state.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
2
1
|
import { useState, useEffect } from 'react';
|
|
3
2
|
var TOOLTIP_STATES;
|
|
4
3
|
|
|
@@ -9,17 +8,12 @@ var TOOLTIP_STATES;
|
|
|
9
8
|
})(TOOLTIP_STATES || (TOOLTIP_STATES = {}));
|
|
10
9
|
|
|
11
10
|
function useTooltipState(isOpen) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
16
|
-
state = _useState2[0],
|
|
17
|
-
setState = _useState2[1];
|
|
18
|
-
|
|
19
|
-
useEffect(function () {
|
|
11
|
+
let transitionDuration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
12
|
+
const [state, setState] = useState(TOOLTIP_STATES.CLOSED);
|
|
13
|
+
useEffect(() => {
|
|
20
14
|
if (isOpen) {
|
|
21
15
|
// set tooltip state to OPEN when it should be open, but the current state is closing or already closed
|
|
22
|
-
setState(
|
|
16
|
+
setState(curState => {
|
|
23
17
|
if (curState === TOOLTIP_STATES.CLOSING || curState === TOOLTIP_STATES.CLOSED) {
|
|
24
18
|
return TOOLTIP_STATES.OPEN;
|
|
25
19
|
} else {
|
|
@@ -30,7 +24,7 @@ function useTooltipState(isOpen) {
|
|
|
30
24
|
|
|
31
25
|
if (!isOpen) {
|
|
32
26
|
// if tooltip should not be open, but actually open, start the closing process
|
|
33
|
-
setState(
|
|
27
|
+
setState(curState => {
|
|
34
28
|
if (curState === TOOLTIP_STATES.OPEN) {
|
|
35
29
|
return TOOLTIP_STATES.CLOSING;
|
|
36
30
|
}
|
|
@@ -39,8 +33,8 @@ function useTooltipState(isOpen) {
|
|
|
39
33
|
}); // by the time the transition is finished, set state from closing to closed
|
|
40
34
|
// if by any means at that moment state is not closing (but open or already closed), do nothing
|
|
41
35
|
|
|
42
|
-
|
|
43
|
-
setState(
|
|
36
|
+
const timeoutId = setTimeout(() => {
|
|
37
|
+
setState(curState => {
|
|
44
38
|
if (curState === TOOLTIP_STATES.CLOSING) {
|
|
45
39
|
return TOOLTIP_STATES.CLOSED;
|
|
46
40
|
}
|
|
@@ -48,13 +42,13 @@ function useTooltipState(isOpen) {
|
|
|
48
42
|
return curState;
|
|
49
43
|
});
|
|
50
44
|
}, transitionDuration);
|
|
51
|
-
return
|
|
45
|
+
return () => {
|
|
52
46
|
clearTimeout(timeoutId);
|
|
53
47
|
};
|
|
54
48
|
} // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
55
49
|
|
|
56
50
|
|
|
57
|
-
return
|
|
51
|
+
return () => {};
|
|
58
52
|
}, [transitionDuration, isOpen]);
|
|
59
53
|
return state;
|
|
60
54
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/tooltip",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.15-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
|
+
"module": "lib/index.js",
|
|
8
9
|
"src:main": "src/index.ts",
|
|
9
10
|
"files": [
|
|
10
11
|
"lib",
|
|
@@ -14,10 +15,9 @@
|
|
|
14
15
|
"access": "public"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@babel/runtime-corejs3": "^7.
|
|
18
|
+
"@babel/runtime-corejs3": "^7.26.0",
|
|
18
19
|
"@popperjs/core": "^2.9.2",
|
|
19
20
|
"classnames": "^2.2.6",
|
|
20
|
-
"core-js": "^3.9.1",
|
|
21
21
|
"react-is": "^17.0.2",
|
|
22
22
|
"react-popper": "^2.2.5"
|
|
23
23
|
},
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"react-dom": ">=16.8.0 <19"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@rescui/colors": "
|
|
32
|
-
"@rescui/icons": "
|
|
33
|
-
"@rescui/scripts": "
|
|
34
|
-
"@rescui/typography": "
|
|
31
|
+
"@rescui/colors": "0.2.7-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89",
|
|
32
|
+
"@rescui/icons": "0.16.13-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89",
|
|
33
|
+
"@rescui/scripts": "0.4.0",
|
|
34
|
+
"@rescui/typography": "0.19.2-RUI-226-Update-card-cn-6e43cc89.60+6e43cc89",
|
|
35
35
|
"@types/react-is": "^17.0.3"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "rescui-scripts build"
|
|
39
39
|
},
|
|
40
40
|
"nx": {},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "6e43cc893fafb22b990273901bc0a070fb15761f"
|
|
42
42
|
}
|