intelicoreact 1.5.16 → 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,23 +30,25 @@ const Hint = _ref => {
32
30
  id,
33
31
  children,
34
32
  icon,
33
+ activeHint,
34
+ setActiveHint,
35
35
  isAccessability = false,
36
- testId = "test-hint"
36
+ testId = "test-hint",
37
+ isHoverableContent = false
37
38
  } = _ref;
38
39
  const hintRef = (0, _react.useRef)(null);
39
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));
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));
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);
47
46
  const isCallbackExist = typeof onClickCallback === "function";
48
47
  const getHintMarkUp = className => {
49
48
  return /*#__PURE__*/_react.default.createElement("div", {
50
49
  "data-testid": "test-hint-text",
51
- className: (0, _classnames.default)("hint__text", "hint__text_".concat(side), "hint--".concat(className, "__text"))
50
+ className: (0, _classnames.default)("hint__text", "hint__text_".concat(side), "hint--".concat(className, "__text")),
51
+ onMouseLeave: () => isHoverableContent && handleOpenType === "hover" && startCloseTimeout()
52
52
  }, hint, children);
53
53
  };
54
54
  const setHintContainerStyles = () => {
@@ -115,13 +115,47 @@ const Hint = _ref => {
115
115
  if (!hc) return null;
116
116
  return /*#__PURE__*/(0, _reactDom.createPortal)(getHintMarkUp(className), hc);
117
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
+ };
118
154
  (0, _react.useEffect)(() => {
119
155
  (0, _utils2.initHintContainer)(hintId, hintContainer);
120
156
  }, []);
121
157
  (0, _react.useEffect)(() => {
122
158
  setHintContainerStyles();
123
-
124
- //! Обеспечиваем работу колбэка ТОЛЬКО для открытых тултипов
125
159
  if (isOpen) {
126
160
  document.addEventListener("scroll", handleScroll, true);
127
161
  document.addEventListener("click", handleClickOutside, true);
@@ -130,6 +164,9 @@ const Hint = _ref => {
130
164
  document.removeEventListener("click", handleClickOutside, true);
131
165
  }
132
166
  }, [isOpen]);
167
+ (0, _react.useEffect)(() => {
168
+ stopCloseTimeout(null);
169
+ }, [activeHint]);
133
170
  return /*#__PURE__*/_react.default.createElement("div", {
134
171
  className: (0, _classnames.default)("hint", className),
135
172
  ref: hintRef
@@ -137,9 +174,9 @@ const Hint = _ref => {
137
174
  tabIndex: isAccessability ? 0 : -1,
138
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,
139
176
  "aria-label": isAccessability && label || "",
140
- onClick: () => handleOpenType === "click" && (isCallbackExist ? onClickCallback() : setIsOpen(!isOpen)),
141
- onMouseEnter: () => handleOpenType === "hover" && setIsOpen(true),
142
- onMouseLeave: () => handleOpenType === "hover" && setIsOpen(false),
177
+ onClick: handle.onClickHintIcon,
178
+ onMouseEnter: handle.onMouseEnterHintIcon,
179
+ onMouseLeave: handle.onMouseLeaveHintIcon,
143
180
  className: (0, _classnames.default)("hint__button", {
144
181
  hint__button_active: isOpen
145
182
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.5.16",
3
+ "version": "1.5.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [