@skbkontur/side-menu 4.0.10-ddcb0.0 → 4.0.10

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 (81) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +11 -38
  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/SideMenuTheme.d.ts +7 -4
  8. package/internal/themes/SideMenuTheme.js +23 -6
  9. package/lib/theming/ThemeHelpers.js +4 -0
  10. package/lib/utils/scripts.d.ts +0 -1
  11. package/lib/utils/scripts.js +0 -9
  12. package/package.json +1 -2
  13. package/src/Navigation.d.ts +53 -0
  14. package/src/Navigation.js +194 -0
  15. package/src/SideMenu/SideMenu.d.ts +4 -7
  16. package/src/SideMenu/SideMenu.js +178 -148
  17. package/src/SideMenu/SideMenu.styles.js +2 -2
  18. package/src/SideMenuAvatar/SideMenuAvatar.js +2 -11
  19. package/src/SideMenuContext.d.ts +9 -16
  20. package/src/SideMenuContext.js +1 -6
  21. package/src/SideMenuDropdown/SideMenuDropdown.js +18 -11
  22. package/src/SideMenuDropdown/SideMenuDropdown.styles.js +3 -3
  23. package/src/SideMenuFooter/SideMenuFooter.js +3 -15
  24. package/src/SideMenuFooter/SideMenuFooter.styles.d.ts +0 -4
  25. package/src/SideMenuFooter/SideMenuFooter.styles.js +4 -16
  26. package/src/SideMenuHeader/SideMenuHeader.js +3 -4
  27. package/src/SideMenuNotifications/BellWidget.js +13 -6
  28. package/src/SideMenuNotifications/BellWidgetError.js +6 -3
  29. package/src/SideMenuNotifications/BellWidgetView.styles.d.ts +7 -4
  30. package/src/SideMenuNotifications/BellWidgetView.styles.js +20 -9
  31. package/src/SideMenuNotifications/utils/getWrapperHeightClass.d.ts +11 -0
  32. package/src/SideMenuNotifications/utils/getWrapperHeightClass.js +10 -0
  33. package/src/SideMenuSubItem/SideMenuSubItem.d.ts +1 -1
  34. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.js +0 -1
  35. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.d.ts +0 -1
  36. package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.js +2 -5
  37. package/src/SideMenuSubLink/SideMenuSubLink.d.ts +1 -1
  38. package/src/Tree.d.ts +17 -0
  39. package/src/Tree.js +135 -0
  40. package/src/internal/BackButton.d.ts +3 -1
  41. package/src/internal/BackButton.js +3 -4
  42. package/src/internal/ClickableElement.d.ts +1 -8
  43. package/src/internal/ClickableElement.js +67 -125
  44. package/src/internal/ClickableElement.styles.d.ts +0 -1
  45. package/src/internal/ClickableElement.styles.js +3 -6
  46. package/src/internal/ItemContent/Caption.d.ts +1 -1
  47. package/src/internal/ItemContent/Caption.js +26 -9
  48. package/src/internal/ItemContent/Icon.js +2 -3
  49. package/src/internal/ItemContent/Icon.styles.d.ts +0 -1
  50. package/src/internal/ItemContent/Icon.styles.js +3 -6
  51. package/src/internal/ItemContent/ItemContent.js +5 -17
  52. package/src/internal/ItemContent/ItemContent.styles.d.ts +0 -1
  53. package/src/internal/ItemContent/ItemContent.styles.js +4 -7
  54. package/src/internal/RightBorder.d.ts +9 -0
  55. package/src/internal/RightBorder.js +37 -0
  56. package/src/internal/{CollapseToggle.styles.d.ts → RightBorder.styles.d.ts} +1 -0
  57. package/src/internal/RightBorder.styles.js +14 -0
  58. package/src/internal/SeparatedSubMenu.js +9 -7
  59. package/src/internal/SeparatedSubMenu.styles.d.ts +3 -0
  60. package/src/internal/SeparatedSubMenu.styles.js +15 -6
  61. package/src/internal/SideMenuLogotype.js +8 -10
  62. package/src/internal/SubMenu.js +2 -3
  63. package/hooks/useNodeState.d.ts +0 -7
  64. package/hooks/useNodeState.js +0 -12
  65. package/hooks/useSideMenuReducer.d.ts +0 -13
  66. package/hooks/useSideMenuReducer.js +0 -23
  67. package/src/internal/CollapseToggle.d.ts +0 -1
  68. package/src/internal/CollapseToggle.js +0 -27
  69. package/src/internal/CollapseToggle.styles.js +0 -12
  70. package/src/internal/NarrowAccordionDropdown.d.ts +0 -13
  71. package/src/internal/NarrowAccordionDropdown.js +0 -34
  72. package/src/navigationAttributes.d.ts +0 -3
  73. package/src/navigationAttributes.js +0 -3
  74. package/src/state/reducer.d.ts +0 -2
  75. package/src/state/reducer.js +0 -258
  76. package/src/state/selectors.d.ts +0 -16
  77. package/src/state/selectors.js +0 -71
  78. package/src/state/types.d.ts +0 -59
  79. package/src/state/types.js +0 -17
  80. package/unstable.d.ts +0 -1
  81. package/unstable.js +0 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
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.0.10](/compare/@skbkontur/side-menu@4.0.9...@skbkontur/side-menu@4.0.10) (2026-09-16)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **SideMenu:** fit BellWidget error layout on small screens fd17bcd
12
+ * **SideMenu:** fit BellWidget height to MobilePopup on mobile dd8c638
13
+ * **SideMenu:** show deprecation warning on sideMenuProductColor var customization a53a9b9
14
+ * **SideMenu:** use isMobile for BellWidget width 19a4233
15
+ * **SideMenu:** use shapeBoldWarning for BellWidgetError icons ee5f199
16
+
17
+
18
+
19
+
20
+
6
21
  ## [4.0.9](/compare/@skbkontur/side-menu@4.0.8...@skbkontur/side-menu@4.0.9) (2026-07-23)
7
22
 
8
23
 
package/README.md CHANGED
@@ -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
+ };
@@ -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,6 +91,27 @@ 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';
@@ -130,13 +151,11 @@ 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
157
  SideMenuTheme.sideMenuItemBgHover = colors.shapeOtherBacklessHover;
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;
@@ -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.0.10",
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
  },
@@ -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 };
@@ -25,18 +25,15 @@ export interface SideMenuProps extends CommonProps {
25
25
  */
26
26
  isSeparatedMenu?: boolean;
27
27
  /**
28
- * Проп для закрепленного состояния (работает только на широких экранах)
29
- * @deprecated Используйте isOpen
28
+ * Закрепляет свёрнутое до иконок боковое меню на экране. Работает только на широких экранах.
30
29
  */
31
30
  isPinned?: boolean;
32
31
  /**
33
- * Коллбэк для закрепленного состояния (работает только на широких экранах)
34
- * @deprecated Используйте onClose
32
+ * Событие закреплённого состояния. Работает только на широких экранах.
35
33
  */
36
34
  onPinnedValueChange?: (isPinned: boolean) => void;
37
35
  /**
38
- * Заблокировать ручное сворачивание меню: скрывает кнопку-переключатель
39
- * в футере. Автоматическое поведение при смене разрешения сохраняется.
36
+ * Блокирует возможность сворачивать меню до иконок. Работает только на широких экранах.
40
37
  */
41
38
  disableCollapsing?: boolean;
42
39
  /**
@@ -98,7 +95,7 @@ interface SubComponents {
98
95
  SubLink: typeof SideMenuSubLink;
99
96
  __KONTUR_REACT_UI__: string;
100
97
  }
101
- export declare const transitionDuration = 200;
98
+ export declare const transitionDuration = 300;
102
99
  export declare const burgerTransitionDuration: number;
103
100
  export declare const SideMenu: React.ForwardRefExoticComponent<SideMenuProps & React.RefAttributes<HTMLElement>> & SubComponents;
104
101
  export {};