intelicoreact 1.4.69 → 1.4.70

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.
@@ -11,37 +11,51 @@ var _reactFeather = require("react-feather");
11
11
  require("./AccordionText.scss");
12
12
  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); }
13
13
  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; }
14
+ const defaultText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";
14
15
  const AccordionText = _ref => {
15
16
  let {
16
17
  isDefaultOpen = false,
17
18
  isOuterOpen = false,
18
- isForcedAlwaysAccordion = false,
19
19
  className,
20
- text = "Default Accordion Text."
20
+ text = defaultText,
21
+ shortText = null
21
22
  } = _ref;
22
23
  const bodyRef = (0, _react.useRef)(null);
23
24
  const [isOpen, setIsOpen] = (0, _react.useState)(isDefaultOpen);
24
- const [isAccordionNeeded, setIsAccordionNeeded] = (0, _react.useState)(false);
25
- function isEllipsisActive(e) {
26
- return e.offsetWidth < e.scrollWidth;
27
- }
25
+ const [isNeedTrimText, setIsNeedTrimText] = (0, _react.useState)(false);
28
26
  (0, _react.useEffect)(() => {
29
27
  setIsOpen(isOuterOpen);
30
28
  }, [isOuterOpen]);
31
29
  (0, _react.useEffect)(() => {
32
- if (bodyRef !== null && bodyRef !== void 0 && bodyRef.current) {
33
- setIsAccordionNeeded(isEllipsisActive(bodyRef === null || bodyRef === void 0 ? void 0 : bodyRef.current));
30
+ const checkEllipsis = () => {
31
+ if (bodyRef.current) {
32
+ setIsNeedTrimText(bodyRef.current.scrollWidth > bodyRef.current.clientWidth);
33
+ }
34
+ };
35
+ const resizeObserver = new ResizeObserver(() => {
36
+ checkEllipsis();
37
+ });
38
+ if (bodyRef.current) {
39
+ resizeObserver.observe(bodyRef.current);
40
+ checkEllipsis();
34
41
  }
35
- }, [bodyRef === null || bodyRef === void 0 ? void 0 : bodyRef.current]);
42
+ return () => {
43
+ if (bodyRef.current) {
44
+ resizeObserver.unobserve(bodyRef.current);
45
+ }
46
+ };
47
+ }, [text]);
36
48
  return /*#__PURE__*/_react.default.createElement("div", {
37
49
  className: (0, _classnames.default)("accordion-text", className, {
38
50
  "accordion-text--open": isOpen
39
51
  }),
40
- onClick: () => setIsOpen(isOpen => !isOpen)
52
+ onClick: () => setIsOpen(prevIsOpen => !prevIsOpen)
41
53
  }, /*#__PURE__*/_react.default.createElement("div", {
42
- className: "accordion-text__body",
54
+ className: (0, _classnames.default)("accordion-text__body", {
55
+ "accordion-text__body--trim-text": isNeedTrimText && !isOpen
56
+ }),
43
57
  ref: bodyRef
44
- }, text), isAccordionNeeded || isForcedAlwaysAccordion && /*#__PURE__*/_react.default.createElement("div", {
58
+ }, shortText ? isOpen ? text : shortText : text), /*#__PURE__*/_react.default.createElement("div", {
45
59
  className: "accordion-text__toggle"
46
60
  }, isOpen ? /*#__PURE__*/_react.default.createElement(_reactFeather.ChevronUp, null) : /*#__PURE__*/_react.default.createElement(_reactFeather.ChevronDown, null)));
47
61
  };
@@ -1,50 +1,53 @@
1
1
  .accordion-text {
2
2
  position: relative;
3
-
4
- height: 100%;
5
- max-height: 18px;
6
3
  padding: 4px 24px 4px 8px;
7
-
8
4
  font-size: 12px;
9
5
  font-weight: 400;
10
6
  line-height: 18px;
11
7
  cursor: pointer;
12
-
13
8
  border-radius: 4px;
14
9
  background-color: rgba(48, 57, 91, 0.05);
10
+ overflow: hidden;
11
+ height: 25px;
12
+ box-sizing: border-box;
15
13
 
16
14
  &--open {
17
15
  max-height: 100%;
18
- }
19
-
20
- &--open &__body {
21
- overflow: visible;
22
-
23
- white-space: normal; // Change 'wrap' to 'normal'
24
- text-overflow: clip; // Change 'unset' to 'clip'
16
+ height: fit-content;
25
17
  }
26
18
 
27
19
  &__body {
28
20
  overflow: hidden;
21
+ white-space: nowrap;
22
+ text-overflow: ellipsis;
23
+ width: 100%; // Устанавливаем ширину в 100% родительского контейнера
24
+ }
29
25
 
26
+ &__body--trim-text > * {
30
27
  white-space: nowrap;
31
28
  text-overflow: ellipsis;
29
+ overflow: hidden; // Необходимо для работы обрезки текста
30
+ width: 100%; // Обеспечивает переполнение текста
31
+ }
32
+
33
+ &--open &__body {
34
+ white-space: normal; // Вернуть к нормальному переносу в открытом состоянии
35
+ text-overflow: clip; // Убираем обрезку текста
36
+ overflow: visible; // Убираем скрытие переполненного контента в открытом состоянии
32
37
  }
33
38
 
34
39
  &__toggle {
35
40
  position: absolute;
36
41
  top: 0;
37
42
  right: 0;
38
-
39
43
  display: flex;
40
44
  justify-content: center;
41
45
  align-items: center;
42
-
43
46
  width: 16px;
44
47
  height: 16px;
45
48
  margin: 4px;
46
49
  padding: 2px;
47
-
48
50
  color: #a0a4b0;
51
+ pointer-events: none;
49
52
  }
50
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.4.69",
3
+ "version": "1.4.70",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [