@skbkontur/side-menu 4.0.10-ddcb0.0 → 4.1.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +13 -40
  3. package/SideMenuDataTids.d.ts +1 -2
  4. package/SideMenuDataTids.js +1 -2
  5. package/hooks/useMemoIcon.d.ts +2 -1
  6. package/hooks/useMemoIcon.js +9 -0
  7. package/internal/themes/SideMenuDarkTheme.js +3 -3
  8. package/internal/themes/SideMenuTheme.d.ts +7 -4
  9. package/internal/themes/SideMenuTheme.js +26 -9
  10. package/lib/theming/ThemeHelpers.js +4 -0
  11. package/lib/utils/scripts.d.ts +0 -1
  12. package/lib/utils/scripts.js +0 -9
  13. package/package.json +4 -5
  14. package/src/Navigation.d.ts +53 -0
  15. package/src/Navigation.js +194 -0
  16. package/src/SideMenu/SideMenu.d.ts +4 -7
  17. package/src/SideMenu/SideMenu.js +178 -148
  18. package/src/SideMenu/SideMenu.styles.js +2 -2
  19. package/src/SideMenuAvatar/SideMenuAvatar.js +2 -11
  20. package/src/SideMenuContext.d.ts +9 -16
  21. package/src/SideMenuContext.js +1 -6
  22. package/src/SideMenuDropdown/SideMenuDropdown.js +18 -11
  23. package/src/SideMenuDropdown/SideMenuDropdown.styles.js +3 -3
  24. package/src/SideMenuFooter/SideMenuFooter.js +3 -15
  25. package/src/SideMenuFooter/SideMenuFooter.styles.d.ts +0 -4
  26. package/src/SideMenuFooter/SideMenuFooter.styles.js +4 -16
  27. package/src/SideMenuHeader/SideMenuHeader.js +3 -4
  28. package/src/SideMenuNotifications/BellWidget.js +13 -6
  29. package/src/SideMenuNotifications/BellWidgetError.js +6 -3
  30. package/src/SideMenuNotifications/BellWidgetView.styles.d.ts +7 -4
  31. package/src/SideMenuNotifications/BellWidgetView.styles.js +20 -9
  32. package/src/SideMenuNotifications/utils/getWrapperHeightClass.d.ts +11 -0
  33. package/src/SideMenuNotifications/utils/getWrapperHeightClass.js +10 -0
  34. package/src/SideMenuSubItem/SideMenuSubItem.d.ts +1 -1
  35. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.js +0 -1
  36. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.d.ts +0 -1
  37. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.js +2 -5
  38. package/src/SideMenuSubLink/SideMenuSubLink.d.ts +1 -1
  39. package/src/Tree.d.ts +17 -0
  40. package/src/Tree.js +135 -0
  41. package/src/internal/BackButton.d.ts +3 -1
  42. package/src/internal/BackButton.js +3 -4
  43. package/src/internal/ClickableElement.d.ts +1 -8
  44. package/src/internal/ClickableElement.js +67 -125
  45. package/src/internal/ClickableElement.styles.d.ts +0 -1
  46. package/src/internal/ClickableElement.styles.js +3 -6
  47. package/src/internal/ItemContent/Caption.d.ts +1 -1
  48. package/src/internal/ItemContent/Caption.js +26 -9
  49. package/src/internal/ItemContent/Icon.js +2 -3
  50. package/src/internal/ItemContent/Icon.styles.d.ts +0 -1
  51. package/src/internal/ItemContent/Icon.styles.js +3 -6
  52. package/src/internal/ItemContent/ItemContent.js +5 -17
  53. package/src/internal/ItemContent/ItemContent.styles.d.ts +0 -1
  54. package/src/internal/ItemContent/ItemContent.styles.js +4 -7
  55. package/src/internal/RightBorder.d.ts +9 -0
  56. package/src/internal/RightBorder.js +37 -0
  57. package/src/internal/{CollapseToggle.styles.d.ts → RightBorder.styles.d.ts} +1 -0
  58. package/src/internal/RightBorder.styles.js +14 -0
  59. package/src/internal/SeparatedSubMenu.js +9 -7
  60. package/src/internal/SeparatedSubMenu.styles.d.ts +3 -0
  61. package/src/internal/SeparatedSubMenu.styles.js +15 -6
  62. package/src/internal/SideMenuLogotype.js +8 -10
  63. package/src/internal/SubMenu.js +2 -3
  64. package/hooks/useNodeState.d.ts +0 -7
  65. package/hooks/useNodeState.js +0 -12
  66. package/hooks/useSideMenuReducer.d.ts +0 -13
  67. package/hooks/useSideMenuReducer.js +0 -23
  68. package/src/internal/CollapseToggle.d.ts +0 -1
  69. package/src/internal/CollapseToggle.js +0 -27
  70. package/src/internal/CollapseToggle.styles.js +0 -12
  71. package/src/internal/NarrowAccordionDropdown.d.ts +0 -13
  72. package/src/internal/NarrowAccordionDropdown.js +0 -34
  73. package/src/navigationAttributes.d.ts +0 -3
  74. package/src/navigationAttributes.js +0 -3
  75. package/src/state/reducer.d.ts +0 -2
  76. package/src/state/reducer.js +0 -258
  77. package/src/state/selectors.d.ts +0 -16
  78. package/src/state/selectors.js +0 -71
  79. package/src/state/types.d.ts +0 -59
  80. package/src/state/types.js +0 -17
  81. package/unstable.d.ts +0 -1
  82. package/unstable.js +0 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,32 @@
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
+ # [4.1.0](/compare/@skbkontur/side-menu@4.0.10...@skbkontur/side-menu@4.1.0) (2026-11-05)
7
+
8
+
9
+ ### Features
10
+
11
+ * **side-menu:** update @skbkontur/colors to 3.0.0 2c3514a
12
+
13
+
14
+
15
+
16
+
17
+ ## [4.0.10](/compare/@skbkontur/side-menu@4.0.9...@skbkontur/side-menu@4.0.10) (2026-09-16)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **SideMenu:** fit BellWidget error layout on small screens fd17bcd
23
+ * **SideMenu:** fit BellWidget height to MobilePopup on mobile dd8c638
24
+ * **SideMenu:** show deprecation warning on sideMenuProductColor var customization a53a9b9
25
+ * **SideMenu:** use isMobile for BellWidget width 19a4233
26
+ * **SideMenu:** use shapeBoldWarning for BellWidgetError icons ee5f199
27
+
28
+
29
+
30
+
31
+
6
32
  ## [4.0.9](/compare/@skbkontur/side-menu@4.0.8...@skbkontur/side-menu@4.0.9) (2026-07-23)
7
33
 
8
34
 
package/README.md CHANGED
@@ -48,7 +48,7 @@ import { IconAttachLinkRegular24 } from '@skbkontur/icons/IconAttachLinkRegular2
48
48
  <SideMenu.SubItem caption={'Внутренние'} marker/>
49
49
  <SideMenu.SubItem caption={'Черновики'}/>
50
50
  <SideMenu.SubItem caption={'Удаленные'}/>
51
- <SideMenu.SubLink caption={'Cсылка в подменю'} href={'https://www.google.com/search?q=test'} target={'_blank'}/>
51
+ <SideMenu.SubLink caption={'Ссылка в подменю'} href={'https://www.google.com/search?q=test'} target={'_blank'}/>
52
52
  <SideMenu.SubItemHeader>Согласованные</SideMenu.SubItemHeader>
53
53
  <SideMenu.SubItem caption={'Требуют обработки'}/>
54
54
  <SideMenu.SubItem caption={'Обработанные'}/>
@@ -362,7 +362,7 @@ const items = [
362
362
  `sideMenuTabletMediaQuery = '(min-width: 768px)';`
363
363
  `sideMenuMobileMediaQuery = '(min-width: 0px)';`
364
364
 
365
- Для того чтобы пропускать брекпойнты, достаточно указать значение, равное следующему за ним брейкпойнту.
365
+ Для того чтобы пропускать брейкпойнты, достаточно указать значение, равное следующему за ним брейкпойнту.
366
366
  Например, в следующем случае у `SideMenu` не будет адаптива для планшетов:
367
367
 
368
368
  `<SideMenu tabletMediaQuery={'(min-width: 768px)'} narrowDesktopMediaQuery={'(min-width: 768px)'}/>`
@@ -559,53 +559,30 @@ const [isOpen, setIsOpen] = React.useState(true);
559
559
  </div>
560
560
  ```
561
561
 
562
- > На широких экранах меню сворачивается и разворачивается кнопкой-переключателем в футере (`CollapseToggle`).
563
- > Управлять состоянием можно через пропы `isOpen` / `onOpen` / `onClose` (см. пример выше).
564
- >
565
- > Пропы `isPinned` и `onPinnedValueChange` устарели — используйте `isOpen` и `onClose`.
566
-
567
- #### Пример с сохранением состояния меню (`isOpen` + `localStorage`)
562
+ #### Пример с использованием пропа `isPinned`
568
563
 
569
564
  ```jsx harmony
570
565
  import { CdnLogo } from '@skbkontur/ui-cdn-components';
571
566
  import { SideMenu } from '@skbkontur/side-menu';
572
567
  import { IconDocTextRegular24 } from '@skbkontur/icons/IconDocTextRegular24';
573
568
  import { IconSettingsGearRegular24 } from '@skbkontur/icons/IconSettingsGearRegular24';
574
- import { ThemeContext, ThemeFactory } from '@skbkontur/react-ui';
575
-
576
- const readIsOpen = () => {
577
- try {
578
- return localStorage.getItem('sideMenuIsOpen') !== 'false';
579
- } catch {
580
- return true;
581
- }
582
- };
583
-
584
- const writeIsOpen = (value) => {
585
- try {
586
- localStorage.setItem('sideMenuIsOpen', String(value));
587
- } catch {
588
- /* localStorage может быть недоступен (приватный режим, отключено) */
589
- }
590
- };
569
+ import { ThemeContext, ThemeFactory, Button } from '@skbkontur/react-ui';
591
570
 
592
- const [isOpen, setIsOpen] = React.useState(readIsOpen());
571
+ const [isPinned, setIsPinned] = React.useState(localStorage.getItem('sideMenuIsPinned') === 'true');
593
572
 
594
573
  React.useEffect(() => {
595
- const sync = () => setIsOpen(readIsOpen());
596
- window.addEventListener('storage', sync);
597
- return () => window.removeEventListener('storage', sync);
574
+ window.addEventListener('storage', () => {
575
+ setIsPinned(localStorage.getItem('sideMenuIsPinned') === 'true');
576
+ });
598
577
  }, []);
599
578
 
600
- const persist = (value) => {
601
- setIsOpen(value);
602
- writeIsOpen(value);
603
- };
604
-
605
579
  <div style={{ height: '200px', position: 'relative', display: 'flex' }}>
606
580
  <ThemeContext.Provider
607
581
  value={ThemeFactory.create({ sideMenuWidth: '300px', sideMenuProductColor: '#64b419' })}>
608
- <SideMenu isOpen={isOpen} onOpen={() => persist(true)} onClose={() => persist(false)}>
582
+ <SideMenu isPinned={isPinned}
583
+ onPinnedValueChange={(isPinned) => {
584
+ localStorage.setItem('sideMenuIsPinned', String(isPinned));
585
+ }}>
609
586
  <SideMenu.Header productLogo={<CdnLogo logo="ofd" />} />
610
587
  <SideMenu.Body>
611
588
  <SideMenu.Item icon={<IconDocTextRegular24 />} caption={'Документы к подписанию'} />
@@ -649,14 +626,10 @@ const persist = (value) => {
649
626
  //#region NestedMenu
650
627
  sideMenuNestedMenuPaddingLeft: string;
651
628
  //#endregion
652
- //#region CollapseToggle (для широких экранов)
653
- sideMenuCollapseToggleSize: string;
654
- sideMenuCollapseToggleSizeLarge: string;
655
- //#endregion
656
629
  //#region RightBorder
657
630
  sideMenuRightBorderWidth: string;
658
631
  sideMenuRightBorderIconColor: string;
659
- sideMenuRightBorderIconColorHover: string;
632
+ sideMenuRightBorderHoverIconColor: string;
660
633
  // #region BackButton (for Mobiles)
661
634
  sideMenuBackButtonCaptionFontWeight: string;
662
635
  sideMenuBackButtonCaptionFontSize: string;
@@ -3,10 +3,9 @@ export declare const SideMenuDataTids: {
3
3
  burger: string;
4
4
  backButton: string;
5
5
  separatedSubMenu: string;
6
+ rightBorder: string;
6
7
  clickableElement: string;
7
8
  footer: string;
8
- collapseToggle: string;
9
- narrowAccordionDropdown: string;
10
9
  bellSideMenuDropdownButton: string;
11
10
  bellCloseButton: string;
12
11
  bellHeader: string;
@@ -3,10 +3,9 @@ export var SideMenuDataTids = {
3
3
  burger: 'SideMenu__burger',
4
4
  backButton: 'SideMenu__backButton',
5
5
  separatedSubMenu: 'SideMenu__separatedSubMenu',
6
+ rightBorder: 'SideMenu__rightBorder',
6
7
  clickableElement: 'SideMenu__clickableElement',
7
8
  footer: 'SideMenu__footer',
8
- collapseToggle: 'SideMenu__collapseToggle',
9
- narrowAccordionDropdown: 'SideMenu__narrowAccordionDropdown',
10
9
  bellSideMenuDropdownButton: 'SideMenu__bellDropdownButton',
11
10
  bellCloseButton: 'SideMenu__bellCloseButton',
12
11
  bellHeader: 'SideMenu__bellHeaderWidget',
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  interface IconParams {
3
3
  isOpened: boolean;
4
- onClick: (e: React.MouseEvent) => void;
4
+ onClick: () => void;
5
5
  }
6
6
  export declare const useMemoIcon: (children: React.ReactNode, { isOpened, onClick }: IconParams) => JSX.Element | undefined;
7
+ export declare const useMemoBorderIcon: (isCollapsed?: boolean) => JSX.Element;
7
8
  export {};
@@ -1,4 +1,5 @@
1
1
  import { IconArrowCDownRegular16 } from '@skbkontur/icons/IconArrowCDownRegular16';
2
+ import { IconArrowCLeftRegular16 } from '@skbkontur/icons/IconArrowCLeftRegular16';
2
3
  import { IconArrowCRightRegular16 } from '@skbkontur/icons/IconArrowCRightRegular16';
3
4
  import React, { useMemo } from 'react';
4
5
  export var useMemoIcon = function (children, _a) {
@@ -12,3 +13,11 @@ export var useMemoIcon = function (children, _a) {
12
13
  }
13
14
  }, [isOpened, children]);
14
15
  };
16
+ export var useMemoBorderIcon = function (isCollapsed) {
17
+ return useMemo(function () {
18
+ if (isCollapsed) {
19
+ return React.createElement(IconArrowCRightRegular16, null);
20
+ }
21
+ return React.createElement(IconArrowCLeftRegular16, null);
22
+ }, [isCollapsed]);
23
+ };
@@ -9,18 +9,18 @@ var SideMenuDarkTheme = /** @class */ (function (_super) {
9
9
  }
10
10
  // #region SideMenu
11
11
  SideMenuDarkTheme.sideMenuBg = colors.surfaceLow;
12
- SideMenuDarkTheme.sideMenuBgHover = colors.shapeOtherNeutralFaintSolid;
12
+ SideMenuDarkTheme.sideMenuBgHover = colors.shapeFaintNeutralSolid;
13
13
  // #endregion
14
14
  // #region Divider
15
15
  SideMenuDarkTheme.sideMenuDividerBg = colors.lineNeutralFaint;
16
16
  // #endregion
17
17
  // #region Item
18
- SideMenuDarkTheme.sideMenuItemBgHover = colors.shapeOtherBacklessHover;
18
+ SideMenuDarkTheme.sideMenuItemBgHover = colors.shapeOtherBacklessAlphaHover;
19
19
  SideMenuDarkTheme.sideMenuItemBgActive = colors.shapeOtherBase;
20
20
  SideMenuDarkTheme.sideMenuItemColor = colors.textNeutralHeavy;
21
21
  SideMenuDarkTheme.sideMenuItemColorDisabled = colors.textNeutralFaint;
22
22
  SideMenuDarkTheme.sideMenuItemBoxShadowColorFocus = colors.lineAccentBold;
23
- SideMenuDarkTheme.sideMenuSubItemWithSeparatedSubMenuBgHover = colors.shapeOtherBacklessHover;
23
+ SideMenuDarkTheme.sideMenuSubItemWithSeparatedSubMenuBgHover = colors.shapeOtherBacklessAlphaHover;
24
24
  SideMenuDarkTheme.sideMenuSubItemWithSeparatedSubMenuBgActive = colors.shapeFaintNeutralAlpha;
25
25
  // #endregion
26
26
  // #region Icon
@@ -35,11 +35,9 @@ export declare class SideMenuTheme extends BasicThemeClassForExtension {
35
35
  static sideMenuFooterPaddingTop: string;
36
36
  static sideMenuFooterPaddingBottom: string;
37
37
  static get sideMenuFooterDividerColor(): string;
38
- static sideMenuCollapseToggleSize: string;
39
38
  static sideMenuItemBorderRadius: string;
40
39
  static sideMenuItemBgHover: string;
41
40
  static sideMenuItemBgActive: string;
42
- static sideMenuItemBgPressed: string;
43
41
  static sideMenuItemColor: string;
44
42
  static sideMenuItemColorDisabled: string;
45
43
  static sideMenuItemBoxShadowColorFocus: string;
@@ -57,8 +55,6 @@ export declare class SideMenuTheme extends BasicThemeClassForExtension {
57
55
  static sideMenuSubItemContentPaddingY: string;
58
56
  static sideMenuSubItemContentPaddingYLarge: string;
59
57
  static sideMenuSubItemContentPaddingYTouchScreen: string;
60
- static sideMenuSubItemContentPaddingYDropdown: string;
61
- static sideMenuSubItemContentPaddingXDropdown: string;
62
58
  static sideMenuIconSize: string;
63
59
  static sideMenuIconMarginY: string;
64
60
  static sideMenuIconMarginX: string;
@@ -126,6 +122,13 @@ export declare class SideMenuTheme extends BasicThemeClassForExtension {
126
122
  static sideMenuNotificationsMarkerBg: string;
127
123
  /** от 400px до 784px */
128
124
  static sideMenuNotificationsWrapperHeight: string;
125
+ /**
126
+ * CSS-выражение для вычитания из 100vh на mobile (отступы MobilePopup `@skbkontur/react-ui`).
127
+ *
128
+ * Тема < 6.1: `2 * mobilePopupTopPadding`.
129
+ * Тема ≥ 6.1: `2 * mobilePopupPositionY + 2 * mobilePopupPaddingSmall` (size small).
130
+ */
131
+ static get sideMenuNotificationsMobilePopupHeightOffset(): string;
129
132
  }
130
133
  export declare const REACT_UI_SIDE_MENU_THEME_KEY = "__IS_REACT_UI_SIDE_MENU_THEME__";
131
134
  export declare const markAsSideMenuTheme: <T extends object>(theme: T) => T;
@@ -1,7 +1,7 @@
1
1
  import { __extends } from "tslib";
2
2
  import * as colors from '@skbkontur/colors/tokens-default/light';
3
3
  import { BasicThemeClassForExtension } from '@skbkontur/react-ui/internal/themes/BasicTheme';
4
- import { exposeGetters } from '@skbkontur/react-ui/lib/theming/ThemeHelpers';
4
+ import { exposeGetters, isThemeGTE } from '@skbkontur/react-ui/lib/theming/ThemeHelpers';
5
5
  import warning from 'warning';
6
6
  var SideMenuTheme = /** @class */ (function (_super) {
7
7
  __extends(SideMenuTheme, _super);
@@ -15,7 +15,7 @@ var SideMenuTheme = /** @class */ (function (_super) {
15
15
  return this._sideMenuProductColor;
16
16
  },
17
17
  set: function (value) {
18
- warning('[SideMenuTheme]: sideMenuProductColor is deprecated. Use @skbkontur/colors or theme variable `sideMenuMarkerBg` instead');
18
+ warning(false, '[SideMenuTheme]: sideMenuProductColor is deprecated. Use @skbkontur/colors or theme variable `sideMenuMarkerBg` instead');
19
19
  this._sideMenuProductColor = value;
20
20
  },
21
21
  enumerable: false,
@@ -91,13 +91,34 @@ var SideMenuTheme = /** @class */ (function (_super) {
91
91
  enumerable: false,
92
92
  configurable: true
93
93
  });
94
+ Object.defineProperty(SideMenuTheme, "sideMenuNotificationsMobilePopupHeightOffset", {
95
+ /**
96
+ * CSS-выражение для вычитания из 100vh на mobile (отступы MobilePopup `@skbkontur/react-ui`).
97
+ *
98
+ * Тема < 6.1: `2 * mobilePopupTopPadding`.
99
+ * Тема ≥ 6.1: `2 * mobilePopupPositionY + 2 * mobilePopupPaddingSmall` (size small).
100
+ */
101
+ get: function () {
102
+ var _a, _b;
103
+ if (isThemeGTE(this, '6.1')) {
104
+ var theme = this;
105
+ var positionY = (_a = theme.mobilePopupPositionY) !== null && _a !== void 0 ? _a : '16px';
106
+ var paddingSmall = (_b = theme.mobilePopupPaddingSmall) !== null && _b !== void 0 ? _b : '6px';
107
+ // Внешние скобки обязательны: иначе в `calc(100vh - A + B)` B прибавится, а не вычтется.
108
+ return "((2 * ".concat(positionY, ") + (2 * ").concat(paddingSmall, "))");
109
+ }
110
+ return "(2 * ".concat(this.mobilePopupTopPadding, ")");
111
+ },
112
+ enumerable: false,
113
+ configurable: true
114
+ });
94
115
  // #region SideMenu
95
116
  SideMenuTheme.sideMenuWidth = '232px';
96
117
  SideMenuTheme.sideMenuWidthTouchScreen = '328px';
97
118
  SideMenuTheme.sideMenuWidthCollapsed = '72px';
98
119
  SideMenuTheme.sideMenuMarginX = '16px';
99
120
  SideMenuTheme.sideMenuBg = colors.surfaceLow;
100
- SideMenuTheme.sideMenuBgHover = colors.shapeOtherNeutralFaintSolid;
121
+ SideMenuTheme.sideMenuBgHover = colors.shapeFaintNeutralSolid;
101
122
  SideMenuTheme.sideMenuBoxShadow = "\n 4px 0 12px rgba(0, 0, 0, 0.08),\n 12px 0 32px rgba(0, 0, 0, 0.04),\n 16px 0 40px rgba(0, 0, 0, 0.04)\n ";
102
123
  SideMenuTheme.sideMenuLineHeight = '20px';
103
124
  SideMenuTheme.sideMenuLineHeightLarge = '22px';
@@ -130,18 +151,16 @@ var SideMenuTheme = /** @class */ (function (_super) {
130
151
  // #region Footer
131
152
  SideMenuTheme.sideMenuFooterPaddingTop = '8px';
132
153
  SideMenuTheme.sideMenuFooterPaddingBottom = '24px';
133
- SideMenuTheme.sideMenuCollapseToggleSize = '40px';
134
154
  // #endregion
135
155
  // #region Item
136
156
  SideMenuTheme.sideMenuItemBorderRadius = '8px';
137
- SideMenuTheme.sideMenuItemBgHover = colors.shapeOtherBacklessHover;
157
+ SideMenuTheme.sideMenuItemBgHover = colors.shapeOtherBacklessAlphaHover;
138
158
  SideMenuTheme.sideMenuItemBgActive = colors.shapeOtherBase;
139
- SideMenuTheme.sideMenuItemBgPressed = colors.shapeOtherBacklessPressed;
140
159
  SideMenuTheme.sideMenuItemColor = colors.textNeutralHeavy;
141
160
  SideMenuTheme.sideMenuItemColorDisabled = colors.textNeutralFaint;
142
161
  SideMenuTheme.sideMenuItemBoxShadowColorFocus = colors.lineAccentBold;
143
162
  SideMenuTheme.sideMenuItemNestedPaddingLeft = '16px';
144
- SideMenuTheme.sideMenuSubItemWithSeparatedSubMenuBgHover = colors.shapeOtherBacklessHover;
163
+ SideMenuTheme.sideMenuSubItemWithSeparatedSubMenuBgHover = colors.shapeOtherBacklessAlphaHover;
145
164
  SideMenuTheme.sideMenuSubItemWithSeparatedSubMenuBgActive = colors.shapeFaintNeutralAlpha;
146
165
  // #endregion
147
166
  // #region ItemContent
@@ -155,8 +174,6 @@ var SideMenuTheme = /** @class */ (function (_super) {
155
174
  SideMenuTheme.sideMenuSubItemContentPaddingY = '4px';
156
175
  SideMenuTheme.sideMenuSubItemContentPaddingYLarge = '5px';
157
176
  SideMenuTheme.sideMenuSubItemContentPaddingYTouchScreen = '9px';
158
- SideMenuTheme.sideMenuSubItemContentPaddingYDropdown = '6px';
159
- SideMenuTheme.sideMenuSubItemContentPaddingXDropdown = '8px';
160
177
  // #endregion
161
178
  // #region Icon
162
179
  SideMenuTheme.sideMenuIconSize = '24';
@@ -1,6 +1,7 @@
1
1
  import { __values } from "tslib";
2
2
  import { isDarkTheme } from '@skbkontur/react-ui/lib/theming/ThemeHelpers';
3
3
  import { isFunction } from '@skbkontur/react-ui/lib/utils';
4
+ import warning from 'warning';
4
5
  import { SideMenuDarkThemeInternal } from '../../internal/themes/SideMenuDarkTheme.js';
5
6
  import { SideMenuThemeInternal, isSideMenuTheme, markAsSideMenuTheme } from '../../internal/themes/SideMenuTheme.js';
6
7
  import { memo } from '../utils/memo.js';
@@ -19,6 +20,9 @@ export var createSideMenuTheme = function (theme) {
19
20
  if (isSideMenuTheme(theme)) {
20
21
  return theme;
21
22
  }
23
+ if (Object.prototype.hasOwnProperty.call(theme, 'sideMenuProductColor')) {
24
+ warning(false, '[SideMenuTheme]: sideMenuProductColor is deprecated. Use @skbkontur/colors or theme variable `sideMenuMarkerBg` instead');
25
+ }
22
26
  var sideMenuTheme = Object.create(theme, Object.assign(Object.getOwnPropertyDescriptors(SideMenuThemeInternal), isDarkTheme(theme) ? Object.getOwnPropertyDescriptors(SideMenuDarkThemeInternal) : {}));
23
27
  var _loop_1 = function (key) {
24
28
  var descriptor = Object.getOwnPropertyDescriptor(sideMenuTheme, key);
@@ -3,4 +3,3 @@ export declare const isBrowser: boolean;
3
3
  export declare const isTouchDevice: () => boolean;
4
4
  export declare const isKonturIcon: (icon: React.ReactElement) => boolean;
5
5
  export declare const generateId: () => string;
6
- export declare const flattenChildren: (children: React.ReactNode) => React.ReactNode[];
@@ -1,4 +1,3 @@
1
- import { Children, isValidElement, Fragment } from 'react';
2
1
  export var isBrowser = typeof window !== 'undefined';
3
2
  export var isTouchDevice = function () {
4
3
  return isBrowser && ('ontouchstart' in window || matchMedia('(pointer: coarse)').matches);
@@ -9,11 +8,3 @@ export var isKonturIcon = function (icon) {
9
8
  export var generateId = function () {
10
9
  return Date.now().toString(36) + Math.random().toString(36).substr(2);
11
10
  };
12
- export var flattenChildren = function (children) {
13
- return Children.toArray(children).flatMap(function (child) {
14
- if (isValidElement(child) && child.type === Fragment) {
15
- return flattenChildren(child.props.children);
16
- }
17
- return [child];
18
- });
19
- };
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@skbkontur/side-menu",
3
- "version": "4.0.10-ddcb0.0",
3
+ "version": "4.1.0",
4
4
  "private": false,
5
5
  "license": "UNLICENSED",
6
6
  "author": "Kontur",
7
7
  "type": "module",
8
8
  "exports": {
9
9
  ".": "./index.js",
10
- "./unstable": "./unstable.js",
11
10
  "./lib/*": "./lib/*.js",
12
11
  "./package.json": "./package.json"
13
12
  },
@@ -27,10 +26,10 @@
27
26
  },
28
27
  "dependencies": {
29
28
  "@skbkontur/bell-widget-npm-loader": "^0.3.0",
30
- "@skbkontur/colors": "^2.1.7",
31
- "@skbkontur/empty-state": "^2.0.2",
29
+ "@skbkontur/colors": "^3.0.0",
30
+ "@skbkontur/empty-state": "^2.1.0",
32
31
  "@skbkontur/icons": "^2.0.0",
33
- "@skbkontur/react-ui-addons": "^6.0.6",
32
+ "@skbkontur/react-ui-addons": "^6.1.0",
34
33
  "@skbkontur/widget-consumer-react-utils": "^1.6.12",
35
34
  "tslib": "^2.8.0"
36
35
  },
@@ -0,0 +1,53 @@
1
+ import type { RefObject } from 'react';
2
+ import type { TreeNode } from './Tree.js';
3
+ import { Tree } from './Tree.js';
4
+ export declare const navigationAttribute = "data-navigation-id";
5
+ export declare const navigationAttributeForSeparatedMenu = "data-parent-navigation-id";
6
+ export declare const navigationAttributeBackButton = "data-navigation-back-button";
7
+ export interface NavigableElement {
8
+ setIsActive: (value: boolean) => void;
9
+ setIsOpened: (value: boolean) => void;
10
+ setIsNestedSubMenu: (value: boolean) => void;
11
+ setHasSubIcons: (value: boolean) => void;
12
+ setIsFirstLevelParentOfActiveMenuItem: (value: boolean) => void;
13
+ isSubMenu?: boolean;
14
+ }
15
+ interface MenuNavigationOptions {
16
+ rootRef: RefObject<HTMLDivElement> | null;
17
+ activeMenuItem?: string;
18
+ setActiveMenuItem: (id: string) => void;
19
+ isSeparatedMenu: boolean;
20
+ isSeparatedMenuShown: boolean;
21
+ setIsSeparatedMenuShown: (value: boolean) => void;
22
+ isOpened?: boolean;
23
+ isDesktop?: boolean;
24
+ isMobile?: boolean;
25
+ isCollapsable?: boolean;
26
+ }
27
+ export declare class MenuNavigation {
28
+ navigationTree: Tree | null;
29
+ activeMenuItem?: string;
30
+ isSeparatedMenuShown?: boolean;
31
+ setIsSeparatedMenuShown?: (value: boolean) => void;
32
+ activeMenuItemTreeNode?: TreeNode;
33
+ private readonly rootRef;
34
+ private readonly setActiveMenuItem?;
35
+ private isSeparatedMenu;
36
+ private readonly isOpened?;
37
+ private readonly isDesktop?;
38
+ private readonly isMobile?;
39
+ isCollapsable?: boolean;
40
+ private menuItemsIds;
41
+ constructor(options: MenuNavigationOptions);
42
+ updateNavigationTree(): void;
43
+ addValue(id: string, value: NavigableElement): void;
44
+ switchActiveMenuItem(id?: string, isButton?: boolean): void;
45
+ switchIsSeparatedMenu(value: boolean): void;
46
+ private setHighlightedFirstLevelMenuItemInCollapsedInnerMenu;
47
+ private getFirstLevelParent;
48
+ private openMenuItems;
49
+ private openAllParents;
50
+ private getParentId;
51
+ private switchVisibilityOfSeparatedMenu;
52
+ }
53
+ export {};
@@ -0,0 +1,194 @@
1
+ import { __values } from "tslib";
2
+ import { Tree } from './Tree.js';
3
+ var MENU_ROOT_ID = 'menu-root-id';
4
+ export var navigationAttribute = 'data-navigation-id';
5
+ export var navigationAttributeForSeparatedMenu = 'data-parent-navigation-id';
6
+ export var navigationAttributeBackButton = 'data-navigation-back-button';
7
+ var MenuNavigation = /** @class */ (function () {
8
+ function MenuNavigation(options) {
9
+ this.navigationTree = null;
10
+ this.menuItemsIds = '';
11
+ this.navigationTree = new Tree(MENU_ROOT_ID);
12
+ this.activeMenuItemTreeNode = this.navigationTree.find(options.activeMenuItem);
13
+ this.rootRef = options.rootRef;
14
+ this.activeMenuItem = options.activeMenuItem;
15
+ this.setActiveMenuItem = options.setActiveMenuItem;
16
+ this.isSeparatedMenu = options.isSeparatedMenu;
17
+ this.isSeparatedMenuShown = options.isSeparatedMenuShown;
18
+ this.setIsSeparatedMenuShown = options.setIsSeparatedMenuShown;
19
+ this.isOpened = options.isOpened;
20
+ this.isDesktop = options.isDesktop;
21
+ this.isMobile = options.isMobile;
22
+ this.isCollapsable = options.isCollapsable;
23
+ }
24
+ MenuNavigation.prototype.updateNavigationTree = function () {
25
+ var _this = this;
26
+ var _a;
27
+ if ((_a = this.rootRef) === null || _a === void 0 ? void 0 : _a.current) {
28
+ var menuItems = Array.from(this.rootRef.current.querySelectorAll("[".concat(navigationAttribute, "]"))).filter(function (item) { return !item.querySelector("[".concat(navigationAttributeBackButton, "]")); });
29
+ var newItemsIds = menuItems.map(function (node) { return node.getAttribute(navigationAttribute); }).join('');
30
+ if (this.menuItemsIds === newItemsIds) {
31
+ return;
32
+ }
33
+ this.menuItemsIds = newItemsIds;
34
+ menuItems.forEach(function (menuItem) {
35
+ var _a, _b, _c;
36
+ var id = menuItem.getAttribute(navigationAttribute);
37
+ var parentId = _this.getParentId(menuItem);
38
+ var oldValue = (_b = (_a = _this.navigationTree) === null || _a === void 0 ? void 0 : _a.find(id)) === null || _b === void 0 ? void 0 : _b.value;
39
+ (_c = _this.navigationTree) === null || _c === void 0 ? void 0 : _c.insert(parentId, id, oldValue);
40
+ });
41
+ }
42
+ };
43
+ MenuNavigation.prototype.addValue = function (id, value) {
44
+ var _a, _b, _c;
45
+ this.updateNavigationTree();
46
+ var foundTreeNode = (_a = this.navigationTree) === null || _a === void 0 ? void 0 : _a.find(id);
47
+ if (foundTreeNode) {
48
+ foundTreeNode.value = value;
49
+ }
50
+ if ((foundTreeNode === null || foundTreeNode === void 0 ? void 0 : foundTreeNode.parent) && foundTreeNode.parent.parent && foundTreeNode.parent.parent.id !== MENU_ROOT_ID) {
51
+ (_b = foundTreeNode.value) === null || _b === void 0 ? void 0 : _b.setIsNestedSubMenu(true);
52
+ }
53
+ if (this.isSeparatedMenu && (foundTreeNode === null || foundTreeNode === void 0 ? void 0 : foundTreeNode.hasChildren)) {
54
+ (_c = foundTreeNode.value) === null || _c === void 0 ? void 0 : _c.setHasSubIcons(true);
55
+ }
56
+ };
57
+ MenuNavigation.prototype.switchActiveMenuItem = function (id, isButton) {
58
+ var e_1, _a;
59
+ var _b, _c, _d, _e, _f;
60
+ if (!isButton) {
61
+ try {
62
+ for (var _g = __values(((_b = this.navigationTree) === null || _b === void 0 ? void 0 : _b.preOrderTraversal()) || []), _h = _g.next(); !_h.done; _h = _g.next()) {
63
+ var node = _h.value;
64
+ (_c = node.value) === null || _c === void 0 ? void 0 : _c.setIsActive(false);
65
+ }
66
+ }
67
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
68
+ finally {
69
+ try {
70
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
71
+ }
72
+ finally { if (e_1) throw e_1.error; }
73
+ }
74
+ }
75
+ var foundTreeNode = (_d = this.navigationTree) === null || _d === void 0 ? void 0 : _d.find(id);
76
+ var oldFirstLevelParent = this.getFirstLevelParent(this.activeMenuItemTreeNode);
77
+ var firstLevelParent = this.getFirstLevelParent(foundTreeNode);
78
+ var firstLevelParentChanged = oldFirstLevelParent !== firstLevelParent;
79
+ if (foundTreeNode) {
80
+ if (!isButton) {
81
+ this.activeMenuItem = foundTreeNode.id;
82
+ this.activeMenuItemTreeNode = foundTreeNode;
83
+ (_e = this.setActiveMenuItem) === null || _e === void 0 ? void 0 : _e.call(this, foundTreeNode.id);
84
+ this.setHighlightedFirstLevelMenuItemInCollapsedInnerMenu(firstLevelParent);
85
+ (_f = foundTreeNode.value) === null || _f === void 0 ? void 0 : _f.setIsActive(true);
86
+ }
87
+ if (this.isSeparatedMenu) {
88
+ this.switchVisibilityOfSeparatedMenu();
89
+ }
90
+ this.openMenuItems(foundTreeNode, firstLevelParentChanged);
91
+ }
92
+ };
93
+ MenuNavigation.prototype.switchIsSeparatedMenu = function (value) {
94
+ this.isSeparatedMenu = value;
95
+ this.switchVisibilityOfSeparatedMenu();
96
+ };
97
+ MenuNavigation.prototype.setHighlightedFirstLevelMenuItemInCollapsedInnerMenu = function (firstLevelParent) {
98
+ var e_2, _a;
99
+ var _b, _c, _d;
100
+ try {
101
+ for (var _e = __values(((_b = this.navigationTree) === null || _b === void 0 ? void 0 : _b.preOrderTraversal()) || []), _f = _e.next(); !_f.done; _f = _e.next()) {
102
+ var node = _f.value;
103
+ (_c = node.value) === null || _c === void 0 ? void 0 : _c.setIsFirstLevelParentOfActiveMenuItem(false);
104
+ }
105
+ }
106
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
107
+ finally {
108
+ try {
109
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
110
+ }
111
+ finally { if (e_2) throw e_2.error; }
112
+ }
113
+ (_d = firstLevelParent === null || firstLevelParent === void 0 ? void 0 : firstLevelParent.value) === null || _d === void 0 ? void 0 : _d.setIsFirstLevelParentOfActiveMenuItem(true);
114
+ };
115
+ MenuNavigation.prototype.getFirstLevelParent = function (treeNode) {
116
+ if (!treeNode) {
117
+ return;
118
+ }
119
+ var parentTreeNode = treeNode.parent;
120
+ while (parentTreeNode) {
121
+ var foundNode = parentTreeNode.parent;
122
+ if ((foundNode === null || foundNode === void 0 ? void 0 : foundNode.id) === MENU_ROOT_ID) {
123
+ break;
124
+ }
125
+ parentTreeNode = foundNode;
126
+ }
127
+ return parentTreeNode;
128
+ };
129
+ MenuNavigation.prototype.openMenuItems = function (treeNode, firstLevelParentChanged) {
130
+ var e_3, _a;
131
+ var _b, _c, _d, _e;
132
+ if (!((_b = treeNode.value) === null || _b === void 0 ? void 0 : _b.isSubMenu) || firstLevelParentChanged) {
133
+ try {
134
+ for (var _f = __values(((_c = this.navigationTree) === null || _c === void 0 ? void 0 : _c.preOrderTraversal()) || []), _g = _f.next(); !_g.done; _g = _f.next()) {
135
+ var node = _g.value;
136
+ (_d = node.value) === null || _d === void 0 ? void 0 : _d.setIsOpened(false);
137
+ }
138
+ }
139
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
140
+ finally {
141
+ try {
142
+ if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
143
+ }
144
+ finally { if (e_3) throw e_3.error; }
145
+ }
146
+ }
147
+ if (treeNode.children.length > 0) {
148
+ (_e = treeNode.value) === null || _e === void 0 ? void 0 : _e.setIsOpened(true);
149
+ }
150
+ this.openAllParents(treeNode);
151
+ };
152
+ MenuNavigation.prototype.openAllParents = function (treeNode) {
153
+ var _a;
154
+ var parentTreeNode = treeNode.parent;
155
+ while (parentTreeNode && parentTreeNode.id !== MENU_ROOT_ID) {
156
+ (_a = parentTreeNode.value) === null || _a === void 0 ? void 0 : _a.setIsOpened(true);
157
+ parentTreeNode = parentTreeNode.parent;
158
+ }
159
+ };
160
+ MenuNavigation.prototype.getParentId = function (menuItem) {
161
+ var _a, _b, _c;
162
+ var parentElement;
163
+ var clickableElementSelector = "[".concat(navigationAttribute, "]");
164
+ var separatedMenuSelector = "[".concat(navigationAttributeForSeparatedMenu, "]");
165
+ parentElement = (_a = menuItem.parentElement) === null || _a === void 0 ? void 0 : _a.closest(clickableElementSelector);
166
+ if (!parentElement) {
167
+ var separatedMenu = menuItem.closest(separatedMenuSelector);
168
+ if (separatedMenu) {
169
+ var firstLevelMenuId = separatedMenu.getAttribute(navigationAttributeForSeparatedMenu);
170
+ parentElement = (_c = (_b = this.rootRef) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.querySelector("[".concat(navigationAttribute, "=\"").concat(firstLevelMenuId, "\"]"));
171
+ }
172
+ }
173
+ return (parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute(navigationAttribute)) || MENU_ROOT_ID;
174
+ };
175
+ MenuNavigation.prototype.switchVisibilityOfSeparatedMenu = function () {
176
+ var _a, _b, _c, _d, _e, _f;
177
+ if (!this.isSeparatedMenu) {
178
+ this.isSeparatedMenuShown = false;
179
+ return (_a = this.setIsSeparatedMenuShown) === null || _a === void 0 ? void 0 : _a.call(this, false);
180
+ }
181
+ var activeItemHasParent = (_c = (_b = this.activeMenuItemTreeNode) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.isSubMenu;
182
+ var activeMenuItemHasChildren = (_d = this.activeMenuItemTreeNode) === null || _d === void 0 ? void 0 : _d.hasChildren;
183
+ var isActive = activeItemHasParent || activeMenuItemHasChildren || false;
184
+ var isCollapsedInWideDesktop = !this.isOpened && this.isDesktop && !this.isCollapsable;
185
+ if (this.isMobile && !activeItemHasParent && this.isSeparatedMenuShown) {
186
+ this.isSeparatedMenuShown = false;
187
+ return (_e = this.setIsSeparatedMenuShown) === null || _e === void 0 ? void 0 : _e.call(this, false);
188
+ }
189
+ this.isSeparatedMenuShown = isActive && !isCollapsedInWideDesktop;
190
+ (_f = this.setIsSeparatedMenuShown) === null || _f === void 0 ? void 0 : _f.call(this, this.isSeparatedMenuShown);
191
+ };
192
+ return MenuNavigation;
193
+ }());
194
+ export { MenuNavigation };