@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
@@ -5,7 +5,7 @@ import React, { forwardRef, useContext, useEffect, useRef } from 'react';
5
5
  import ReactDOM from 'react-dom';
6
6
  import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
7
7
  import { SideMenuDataTids } from '../../SideMenuDataTids.js';
8
- import { navigationAttributeForSeparatedMenu } from '../navigationAttributes.js';
8
+ import { navigationAttributeForSeparatedMenu } from '../Navigation.js';
9
9
  import { getStyles as getSideMenuStyles } from '../SideMenu/SideMenu.styles.js';
10
10
  import { SideMenuContext } from '../SideMenuContext.js';
11
11
  import { BackButton } from './BackButton.js';
@@ -17,7 +17,7 @@ import { getCustomStyles, getStyles } from './SeparatedSubMenu.styles.js';
17
17
  */
18
18
  var SeparatedSubMenu = forwardRef(function (_a, ref) {
19
19
  var _b, _c, _d;
20
- var _e, _f;
20
+ var _e, _f, _g;
21
21
  var children = _a.children, caption = _a.caption, htmlId = _a.htmlId, isOpened = _a.isOpened;
22
22
  var context = useContext(SideMenuContext);
23
23
  var scrollContainerRef = useRef(null);
@@ -30,20 +30,22 @@ var SeparatedSubMenu = forwardRef(function (_a, ref) {
30
30
  if (!context.isMobile) {
31
31
  return;
32
32
  }
33
- var timeoutId = setTimeout(function () {
33
+ setTimeout(function () {
34
34
  var _a, _b;
35
35
  if (isOpened) {
36
36
  (_a = context.setHasScrollBar) === null || _a === void 0 ? void 0 : _a.call(context, !!((_b = scrollContainerRef.current) === null || _b === void 0 ? void 0 : _b.hasScrollBar('y')));
37
37
  }
38
38
  }, 50);
39
- return function () { return clearTimeout(timeoutId); };
40
- }, [context.isMobile, context.setHasScrollBar, isOpened, context.state.activeItemId]);
41
- if (!((_e = context.sideMenuRef) === null || _e === void 0 ? void 0 : _e.current)) {
39
+ }, [(_e = context.navigation) === null || _e === void 0 ? void 0 : _e.activeMenuItem]);
40
+ if (!((_f = context.sideMenuRef) === null || _f === void 0 ? void 0 : _f.current)) {
42
41
  return null;
43
42
  }
44
43
  return ReactDOM.createPortal(React.createElement("div", (_b = { className: cx(sideMenuStyles.container(theme), styles.root(theme), (_c = {},
45
44
  _c[sideMenuStyles.containerTouchScreen(theme)] = context.isTouchScreen,
46
45
  _c[customStyles.rootMobile(context.headerHeight)] = context.isMobile,
46
+ _c[styles.rootDesktop()] = context.isDesktop,
47
+ _c[styles.rootTouchScreen(theme)] = context.isTouchScreen && context.isOpened && context.isCollapsable,
48
+ _c[styles.rootNarrowDesktop(theme)] = context.isCollapsable,
47
49
  _c[styles.rootTablet(theme)] = context.isTablet,
48
50
  _c[sideMenuStyles.hidden()] = !isOpened || (!context.isOpened && (context.isTablet || context.isMobile)),
49
51
  _c)), ref: ref, "data-tid": SideMenuDataTids.separatedSubMenu }, _b[navigationAttributeForSeparatedMenu] = htmlId, _b),
@@ -57,7 +59,7 @@ var SeparatedSubMenu = forwardRef(function (_a, ref) {
57
59
  _d[styles.contentWrapperMobile()] = context.isMobile,
58
60
  _d)) },
59
61
  context.isMobile && React.createElement(BackButton, { caption: caption, id: htmlId }),
60
- children))), (_f = context.sideMenuRef) === null || _f === void 0 ? void 0 : _f.current);
62
+ children))), (_g = context.sideMenuRef) === null || _g === void 0 ? void 0 : _g.current);
61
63
  });
62
64
  SeparatedSubMenu.displayName = 'SeparatedSubMenu';
63
65
  var SeparatedSubMenuWithStaticFields = Object.assign(SeparatedSubMenu, { __KONTUR_REACT_UI__: 'SeparatedSubMenu' });
@@ -2,6 +2,9 @@ import { type Emotion } from '../../lib/theming/ThemeHelpers.js';
2
2
  import type { SideMenuTheme } from '../../lib/theming/ThemeTypes.js';
3
3
  export declare const getStyles: import("../../lib/theming/ThemeHelpers.js").StylesGetter<{
4
4
  root(t: SideMenuTheme): string;
5
+ rootTouchScreen(t: SideMenuTheme): string;
6
+ rootNarrowDesktop(t: SideMenuTheme): string;
7
+ rootDesktop(): string;
5
8
  rootTablet(t: SideMenuTheme): string;
6
9
  contentWrapper(t: SideMenuTheme): string;
7
10
  contentWrapperMobile(): string;
@@ -4,16 +4,25 @@ export var getStyles = memoizeGetStyles(function (_a) {
4
4
  var css = _a.css;
5
5
  return ({
6
6
  root: function (t) {
7
- return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background: ", ";\n border-right: 1px solid ", ";\n z-index: 8000;\n "], ["\n background: ", ";\n border-right: 1px solid ", ";\n z-index: 8000;\n "])), t.sideMenuSeparatedSubMenuBg, t.sideMenuSeparatedSubMenuBorderRightColor);
7
+ return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n top: 0;\n background: ", ";\n left: 100%;\n justify-content: flex-start;\n border-right: 1px solid ", ";\n z-index: 8000;\n "], ["\n position: absolute;\n top: 0;\n background: ", ";\n left: 100%;\n justify-content: flex-start;\n border-right: 1px solid ", ";\n z-index: 8000;\n "])), t.sideMenuSeparatedSubMenuBg, t.sideMenuSeparatedSubMenuBorderRightColor);
8
+ },
9
+ rootTouchScreen: function (t) {
10
+ return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n left: ", ";\n z-index: -1;\n "], ["\n left: ", ";\n z-index: -1;\n "])), t.sideMenuWidthTouchScreen);
11
+ },
12
+ rootNarrowDesktop: function (t) {
13
+ return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n left: ", ";\n z-index: -1;\n "], ["\n left: ", ";\n z-index: -1;\n "])), t.sideMenuWidthCollapsed);
14
+ },
15
+ rootDesktop: function () {
16
+ return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n z-index: -1;\n "], ["\n z-index: -1;\n "])));
8
17
  },
9
18
  rootTablet: function (t) {
10
- return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n border-right: none;\n "], ["\n border-right: none;\n "])));
19
+ return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n box-shadow: ", ";\n clip-path: inset(0 -", " 0 0);\n border-right: none;\n "], ["\n box-shadow: ", ";\n clip-path: inset(0 -", " 0 0);\n border-right: none;\n "])), t.sideMenuBoxShadow, t.sideMenuSeparatedSubMenuBoxShadowRadius);
11
20
  },
12
21
  contentWrapper: function (t) {
13
- return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n padding: ", " ", ";\n "], ["\n padding: ", " ", ";\n "])), t.sideMenuSeparatedSubMenuPaddingY, t.sideMenuSeparatedSubMenuPaddingX);
22
+ return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding: ", " ", ";\n "], ["\n padding: ", " ", ";\n "])), t.sideMenuSeparatedSubMenuPaddingY, t.sideMenuSeparatedSubMenuPaddingX);
14
23
  },
15
24
  contentWrapperMobile: function () {
16
- return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n padding-top: 0;\n "], ["\n padding-top: 0;\n "])));
25
+ return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n padding-top: 0;\n "], ["\n padding-top: 0;\n "])));
17
26
  },
18
27
  });
19
28
  });
@@ -21,8 +30,8 @@ export var getCustomStyles = function (_a) {
21
30
  var css = _a.css;
22
31
  return ({
23
32
  rootMobile: function (headerHeight) {
24
- return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n position: absolute;\n height: calc(100vh - ", "px);\n left: 0;\n top: ", "px;\n "], ["\n position: absolute;\n height: calc(100vh - ", "px);\n left: 0;\n top: ", "px;\n "])), headerHeight, headerHeight);
33
+ return css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n height: calc(100vh - ", "px);\n left: 0;\n top: ", "px;\n "], ["\n height: calc(100vh - ", "px);\n left: 0;\n top: ", "px;\n "])), headerHeight, headerHeight);
25
34
  },
26
35
  });
27
36
  };
28
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
37
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
@@ -27,7 +27,7 @@ var getProductName = function (productLogo) {
27
27
  : 'kontur';
28
28
  };
29
29
  var getStaticIconPath = function (productName) {
30
- return "https://s.kontur.ru/common-v2/icons-products/".concat(productName, "/").concat(productName, "-").concat(parseInt(sideMenuLogotypeIconSize, 10), ".svg");
30
+ return "https://s.kontur.ru/common-v2/icons-products/".concat(productName, "/").concat(productName, "-").concat(parseInt(sideMenuLogotypeIconSize), ".svg");
31
31
  };
32
32
  /**
33
33
  * Логотип
@@ -47,22 +47,20 @@ var SideMenuLogotype = forwardRef(function (_a, ref) {
47
47
  var _f = __read(useState(false), 2), isSizeCalculated = _f[0], setIsSizeCalculated = _f[1];
48
48
  var _g = __read(useState(getStaticIconPath(productName)), 2), productIconUrl = _g[0], setProductIconUrl = _g[1];
49
49
  var isTabletOrMobile = context.isTablet || context.isMobile;
50
- var isDesktopCollapsedMode = !context.isOpened && (context.isDesktop || context.isNarrowDesktop);
51
- var sideMenuWidth = theme.sideMenuWidth, sideMenuMarginX = theme.sideMenuMarginX, sideMenuLogotypePaddingLeft = theme.sideMenuLogotypePaddingLeft;
52
50
  useEffect(function () {
53
51
  var _a, _b;
54
52
  var logotypeWidth = (_b = (_a = refLogotype.current) === null || _a === void 0 ? void 0 : _a.logotypeRef) === null || _b === void 0 ? void 0 : _b.clientWidth;
55
- var maxWidth = parseInt(sideMenuWidth, 10) -
56
- 2 * parseInt(sideMenuMarginX, 10) -
57
- parseInt(sideMenuLogotypePaddingLeft, 10) +
53
+ var maxWidth = parseInt(theme.sideMenuWidth) -
54
+ 2 * parseInt(theme.sideMenuMarginX) -
55
+ parseInt(theme.sideMenuLogotypePaddingLeft) +
58
56
  (withWidget ? -28 : 0);
59
57
  if (logotypeWidth && logotypeWidth > maxWidth && !rest.size) {
60
58
  setSize(24);
61
59
  }
62
60
  setIsSizeCalculated(true);
63
- }, [sideMenuWidth, sideMenuMarginX, sideMenuLogotypePaddingLeft, withWidget, rest.size]);
64
- var getWidget = function (withWidget, isCollapsedOnDesktop) {
65
- if (isCollapsedOnDesktop) {
61
+ }, []);
62
+ var getWidget = function (withWidget, isCollapsedInNarrowDesktop) {
63
+ if (isCollapsedInNarrowDesktop) {
66
64
  return false;
67
65
  }
68
66
  return withWidget;
@@ -81,7 +79,7 @@ var SideMenuLogotype = forwardRef(function (_a, ref) {
81
79
  _d[styles.logoWrapperHidden()] = isSizeCalculated && !context.isOpened && !isTabletOrMobile,
82
80
  _d)) },
83
81
  isTabletOrMobile && React.createElement(Burger, null),
84
- React.createElement(Logotype, __assign({ ref: refLogotype, size: size, productLogo: productLogo, konturLogo: konturLogo, withWidget: getWidget(withWidget, isDesktopCollapsedMode) }, rest)))));
82
+ React.createElement(Logotype, __assign({ ref: refLogotype, size: size, productLogo: productLogo, konturLogo: konturLogo, withWidget: getWidget(withWidget, !context.isOpened && context.isCollapsable) }, rest)))));
85
83
  });
86
84
  SideMenuLogotype.displayName = 'SideMenuLogotype';
87
85
  var SideMenuLogotypeWithStaticFields = Object.assign(SideMenuLogotype, { __KONTUR_REACT_UI__: 'SideMenuLogotype' });
@@ -1,6 +1,5 @@
1
1
  import React, { forwardRef, useContext } from 'react';
2
2
  import { SideMenuContext } from '../SideMenuContext.js';
3
- import { separatedShown } from '../state/selectors.js';
4
3
  import { InnerSubMenu } from './InnerSubMenu.js';
5
4
  import { NestedMenu } from './NestedMenu.js';
6
5
  import { SeparatedSubMenu } from './SeparatedSubMenu.js';
@@ -10,14 +9,14 @@ import { SeparatedSubMenu } from './SeparatedSubMenu.js';
10
9
  * @visibleName InnerSubMenu
11
10
  */
12
11
  var SubMenu = forwardRef(function (_a, ref) {
12
+ var _b;
13
13
  var children = _a.children, isOpened = _a.isOpened, isSubMenu = _a.isSubMenu, isSeparatedMenu = _a.isSeparatedMenu, caption = _a.caption, htmlId = _a.htmlId;
14
14
  var context = useContext(SideMenuContext);
15
- var isSeparatedMenuShown = separatedShown(context.state);
16
15
  if (isSubMenu) {
17
16
  return (React.createElement(NestedMenu, { ref: ref, htmlId: htmlId, isOpened: isOpened }, children));
18
17
  }
19
18
  if (isSeparatedMenu) {
20
- return (React.createElement(SeparatedSubMenu, { ref: ref, caption: caption, htmlId: htmlId, isOpened: isOpened && isSeparatedMenuShown }, children));
19
+ return (React.createElement(SeparatedSubMenu, { ref: ref, caption: caption, htmlId: htmlId, isOpened: isOpened && ((_b = context.navigation) === null || _b === void 0 ? void 0 : _b.isSeparatedMenuShown) }, children));
21
20
  }
22
21
  return (React.createElement(InnerSubMenu, { ref: ref, htmlId: htmlId, isOpened: isOpened }, children));
23
22
  });
@@ -1,7 +0,0 @@
1
- export interface NodeState {
2
- isActive: boolean;
3
- isExpanded: boolean;
4
- isNestedSubMenu: boolean;
5
- hasSeparatedSubMenu: boolean;
6
- }
7
- export declare function useNodeState(id: string): NodeState;
@@ -1,12 +0,0 @@
1
- import { useContext } from 'react';
2
- import { SideMenuContext } from '../src/SideMenuContext.js';
3
- import { hasSeparatedSubMenu, isActive, isExpanded, isNestedSubMenu } from '../src/state/selectors.js';
4
- export function useNodeState(id) {
5
- var state = useContext(SideMenuContext).state;
6
- return {
7
- isActive: isActive(state, id),
8
- isExpanded: isExpanded(state, id),
9
- isNestedSubMenu: isNestedSubMenu(state, id),
10
- hasSeparatedSubMenu: hasSeparatedSubMenu(state, id),
11
- };
12
- }
@@ -1,13 +0,0 @@
1
- import { type Dispatch } from 'react';
2
- import { type Action, type SideMenuState, type Viewport } from '../src/state/types.js';
3
- export interface UseSideMenuReducerOptions {
4
- activeItem?: string;
5
- isSeparatedMenu: boolean;
6
- viewport: Viewport;
7
- isOpened: boolean;
8
- }
9
- export interface UseSideMenuReducerResult {
10
- state: SideMenuState;
11
- dispatch: Dispatch<Action>;
12
- }
13
- export declare function useSideMenuReducer(options: UseSideMenuReducerOptions): UseSideMenuReducerResult;
@@ -1,23 +0,0 @@
1
- import { __read } from "tslib";
2
- import { useEffect, useReducer } from 'react';
3
- import { sideMenuReducer } from '../src/state/reducer.js';
4
- import { createInitialState } from '../src/state/types.js';
5
- export function useSideMenuReducer(options) {
6
- var _a = __read(useReducer(sideMenuReducer, undefined, createInitialState), 2), state = _a[0], dispatch = _a[1];
7
- useEffect(function () {
8
- dispatch({ type: 'SET_VIEWPORT', viewport: options.viewport });
9
- }, [options.viewport]);
10
- useEffect(function () {
11
- dispatch({ type: 'SET_OPENED', open: options.isOpened });
12
- }, [options.isOpened]);
13
- useEffect(function () {
14
- dispatch({ type: 'SET_SEPARATED_MENU', isSeparatedMenu: options.isSeparatedMenu });
15
- }, [options.isSeparatedMenu]);
16
- // The reducer defers an `activeItem` that names a not-yet-registered node and applies it
17
- // on REGISTER, so this effect only needs to react to the prop itself.
18
- useEffect(function () {
19
- var _a;
20
- dispatch({ type: 'SET_ACTIVE_ITEM', id: (_a = options.activeItem) !== null && _a !== void 0 ? _a : null });
21
- }, [options.activeItem]);
22
- return { state: state, dispatch: dispatch };
23
- }
@@ -1 +0,0 @@
1
- export declare const CollapseToggle: () => JSX.Element;
@@ -1,27 +0,0 @@
1
- import { Hint } from '@skbkontur/react-ui/components/Hint/Hint';
2
- import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
3
- import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
4
- import React, { useContext } from 'react';
5
- import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
6
- import { SideMenuDataTids } from '../../SideMenuDataTids.js';
7
- import { SideMenuContext } from '../SideMenuContext.js';
8
- import { getStyles } from './CollapseToggle.styles.js';
9
- var SideMenuCollapseIcon = function () {
10
- return (React.createElement("svg", { width: "24", height: "24", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
11
- React.createElement("path", { d: "M7.29951 3.00195L7.29951 17.002M3.69951 17.002H16.2995C17.7907 17.002 18.9995 15.6588 18.9995 14.002V6.00195C18.9995 4.3451 17.7907 3.00195 16.2995 3.00195H3.69951C2.20834 3.00195 0.999512 4.3451 0.999512 6.00195V14.002C0.999512 15.6588 2.20834 17.002 3.69951 17.002Z", stroke: "currentColor", strokeWidth: "1.5" })));
12
- };
13
- export var CollapseToggle = function () {
14
- var context = useContext(SideMenuContext);
15
- var theme = getSideMenuTheme(useContext(ThemeContext));
16
- var styles = useStyles(getStyles);
17
- var cx = useEmotion().cx;
18
- var isOpened = !!context.isOpened;
19
- var hintText = isOpened ? 'Свернуть меню' : 'Развернуть меню';
20
- var handleClick = function () {
21
- var _a;
22
- (_a = context.setMenuOpened) === null || _a === void 0 ? void 0 : _a.call(context, !isOpened);
23
- };
24
- return (React.createElement(Hint, { text: hintText, pos: 'right' },
25
- React.createElement("button", { type: 'button', className: cx(styles.root(theme)), "aria-label": hintText, "aria-expanded": isOpened, "data-tid": SideMenuDataTids.collapseToggle, onClick: handleClick },
26
- React.createElement(SideMenuCollapseIcon, null))));
27
- };
@@ -1,12 +0,0 @@
1
- import { __makeTemplateObject } from "tslib";
2
- import { resetButton } from '@skbkontur/react-ui/lib/styles/Mixins';
3
- import { memoizeGetStyles } from '../../lib/theming/ThemeHelpers.js';
4
- export var getStyles = memoizeGetStyles(function (_a) {
5
- var css = _a.css;
6
- return ({
7
- root: function (t) {
8
- return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", ";\n display: flex;\n align-items: center;\n justify-content: center;\n width: ", ";\n height: ", ";\n flex-shrink: 0;\n border-radius: ", ";\n color: ", ";\n cursor: pointer;\n\n &:hover {\n color: ", ";\n }\n\n &:focus-visible {\n box-shadow: ", ";\n }\n "], ["\n ", ";\n display: flex;\n align-items: center;\n justify-content: center;\n width: ", ";\n height: ", ";\n flex-shrink: 0;\n border-radius: ", ";\n color: ", ";\n cursor: pointer;\n\n &:hover {\n color: ", ";\n }\n\n &:focus-visible {\n box-shadow: ", ";\n }\n "])), resetButton(), t.sideMenuCollapseToggleSize, t.sideMenuCollapseToggleSize, t.sideMenuItemBorderRadius, t.sideMenuRightBorderIconColor, t.sideMenuRightBorderIconColorHover, t.sideMenuItemBoxShadowFocus);
9
- },
10
- });
11
- });
12
- var templateObject_1;
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- interface NarrowAccordionDropdownProps {
3
- caption: React.ReactNode;
4
- children?: React.ReactNode;
5
- htmlId: string;
6
- 'aria-label'?: string;
7
- childIdCounterRef?: React.MutableRefObject<number>;
8
- }
9
- export declare const NarrowAccordionDropdown: {
10
- ({ caption, children, htmlId, "aria-label": ariaLabel, childIdCounterRef, }: NarrowAccordionDropdownProps): JSX.Element;
11
- displayName: string;
12
- };
13
- export {};
@@ -1,34 +0,0 @@
1
- import { __assign } from "tslib";
2
- import { DropdownMenu } from '@skbkontur/react-ui/components/DropdownMenu';
3
- import { useStyles, useEmotion } from '@skbkontur/react-ui/lib/renderEnvironment';
4
- import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
5
- import React, { useContext, useRef } from 'react';
6
- import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
7
- import { SideMenuDataTids } from '../../SideMenuDataTids.js';
8
- import { getStyles as getSideMenuStyles } from '../SideMenu/SideMenu.styles.js';
9
- import { SideMenuContext } from '../SideMenuContext.js';
10
- import { getStyles as getDropdownStyles } from '../SideMenuDropdown/SideMenuDropdown.styles.js';
11
- export var NarrowAccordionDropdown = function (_a) {
12
- var _b;
13
- var _c;
14
- var caption = _a.caption, children = _a.children, htmlId = _a.htmlId, ariaLabel = _a["aria-label"], childIdCounterRef = _a.childIdCounterRef;
15
- var context = useContext(SideMenuContext);
16
- var theme = getSideMenuTheme(useContext(ThemeContext));
17
- var sideMenuStyles = useStyles(getSideMenuStyles);
18
- var cx = useEmotion().cx;
19
- var dropdownStyles = useStyles(getDropdownStyles);
20
- var dropdownMenuRef = useRef(null);
21
- var isMenuCollapsed = !context.isOpened && (context.isDesktop || context.isNarrowDesktop);
22
- return (React.createElement("div", { className: cx(dropdownStyles.wrapper()) },
23
- React.createElement(DropdownMenu, { ref: dropdownMenuRef, caption: React.createElement("div", { className: cx(dropdownStyles.label(theme), (_b = {},
24
- _b[dropdownStyles.labelTouchScreen(theme)] = context.isTouchScreen,
25
- _b[dropdownStyles.labelCollapsed()] = isMenuCollapsed,
26
- _b)) }, caption), positions: ['right top', 'right middle', 'right bottom'], disableAnimations: true, popupMenuId: htmlId, "aria-label": ariaLabel, onOpen: function () {
27
- if (childIdCounterRef) {
28
- childIdCounterRef.current = 0;
29
- }
30
- } },
31
- React.createElement("ul", { className: cx(sideMenuStyles.list()), "data-tid": SideMenuDataTids.narrowAccordionDropdown },
32
- React.createElement(SideMenuContext.Provider, { value: __assign(__assign({}, context), { hasSeparatedSubMenu: false, parentItemId: htmlId, currentItemNestingLevel: ((_c = context.currentItemNestingLevel) !== null && _c !== void 0 ? _c : 0) + 1, closeParentDropdown: function () { var _a; return (_a = dropdownMenuRef.current) === null || _a === void 0 ? void 0 : _a.close(); }, childIdCounterRef: childIdCounterRef !== null && childIdCounterRef !== void 0 ? childIdCounterRef : context.childIdCounterRef }) }, children)))));
33
- };
34
- NarrowAccordionDropdown.displayName = 'NarrowAccordionDropdown';
@@ -1,3 +0,0 @@
1
- export declare const navigationAttribute = "data-navigation-id";
2
- export declare const navigationAttributeForSeparatedMenu = "data-parent-navigation-id";
3
- export declare const navigationAttributeBackButton = "data-navigation-back-button";
@@ -1,3 +0,0 @@
1
- export var navigationAttribute = 'data-navigation-id';
2
- export var navigationAttributeForSeparatedMenu = 'data-parent-navigation-id';
3
- export var navigationAttributeBackButton = 'data-navigation-back-button';
@@ -1,2 +0,0 @@
1
- import { type Action, type SideMenuState } from './types.js';
2
- export declare function sideMenuReducer(state: SideMenuState, action: Action): SideMenuState;
@@ -1,258 +0,0 @@
1
- import { __assign, __read, __spreadArray, __values } from "tslib";
2
- import { isSubMenu, hasChildren, firstLevelParent, ancestors } from './selectors.js';
3
- import { ROOT } from './types.js';
4
- function getDescendantIds(state, id) {
5
- var e_1, _a;
6
- var result = [];
7
- var queue = [id];
8
- while (queue.length > 0) {
9
- var current = queue.shift();
10
- if (current === undefined) {
11
- continue;
12
- }
13
- var kids = state.childrenOf.get(current);
14
- if (kids) {
15
- try {
16
- for (var kids_1 = (e_1 = void 0, __values(kids)), kids_1_1 = kids_1.next(); !kids_1_1.done; kids_1_1 = kids_1.next()) {
17
- var kid = kids_1_1.value;
18
- result.push(kid);
19
- queue.push(kid);
20
- }
21
- }
22
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
23
- finally {
24
- try {
25
- if (kids_1_1 && !kids_1_1.done && (_a = kids_1.return)) _a.call(kids_1);
26
- }
27
- finally { if (e_1) throw e_1.error; }
28
- }
29
- }
30
- }
31
- return result;
32
- }
33
- function register(state, id, parentId, isSubMenuItem) {
34
- var _a;
35
- if (state.parentOf.has(id) || id === ROOT || id === parentId) {
36
- return state;
37
- }
38
- var parentOf = new Map(state.parentOf);
39
- parentOf.set(id, parentId);
40
- var childrenOf = new Map(state.childrenOf);
41
- var parentKids = new Set((_a = childrenOf.get(parentId)) !== null && _a !== void 0 ? _a : []);
42
- parentKids.add(id);
43
- childrenOf.set(parentId, parentKids);
44
- var subMenuIds = isSubMenuItem ? new Set(state.subMenuIds).add(id) : state.subMenuIds;
45
- var next = __assign(__assign({}, state), { parentOf: parentOf, childrenOf: childrenOf, subMenuIds: subMenuIds });
46
- // A controlled `activeItem` that named this node before it registered is applied now.
47
- if (next.pendingActiveItemId === id) {
48
- return __assign(__assign({}, select(next, id, false)), { pendingActiveItemId: null });
49
- }
50
- // Re-expand an ancestor of the active item that re-mounts (e.g. after the narrow
51
- // accordion dropdown closes and the menu is expanded back to the inline view). The
52
- // ancestor ids are captured at selection time in `activeAncestorIds` and survive the
53
- // unmount, so each ancestor re-opens as it registers and the path to the active item
54
- // is restored — including nested sub-subitems.
55
- if (next.activeAncestorIds.has(id) && !next.openNodeIds.has(id)) {
56
- return __assign(__assign({}, next), { openNodeIds: new Set(next.openNodeIds).add(id) });
57
- }
58
- return next;
59
- }
60
- function unregister(state, id) {
61
- var e_2, _a, e_3, _b, e_4, _c, e_5, _d;
62
- if (!state.parentOf.has(id) || id === ROOT) {
63
- return state;
64
- }
65
- var parentId = state.parentOf.get(id);
66
- if (parentId === undefined) {
67
- return state;
68
- }
69
- var idsToRemove = new Set(__spreadArray([id], __read(getDescendantIds(state, id)), false));
70
- var parentOf = new Map(state.parentOf);
71
- try {
72
- for (var idsToRemove_1 = __values(idsToRemove), idsToRemove_1_1 = idsToRemove_1.next(); !idsToRemove_1_1.done; idsToRemove_1_1 = idsToRemove_1.next()) {
73
- var rid = idsToRemove_1_1.value;
74
- parentOf.delete(rid);
75
- }
76
- }
77
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
78
- finally {
79
- try {
80
- if (idsToRemove_1_1 && !idsToRemove_1_1.done && (_a = idsToRemove_1.return)) _a.call(idsToRemove_1);
81
- }
82
- finally { if (e_2) throw e_2.error; }
83
- }
84
- var childrenOf = new Map(state.childrenOf);
85
- try {
86
- for (var idsToRemove_2 = __values(idsToRemove), idsToRemove_2_1 = idsToRemove_2.next(); !idsToRemove_2_1.done; idsToRemove_2_1 = idsToRemove_2.next()) {
87
- var rid = idsToRemove_2_1.value;
88
- childrenOf.delete(rid);
89
- }
90
- }
91
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
92
- finally {
93
- try {
94
- if (idsToRemove_2_1 && !idsToRemove_2_1.done && (_b = idsToRemove_2.return)) _b.call(idsToRemove_2);
95
- }
96
- finally { if (e_3) throw e_3.error; }
97
- }
98
- var parentKids = childrenOf.get(parentId);
99
- if (parentKids) {
100
- var next = new Set(parentKids);
101
- next.delete(id);
102
- childrenOf.set(parentId, next);
103
- }
104
- var subMenuIds = state.subMenuIds;
105
- try {
106
- for (var idsToRemove_3 = __values(idsToRemove), idsToRemove_3_1 = idsToRemove_3.next(); !idsToRemove_3_1.done; idsToRemove_3_1 = idsToRemove_3.next()) {
107
- var rid = idsToRemove_3_1.value;
108
- if (subMenuIds.has(rid)) {
109
- var next = new Set(subMenuIds);
110
- next.delete(rid);
111
- subMenuIds = next;
112
- }
113
- }
114
- }
115
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
116
- finally {
117
- try {
118
- if (idsToRemove_3_1 && !idsToRemove_3_1.done && (_c = idsToRemove_3.return)) _c.call(idsToRemove_3);
119
- }
120
- finally { if (e_4) throw e_4.error; }
121
- }
122
- var openNodeIds = state.openNodeIds;
123
- try {
124
- for (var idsToRemove_4 = __values(idsToRemove), idsToRemove_4_1 = idsToRemove_4.next(); !idsToRemove_4_1.done; idsToRemove_4_1 = idsToRemove_4.next()) {
125
- var rid = idsToRemove_4_1.value;
126
- if (openNodeIds.has(rid)) {
127
- var next = new Set(openNodeIds);
128
- next.delete(rid);
129
- openNodeIds = next;
130
- }
131
- }
132
- }
133
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
134
- finally {
135
- try {
136
- if (idsToRemove_4_1 && !idsToRemove_4_1.done && (_d = idsToRemove_4.return)) _d.call(idsToRemove_4);
137
- }
138
- finally { if (e_5) throw e_5.error; }
139
- }
140
- return __assign(__assign({}, state), { parentOf: parentOf, childrenOf: childrenOf, subMenuIds: subMenuIds, openNodeIds: openNodeIds });
141
- }
142
- /**
143
- * Mirrors the legacy `MenuNavigation.switchVisibilityOfSeparatedMenu`: the panel
144
- * shows when the active item has children or is itself a sub-item, except on
145
- * mobile navigating back to a top-level item while the panel is already shown
146
- * collapses it (the BackButton toggle). `prevShown` carries that statefulness.
147
- */
148
- function computeSeparatedShown(state, active, prevShown) {
149
- if (!state.isSeparatedMenu || active === null) {
150
- return false;
151
- }
152
- var activeHasParent = isSubMenu(state, active);
153
- var activeHasChildren = hasChildren(state, active);
154
- var shouldShow = activeHasParent || activeHasChildren;
155
- if (state.viewport === 'mobile' && !activeHasParent && prevShown) {
156
- return false;
157
- }
158
- return shouldShow;
159
- }
160
- /**
161
- * Core selection transition (replaces switchActiveMenuItem + openMenuItems).
162
- * `isButton` only suppresses the active-item change; expansion rules are identical.
163
- */
164
- function select(state, id, isButton) {
165
- var e_6, _a;
166
- if (!state.parentOf.has(id)) {
167
- return state;
168
- }
169
- var changed = firstLevelParent(state, state.activeItemId) !== firstLevelParent(state, id);
170
- var closeAll = !isSubMenu(state, id) || changed;
171
- var openNodeIds = closeAll ? new Set() : new Set(state.openNodeIds);
172
- if (hasChildren(state, id)) {
173
- openNodeIds.add(id);
174
- }
175
- try {
176
- for (var _b = __values(ancestors(state, id)), _c = _b.next(); !_c.done; _c = _b.next()) {
177
- var ancestor = _c.value;
178
- openNodeIds.add(ancestor);
179
- }
180
- }
181
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
182
- finally {
183
- try {
184
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
185
- }
186
- finally { if (e_6) throw e_6.error; }
187
- }
188
- var nextActive = isButton ? state.activeItemId : id;
189
- var next = __assign(__assign({}, state), { openNodeIds: openNodeIds, activeItemId: nextActive, activeFirstLevelParentId: nextActive !== null ? firstLevelParent(state, nextActive) : null, activeAncestorIds: nextActive !== null ? new Set(ancestors(state, nextActive)) : new Set() });
190
- return __assign(__assign({}, next), { separatedMenuShown: computeSeparatedShown(next, nextActive, state.separatedMenuShown) });
191
- }
192
- function closeNode(state, id) {
193
- var e_7, _a;
194
- if (!state.openNodeIds.has(id)) {
195
- return state;
196
- }
197
- var openNodeIds = new Set(state.openNodeIds);
198
- openNodeIds.delete(id);
199
- try {
200
- for (var _b = __values(getDescendantIds(state, id)), _c = _b.next(); !_c.done; _c = _b.next()) {
201
- var descendant = _c.value;
202
- openNodeIds.delete(descendant);
203
- }
204
- }
205
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
206
- finally {
207
- try {
208
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
209
- }
210
- finally { if (e_7) throw e_7.error; }
211
- }
212
- // Collapsing a top-level section in separated mode also hides the separated column,
213
- // so the root stops reserving the column's double-width space.
214
- if (state.isSeparatedMenu && state.parentOf.get(id) === ROOT) {
215
- return __assign(__assign({}, state), { openNodeIds: openNodeIds, separatedMenuShown: false });
216
- }
217
- return __assign(__assign({}, state), { openNodeIds: openNodeIds });
218
- }
219
- function setActiveItem(state, id) {
220
- if (id === null) {
221
- return __assign(__assign({}, state), { activeItemId: null, activeFirstLevelParentId: null, activeAncestorIds: new Set(), separatedMenuShown: false, pendingActiveItemId: null });
222
- }
223
- if (state.activeItemId === id) {
224
- return state;
225
- }
226
- // Node not registered yet (controlled prop set before mount): defer until it registers.
227
- if (!state.parentOf.has(id)) {
228
- return __assign(__assign({}, state), { pendingActiveItemId: id, activeAncestorIds: new Set() });
229
- }
230
- return __assign(__assign({}, select(state, id, false)), { pendingActiveItemId: null });
231
- }
232
- export function sideMenuReducer(state, action) {
233
- switch (action.type) {
234
- case 'REGISTER':
235
- return register(state, action.id, action.parentId, action.isSubMenu);
236
- case 'UNREGISTER':
237
- return unregister(state, action.id);
238
- case 'SELECT':
239
- return select(state, action.id, action.isButton);
240
- case 'CLOSE_NODE':
241
- return closeNode(state, action.id);
242
- case 'SET_ACTIVE_ITEM':
243
- return setActiveItem(state, action.id);
244
- case 'SET_VIEWPORT':
245
- return action.viewport === state.viewport ? state : __assign(__assign({}, state), { viewport: action.viewport });
246
- case 'SET_OPENED':
247
- return action.open === state.isOpened ? state : __assign(__assign({}, state), { isOpened: action.open });
248
- case 'SET_SEPARATED_MENU': {
249
- if (action.isSeparatedMenu === state.isSeparatedMenu) {
250
- return state;
251
- }
252
- var next = __assign(__assign({}, state), { isSeparatedMenu: action.isSeparatedMenu });
253
- return __assign(__assign({}, next), { separatedMenuShown: computeSeparatedShown(next, next.activeItemId, state.separatedMenuShown) });
254
- }
255
- default:
256
- return state;
257
- }
258
- }
@@ -1,16 +0,0 @@
1
- import { type SideMenuState } from './types.js';
2
- export declare function isActive(state: SideMenuState, id: string): boolean;
3
- export declare function isRegistered(state: SideMenuState, id: string): boolean;
4
- export declare function isSubMenu(state: SideMenuState, id: string): boolean;
5
- export declare function hasChildren(state: SideMenuState, id: string): boolean;
6
- export declare function isExpanded(state: SideMenuState, id: string): boolean;
7
- export declare function depth(state: SideMenuState, id: string): number;
8
- export declare function isNestedSubMenu(state: SideMenuState, id: string): boolean;
9
- export declare function ancestors(state: SideMenuState, id: string): string[];
10
- /**
11
- * The top-level (child-of-ROOT) ancestor of `id`, or null when `id` is itself
12
- * top-level or unknown. Mirrors the original `getFirstLevelParent` semantics.
13
- */
14
- export declare function firstLevelParent(state: SideMenuState, id: string | null): string | null;
15
- export declare function hasSeparatedSubMenu(state: SideMenuState, id: string): boolean;
16
- export declare function separatedShown(state: SideMenuState): boolean;