@skbkontur/side-menu 1.5.0 → 1.6.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.6.0](https://git.skbkontur.ru/ui/ui-parking/compare/@skbkontur/side-menu@1.5.1...@skbkontur/side-menu@1.6.0) (2023-09-14)
7
+
8
+
9
+ ### Features
10
+
11
+ * **SideMenuItem:** change caption type ([fa3d134](https://git.skbkontur.ru/ui/ui-parking/commits/fa3d13435783243268ebc631b98836a8da22229a))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.5.1](https://git.skbkontur.ru/ui/ui-parking/compare/@skbkontur/side-menu@1.5.0...@skbkontur/side-menu@1.5.1) (2023-09-11)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **SideMenu:** separated sub menu fix ([f8c9af9](https://git.skbkontur.ru/ui/ui-parking/commits/f8c9af968945a7d36ad29cc4c8599a342e34f72e))
23
+
24
+
25
+
26
+
27
+
6
28
  # [1.5.0](https://git.skbkontur.ru/ui/ui-parking/compare/@skbkontur/side-menu@1.4.2...@skbkontur/side-menu@1.5.0) (2023-09-05)
7
29
 
8
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skbkontur/side-menu",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
@@ -8,7 +8,7 @@ import { SideMenuContext } from '../SideMenuContext';
8
8
  import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers';
9
9
  var SideMenuDropdownInner = forwardRef(function (_a, ref) {
10
10
  var _b, _c;
11
- var icon = _a.icon, id = _a.id, _generatedId = _a._generatedId, children = _a.children, _d = _a.caption, caption = _d === void 0 ? 'СКБ Контур' : _d, marker = _a.marker, subCaption = _a.subCaption, className = _a.className, _e = _a.disableAnimations, disableAnimations = _e === void 0 ? false : _e, menuWidth = _a.menuWidth, _isAvatar = _a._isAvatar, rest = __rest(_a, ["icon", "id", "_generatedId", "children", "caption", "marker", "subCaption", "className", "disableAnimations", "menuWidth", "_isAvatar"]);
11
+ var icon = _a.icon, id = _a.id, _generatedId = _a._generatedId, children = _a.children, caption = _a.caption, marker = _a.marker, subCaption = _a.subCaption, className = _a.className, _d = _a.disableAnimations, disableAnimations = _d === void 0 ? false : _d, menuWidth = _a.menuWidth, _isAvatar = _a._isAvatar, rest = __rest(_a, ["icon", "id", "_generatedId", "children", "caption", "marker", "subCaption", "className", "disableAnimations", "menuWidth", "_isAvatar"]);
12
12
  var context = useContext(SideMenuContext);
13
13
  var theme = getSideMenuTheme(useContext(ThemeContext));
14
14
  return (React.createElement("li", { className: cx((_b = {}, _b[jsStyles.wrapper()] = true, _b), className), ref: ref },
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
- export interface BackButtonProps {
3
- caption?: string;
4
- id?: string;
2
+ import { CommonClickableElementProps } from './ClickableElement';
3
+ export interface BackButtonProps extends Pick<CommonClickableElementProps, 'caption' | 'id'> {
5
4
  href?: string;
6
5
  generatedId?: string;
7
6
  }
@@ -4,7 +4,7 @@ export interface CommonClickableElementProps extends CommonProps {
4
4
  children?: React.ReactNode;
5
5
  icon: React.ReactElement;
6
6
  marker?: string | true;
7
- caption?: string;
7
+ caption?: ReactNode;
8
8
  subCaption?: ReactNode;
9
9
  id?: string;
10
10
  isButton?: boolean;
@@ -65,17 +65,6 @@ var ClickableElement = forwardRef(function (_a, ref) {
65
65
  (_a = context.setIsMouseOutside) === null || _a === void 0 ? void 0 : _a.call(context, true);
66
66
  }
67
67
  };
68
- var setSeparatedMenuIsShown = function () {
69
- var _a, _b;
70
- if (_isDropdown || _isSubMenu || !context.isSeparatedMenu)
71
- return;
72
- if (children) {
73
- (_a = context.setIsSeparatedMenuShown) === null || _a === void 0 ? void 0 : _a.call(context, true);
74
- }
75
- else {
76
- (_b = context.setIsSeparatedMenuShown) === null || _b === void 0 ? void 0 : _b.call(context, false);
77
- }
78
- };
79
68
  var handleClick = function (e) {
80
69
  onClick === null || onClick === void 0 ? void 0 : onClick(e);
81
70
  var lastElementInTheHierarchy = !hasChildren(id || rest.href, _generatedId) && !_isDropdown && !_isBackButton;
@@ -83,7 +72,6 @@ var ClickableElement = forwardRef(function (_a, ref) {
83
72
  toggleIsShown(lastElementInTheHierarchy);
84
73
  setIsMinimized(lastElementInTheHierarchy);
85
74
  setMouseIsOutside(lastElementInTheHierarchy);
86
- setSeparatedMenuIsShown();
87
75
  };
88
76
  var handleFocus = function (e) {
89
77
  onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
@@ -39,11 +39,32 @@ var InnerBody = function (_a) {
39
39
  setParents(getAllParents(context.activeMenuItem, flattedArrayOfAllElements.current));
40
40
  }
41
41
  };
42
+ var activeMenuItemHasParent = function () {
43
+ if (!context.activeMenuItem)
44
+ return;
45
+ var parentOfActiveMenuItem = getAllParents(context.activeMenuItem, flattedArrayOfAllElements.current);
46
+ return parentOfActiveMenuItem.length > 0;
47
+ };
48
+ var activeMenuItemHasChildren = function () {
49
+ if (!context.activeMenuItem)
50
+ return;
51
+ var childrenOfActiveMenuItem = getChildrenIdArray(flattedArrayOfAllElements.current, context.activeMenuItem);
52
+ var childrenOfActiveMenuItemGenerated = getChildrenIdArray(flattedArrayOfAllElements.current, context.activeMenuItem, true);
53
+ return childrenOfActiveMenuItem.length > 0 || childrenOfActiveMenuItemGenerated.length > 0;
54
+ };
55
+ var setSeparatedMenuIsShown = function () {
56
+ var _a;
57
+ if (!context.isSeparatedMenu)
58
+ return;
59
+ var isActive = activeMenuItemHasParent() || activeMenuItemHasChildren() || false;
60
+ (_a = context.setIsSeparatedMenuShown) === null || _a === void 0 ? void 0 : _a.call(context, isActive);
61
+ };
42
62
  useEffect(function () {
43
63
  getFlattedArrayOfAllElements();
44
64
  }, []);
45
65
  useEffect(function () {
46
66
  getOpenedParents();
67
+ setSeparatedMenuIsShown();
47
68
  }, [context.activeMenuItem]);
48
69
  var levelIndex = 0;
49
70
  return (React.createElement(SideMenuContext.Provider, { value: __assign({ openedParents: parents, flattedArrayOfAllElements: flattedArrayOfAllElements.current }, context) }, React.Children.map(children, function (child) {
@@ -27,8 +27,9 @@ export var Caption = forwardRef(function (_a, ref) {
27
27
  var _d = useContext(SideMenuContext), isBeingTransitioned = _d.isBeingTransitioned, isSeparatedMenu = _d.isSeparatedMenu, size = _d.size, isTouchScreen = _d.isTouchScreen, hasSubIcons = _d.hasSubIcons;
28
28
  var captionRef = useRef(null);
29
29
  var _e = useState(''), tail = _e[0], setTail = _e[1];
30
+ var isCaptionPlainText = typeof caption === 'string';
30
31
  useEffect(function () {
31
- if (!_isDropdown || !captionRef.current || !caption) {
32
+ if (!_isDropdown || !captionRef.current || !caption || !isCaptionPlainText) {
32
33
  return;
33
34
  }
34
35
  captionRef.current.innerText = caption;
@@ -45,14 +46,17 @@ export var Caption = forwardRef(function (_a, ref) {
45
46
  if (userName === void 0) { userName = ''; }
46
47
  return _isAvatar && userName.split(' ').length === 1;
47
48
  };
49
+ var Component = isCaptionPlainText ? 'p' : 'div';
48
50
  return (React.createElement("div", { className: cx((_b = {},
49
51
  _b[jsStyles.root()] = true,
50
52
  _b[jsStyles.rootMultiline()] = isMultiline && !_isSubMenu,
51
53
  _b)), ref: ref },
52
- React.createElement("p", { className: cx((_c = {},
54
+ React.createElement(Component, { className: cx((_c = {},
53
55
  _c[jsStyles.caption(theme)] = true,
54
56
  _c[jsStyles.captionDropdown()] = _isDropdown,
55
- _c[jsStyles.captionTruncated()] = _isDropdown && (!_isAvatar || isAvatarCaptionSingleWord(caption, _isAvatar)),
57
+ _c[jsStyles.captionTruncated()] = isCaptionPlainText &&
58
+ _isDropdown &&
59
+ (!_isAvatar || isAvatarCaptionSingleWord(caption, _isAvatar)),
56
60
  _c[jsStyles.captionSubItem(theme)] = _isSubMenu,
57
61
  _c[jsStyles.captionSubItemSeparatedMenuTopLevel()] = isSeparatedMenu && !_isNestedSubMenu && _isSubMenu && !hasIcon,
58
62
  _c[jsStyles.captionNestedItemSeparatedMenu()] = isSeparatedMenu && _isNestedSubMenu && !hasIcon,
@@ -7,6 +7,18 @@ import { Caption } from './Caption';
7
7
  import { Marker } from './Marker';
8
8
  import { getSideMenuTheme } from '../../../lib/theming/ThemeHelpers';
9
9
  import { ThemeContext } from '@skbkontur/react-ui';
10
+ var getCaptionLineHeight = function (theme, isTouchScreen, _isSubMenu, size) {
11
+ if (isTouchScreen) {
12
+ if (_isSubMenu) {
13
+ return theme.sideMenuCaptionSubItemLineHeightForTouchScreens;
14
+ }
15
+ return theme.sideMenuCaptionLineHeightForTouchScreens;
16
+ }
17
+ if (size === 'large') {
18
+ return theme.sideMenuCaptionLargeLineHeight;
19
+ }
20
+ return theme.sideMenuCaptionLineHeight;
21
+ };
10
22
  /**
11
23
  * Контент для SideMenuItem или SideMenuLink
12
24
  */
@@ -19,13 +31,17 @@ var ItemContent = forwardRef(function (_a, ref) {
19
31
  var _d = useState(false), isMultiline = _d[0], setIsMultiline = _d[1];
20
32
  var theme = getSideMenuTheme(useContext(ThemeContext));
21
33
  useEffect(function () {
22
- if (!textRef.current || _isBackButton)
23
- return;
24
- var text = textRef.current.querySelector('p');
25
- if ((text && parseInt(getComputedStyle(text).lineHeight) < text.clientHeight) || subCaption) {
34
+ if (subCaption) {
26
35
  setIsMultiline(true);
36
+ return;
27
37
  }
28
- });
38
+ if (!textRef.current || _isBackButton || _isDropdown)
39
+ return;
40
+ var captionLineHeight = getCaptionLineHeight(theme, context.isTouchScreen, _isSubMenu, size);
41
+ var isMultiline = parseInt(captionLineHeight) < textRef.current.offsetHeight;
42
+ if (isMultiline)
43
+ setIsMultiline(true);
44
+ }, [caption, context.isBeingTransitioned]);
29
45
  var isSeparatedSubMenuInNarrowDesktop = _isSubMenu && context.isSeparatedMenu && context.isNarrowDesktop;
30
46
  return (React.createElement("div", { className: cx((_b = {},
31
47
  _b[jsStyles.root(theme)] = true,
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
- interface SeparatedSubMenuProps {
2
+ import { CommonClickableElementProps } from './ClickableElement';
3
+ interface SeparatedSubMenuProps extends Pick<CommonClickableElementProps, 'caption' | 'id'> {
3
4
  children?: React.ReactNode;
4
5
  generatedId?: string;
5
- id?: string;
6
6
  href?: string;
7
- caption?: string;
8
7
  htmlId: string;
9
8
  }
10
9
  declare const SeparatedSubMenuWithStaticFields: React.ForwardRefExoticComponent<SeparatedSubMenuProps & React.RefAttributes<HTMLDivElement>> & {
@@ -1,14 +1,13 @@
1
1
  import React from 'react';
2
- interface SubMenuProps {
2
+ import { CommonClickableElementProps } from './ClickableElement';
3
+ interface SubMenuProps extends Pick<CommonClickableElementProps, 'caption' | 'id'> {
3
4
  children?: React.ReactNode;
4
5
  generatedId?: string;
5
6
  isOpened?: boolean;
6
7
  isSubMenu?: boolean;
7
8
  isMinimized?: boolean;
8
9
  isSeparatedMenu?: boolean;
9
- id?: string;
10
10
  href?: string;
11
- caption?: string;
12
11
  htmlId: string;
13
12
  }
14
13
  declare const SubMenuWithStaticFields: React.ForwardRefExoticComponent<SubMenuProps & React.RefAttributes<HTMLDivElement | HTMLUListElement>> & {