intelicoreact 1.5.17 → 1.5.18

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.
@@ -15,8 +15,6 @@ var _utils2 = require("./partials/_utils");
15
15
  require("./Hint.scss");
16
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
- // ToDo - не понятно зачем (ф-я не используется), но не трогаю
19
- const time = (Date.now() * Math.random() / 1000).toString().replace(/\./g, "_");
20
18
  const Hint = _ref => {
21
19
  var _ref2, _label$replace;
22
20
  let {
@@ -32,25 +30,25 @@ const Hint = _ref => {
32
30
  id,
33
31
  children,
34
32
  icon,
33
+ activeHint,
34
+ setActiveHint,
35
35
  isAccessability = false,
36
36
  testId = "test-hint",
37
37
  isHoverableContent = false
38
38
  } = _ref;
39
39
  const hintRef = (0, _react.useRef)(null);
40
40
  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, setIsOpen] = (0, _react.useState)(false);
42
-
43
- //? Определяем handleScroll-стейт, чтобы никогда не менять ссылку тем самым гарантировать корректную работу removeEventListener.
44
- //? Инициализируем стейт вызовом конструктора HandleScrollObj, передаем setIsOpen для записи в объект.
45
- const [handleScroll] = (0, _react.useState)(new _utils2.HandleScrollObj(setIsOpen));
46
- //? По аналогии определяем handleClickOutside
47
- const [handleClickOutside] = (0, _react.useState)(new _utils2.HandleClickOutsideObj(hintId, setIsOpen));
41
+ const isOpen = activeHint === id;
42
+ const [handleScroll] = (0, _react.useState)(new _utils2.HandleScrollObj(setActiveHint));
43
+ const [handleClickOutside] = (0, _react.useState)(new _utils2.HandleClickOutsideObj(hintId, setActiveHint));
44
+ const [hoverTimeout, setHoverTimeout] = (0, _react.useState)(null);
45
+ const [closeTimeout, setCloseTimeout] = (0, _react.useState)(null);
48
46
  const isCallbackExist = typeof onClickCallback === "function";
49
47
  const getHintMarkUp = className => {
50
48
  return /*#__PURE__*/_react.default.createElement("div", {
51
49
  "data-testid": "test-hint-text",
52
50
  className: (0, _classnames.default)("hint__text", "hint__text_".concat(side), "hint--".concat(className, "__text")),
53
- onMouseLeave: () => isHoverableContent && handleOpenType === "hover" && setIsOpen(false)
51
+ onMouseLeave: () => isHoverableContent && handleOpenType === "hover" && startCloseTimeout()
54
52
  }, hint, children);
55
53
  };
56
54
  const setHintContainerStyles = () => {
@@ -117,13 +115,47 @@ const Hint = _ref => {
117
115
  if (!hc) return null;
118
116
  return /*#__PURE__*/(0, _reactDom.createPortal)(getHintMarkUp(className), hc);
119
117
  };
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
+ const handle = {
131
+ onMouseEnterHintIcon: () => {
132
+ stopCloseTimeout();
133
+ if (handleOpenType === "hover") {
134
+ const timeout = setTimeout(() => {
135
+ setActiveHint(id);
136
+ !isOpen && onClickCallback();
137
+ }, 350);
138
+ setHoverTimeout(timeout);
139
+ }
140
+ },
141
+ onMouseLeaveHintIcon: () => {
142
+ if (!isHoverableContent && handleOpenType === "hover") {
143
+ clearTimeout(hoverTimeout);
144
+ setHoverTimeout(null);
145
+ startCloseTimeout();
146
+ }
147
+ },
148
+ onClickHintIcon: () => {
149
+ if (handleOpenType === "click") {
150
+ isCallbackExist ? onClickCallback() : setActiveHint(id);
151
+ }
152
+ }
153
+ };
120
154
  (0, _react.useEffect)(() => {
121
155
  (0, _utils2.initHintContainer)(hintId, hintContainer);
122
156
  }, []);
123
157
  (0, _react.useEffect)(() => {
124
158
  setHintContainerStyles();
125
-
126
- //! Обеспечиваем работу колбэка ТОЛЬКО для открытых тултипов
127
159
  if (isOpen) {
128
160
  document.addEventListener("scroll", handleScroll, true);
129
161
  document.addEventListener("click", handleClickOutside, true);
@@ -132,6 +164,9 @@ const Hint = _ref => {
132
164
  document.removeEventListener("click", handleClickOutside, true);
133
165
  }
134
166
  }, [isOpen]);
167
+ (0, _react.useEffect)(() => {
168
+ stopCloseTimeout(null);
169
+ }, [activeHint]);
135
170
  return /*#__PURE__*/_react.default.createElement("div", {
136
171
  className: (0, _classnames.default)("hint", className),
137
172
  ref: hintRef
@@ -139,9 +174,9 @@ const Hint = _ref => {
139
174
  tabIndex: isAccessability ? 0 : -1,
140
175
  "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,
141
176
  "aria-label": isAccessability && label || "",
142
- onClick: () => handleOpenType === "click" && (isCallbackExist ? onClickCallback() : setIsOpen(!isOpen)),
143
- onMouseEnter: () => handleOpenType === "hover" && setIsOpen(true),
144
- onMouseLeave: () => !isHoverableContent && handleOpenType === "hover" && setIsOpen(false),
177
+ onClick: handle.onClickHintIcon,
178
+ onMouseEnter: handle.onMouseEnterHintIcon,
179
+ onMouseLeave: handle.onMouseLeaveHintIcon,
145
180
  className: (0, _classnames.default)("hint__button", {
146
181
  hint__button_active: isOpen
147
182
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.5.17",
3
+ "version": "1.5.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [