intelicoreact 1.5.18 → 1.5.19
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/dist/Atomic/UI/Hint/Hint.js +26 -40
- package/package.json +1 -1
|
@@ -30,25 +30,26 @@ const Hint = _ref => {
|
|
|
30
30
|
id,
|
|
31
31
|
children,
|
|
32
32
|
icon,
|
|
33
|
-
activeHint,
|
|
34
|
-
setActiveHint,
|
|
35
33
|
isAccessability = false,
|
|
36
34
|
testId = "test-hint",
|
|
37
35
|
isHoverableContent = false
|
|
38
36
|
} = _ref;
|
|
39
37
|
const hintRef = (0, _react.useRef)(null);
|
|
38
|
+
const timeoutRef = (0, _react.useRef)(null);
|
|
40
39
|
const [hintId] = (0, _react.useState)((_ref2 = key !== null && key !== void 0 ? key : id) !== null && _ref2 !== void 0 ? _ref2 : Math.random().toString(16).slice(2));
|
|
41
|
-
const isOpen =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const [
|
|
40
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
41
|
+
|
|
42
|
+
//? Определяем handleScroll-стейт, чтобы никогда не менять ссылку тем самым гарантировать корректную работу removeEventListener.
|
|
43
|
+
//? Инициализируем стейт вызовом конструктора HandleScrollObj, передаем setIsOpen для записи в объект.
|
|
44
|
+
const [handleScroll] = (0, _react.useState)(new _utils2.HandleScrollObj(setIsOpen));
|
|
45
|
+
//? По аналогии определяем handleClickOutside
|
|
46
|
+
const [handleClickOutside] = (0, _react.useState)(new _utils2.HandleClickOutsideObj(hintId, setIsOpen));
|
|
46
47
|
const isCallbackExist = typeof onClickCallback === "function";
|
|
47
48
|
const getHintMarkUp = className => {
|
|
48
49
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
49
50
|
"data-testid": "test-hint-text",
|
|
50
51
|
className: (0, _classnames.default)("hint__text", "hint__text_".concat(side), "hint--".concat(className, "__text")),
|
|
51
|
-
onMouseLeave: () => isHoverableContent && handleOpenType === "hover" &&
|
|
52
|
+
onMouseLeave: () => isHoverableContent && handleOpenType === "hover" && setIsOpen(false)
|
|
52
53
|
}, hint, children);
|
|
53
54
|
};
|
|
54
55
|
const setHintContainerStyles = () => {
|
|
@@ -115,44 +116,29 @@ const Hint = _ref => {
|
|
|
115
116
|
if (!hc) return null;
|
|
116
117
|
return /*#__PURE__*/(0, _reactDom.createPortal)(getHintMarkUp(className), hc);
|
|
117
118
|
};
|
|
118
|
-
const startCloseTimeout = () => {
|
|
119
|
-
const timeout = setTimeout(() => {
|
|
120
|
-
if (activeHint === id) setActiveHint(null);
|
|
121
|
-
}, 1000);
|
|
122
|
-
setCloseTimeout(timeout);
|
|
123
|
-
};
|
|
124
|
-
const stopCloseTimeout = () => {
|
|
125
|
-
if (closeTimeout) {
|
|
126
|
-
clearTimeout(closeTimeout);
|
|
127
|
-
setCloseTimeout(null);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
119
|
const handle = {
|
|
131
|
-
|
|
132
|
-
stopCloseTimeout();
|
|
120
|
+
onMouseEnter: () => {
|
|
133
121
|
if (handleOpenType === "hover") {
|
|
134
|
-
|
|
135
|
-
|
|
122
|
+
timeoutRef.current = setTimeout(() => {
|
|
123
|
+
setIsOpen(true);
|
|
136
124
|
!isOpen && onClickCallback();
|
|
137
125
|
}, 350);
|
|
138
|
-
setHoverTimeout(timeout);
|
|
139
126
|
}
|
|
140
127
|
},
|
|
141
|
-
|
|
128
|
+
onMouseLeave: () => {
|
|
142
129
|
if (!isHoverableContent && handleOpenType === "hover") {
|
|
143
|
-
clearTimeout(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
},
|
|
148
|
-
onClickHintIcon: () => {
|
|
149
|
-
if (handleOpenType === "click") {
|
|
150
|
-
isCallbackExist ? onClickCallback() : setActiveHint(id);
|
|
130
|
+
clearTimeout(timeoutRef.current);
|
|
131
|
+
timeoutRef.current = setTimeout(() => {
|
|
132
|
+
setIsOpen(false);
|
|
133
|
+
}, 1000);
|
|
151
134
|
}
|
|
152
135
|
}
|
|
153
136
|
};
|
|
154
137
|
(0, _react.useEffect)(() => {
|
|
155
138
|
(0, _utils2.initHintContainer)(hintId, hintContainer);
|
|
139
|
+
return () => {
|
|
140
|
+
clearTimeout(timeoutRef.current);
|
|
141
|
+
};
|
|
156
142
|
}, []);
|
|
157
143
|
(0, _react.useEffect)(() => {
|
|
158
144
|
setHintContainerStyles();
|
|
@@ -163,10 +149,10 @@ const Hint = _ref => {
|
|
|
163
149
|
document.removeEventListener("scroll", handleScroll, true);
|
|
164
150
|
document.removeEventListener("click", handleClickOutside, true);
|
|
165
151
|
}
|
|
152
|
+
return () => {
|
|
153
|
+
clearTimeout(timeoutRef.current);
|
|
154
|
+
};
|
|
166
155
|
}, [isOpen]);
|
|
167
|
-
(0, _react.useEffect)(() => {
|
|
168
|
-
stopCloseTimeout(null);
|
|
169
|
-
}, [activeHint]);
|
|
170
156
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
171
157
|
className: (0, _classnames.default)("hint", className),
|
|
172
158
|
ref: hintRef
|
|
@@ -174,9 +160,9 @@ const Hint = _ref => {
|
|
|
174
160
|
tabIndex: isAccessability ? 0 : -1,
|
|
175
161
|
"data-testid": typeof label === "string" && label.length ? (_label$replace = label.replace) === null || _label$replace === void 0 ? void 0 : _label$replace.call(label, /\s/g, "-") : testId,
|
|
176
162
|
"aria-label": isAccessability && label || "",
|
|
177
|
-
onClick:
|
|
178
|
-
onMouseEnter: handle.
|
|
179
|
-
onMouseLeave: handle.
|
|
163
|
+
onClick: () => handleOpenType === "click" && (isCallbackExist ? onClickCallback() : setIsOpen(!isOpen)),
|
|
164
|
+
onMouseEnter: handle.onMouseEnter,
|
|
165
|
+
onMouseLeave: handle.onMouseLeave,
|
|
180
166
|
className: (0, _classnames.default)("hint__button", {
|
|
181
167
|
hint__button_active: isOpen
|
|
182
168
|
})
|