@skbkontur/side-menu 5.0.0-beta.2 → 5.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/hooks/useIsoLayoutEffect.d.ts +2 -0
- package/hooks/useIsoLayoutEffect.js +3 -0
- package/hooks/useSideMenuReducer.d.ts +0 -1
- package/hooks/useSideMenuReducer.js +0 -3
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/internal/themes/SideMenuDarkTheme.js +0 -3
- package/internal/themes/SideMenuTheme.d.ts +0 -4
- package/internal/themes/SideMenuTheme.js +0 -4
- package/package.json +1 -1
- package/src/SideMenu/SideMenu.js +24 -45
- package/src/SideMenuContext.d.ts +0 -2
- package/src/SideMenuFooter/SideMenuFooter.js +13 -12
- package/src/SideMenuFooter/SideMenuFooter.styles.d.ts +1 -0
- package/src/SideMenuFooter/SideMenuFooter.styles.js +14 -11
- package/src/internal/ClickableElement.js +7 -15
- package/src/internal/CollapseToggle.js +7 -3
- package/src/internal/InnerSubMenu.js +1 -4
- package/src/internal/ItemContent/ItemContent.js +8 -5
- package/src/internal/ItemContent/ItemContent.styles.d.ts +1 -0
- package/src/internal/ItemContent/ItemContent.styles.js +6 -3
- package/src/internal/NarrowAccordionDropdown.d.ts +1 -2
- package/src/internal/NarrowAccordionDropdown.js +2 -2
- package/src/internal/SideMenuLogotype.js +3 -2
- package/src/locale/index.d.ts +4 -0
- package/src/locale/index.js +8 -0
- package/src/locale/locales/en.d.ts +2 -0
- package/src/locale/locales/en.js +4 -0
- package/src/locale/locales/ru.d.ts +2 -0
- package/src/locale/locales/ru.js +4 -0
- package/src/locale/types.d.ts +4 -0
- package/src/locale/types.js +1 -0
- package/src/state/reducer.js +0 -2
- package/src/state/selectors.d.ts +0 -1
- package/src/state/selectors.js +0 -3
- package/src/state/types.d.ts +0 -5
- package/src/state/types.js +0 -1
package/README.md
CHANGED
|
@@ -654,7 +654,6 @@ const persist = (value) => {
|
|
|
654
654
|
sideMenuCollapseToggleSizeLarge: string;
|
|
655
655
|
//#endregion
|
|
656
656
|
//#region RightBorder
|
|
657
|
-
sideMenuRightBorderWidth: string;
|
|
658
657
|
sideMenuRightBorderIconColor: string;
|
|
659
658
|
sideMenuRightBorderIconColorHover: string;
|
|
660
659
|
// #region BackButton (for Mobiles)
|
|
@@ -7,9 +7,6 @@ export function useSideMenuReducer(options) {
|
|
|
7
7
|
useEffect(function () {
|
|
8
8
|
dispatch({ type: 'SET_VIEWPORT', viewport: options.viewport });
|
|
9
9
|
}, [options.viewport]);
|
|
10
|
-
useEffect(function () {
|
|
11
|
-
dispatch({ type: 'SET_OPENED', open: options.isOpened });
|
|
12
|
-
}, [options.isOpened]);
|
|
13
10
|
useEffect(function () {
|
|
14
11
|
dispatch({ type: 'SET_SEPARATED_MENU', isSeparatedMenu: options.isSeparatedMenu });
|
|
15
12
|
}, [options.isSeparatedMenu]);
|
package/index.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export * from './src/SideMenuSubItemHeader/SideMenuSubItemHeader.js';
|
|
|
11
11
|
export * from './src/SideMenuDropdown/SideMenuDropdown.js';
|
|
12
12
|
export * from './src/SideMenuLink/SideMenuLink.js';
|
|
13
13
|
export * from './src/SideMenuSubLink/SideMenuSubLink.js';
|
|
14
|
+
export * from './src/locale/index.js';
|
|
14
15
|
export * from './lib/theming/ThemeTypes.js';
|
package/index.js
CHANGED
|
@@ -11,4 +11,5 @@ export * from './src/SideMenuSubItemHeader/SideMenuSubItemHeader.js';
|
|
|
11
11
|
export * from './src/SideMenuDropdown/SideMenuDropdown.js';
|
|
12
12
|
export * from './src/SideMenuLink/SideMenuLink.js';
|
|
13
13
|
export * from './src/SideMenuSubLink/SideMenuSubLink.js';
|
|
14
|
+
export * from './src/locale/index.js';
|
|
14
15
|
export * from './lib/theming/ThemeTypes.js';
|
|
@@ -10,7 +10,6 @@ var SideMenuDarkTheme = /** @class */ (function (_super) {
|
|
|
10
10
|
// #region SideMenu
|
|
11
11
|
SideMenuDarkTheme.sideMenuBg = colors.surfaceLow;
|
|
12
12
|
SideMenuDarkTheme.sideMenuBgHover = colors.shapeFaintNeutralSolid;
|
|
13
|
-
SideMenuDarkTheme.sideMenuBgPressed = colors.shapeFaintNeutralSolidPressed;
|
|
14
13
|
// #endregion
|
|
15
14
|
// #region Divider
|
|
16
15
|
SideMenuDarkTheme.sideMenuDividerBg = colors.lineNeutralFaint;
|
|
@@ -18,7 +17,6 @@ var SideMenuDarkTheme = /** @class */ (function (_super) {
|
|
|
18
17
|
// #region Item
|
|
19
18
|
SideMenuDarkTheme.sideMenuItemBgHover = colors.shapeOtherBacklessAlphaHover;
|
|
20
19
|
SideMenuDarkTheme.sideMenuItemBgActive = colors.shapeOtherBase;
|
|
21
|
-
SideMenuDarkTheme.sideMenuItemBgActivePressed = colors.shapeOtherBasePressed;
|
|
22
20
|
SideMenuDarkTheme.sideMenuItemBgPressed = colors.shapeOtherBacklessAlphaPressed;
|
|
23
21
|
SideMenuDarkTheme.sideMenuItemColor = colors.textNeutralHeavy;
|
|
24
22
|
SideMenuDarkTheme.sideMenuItemColorDisabled = colors.textNeutralFaint;
|
|
@@ -41,7 +39,6 @@ var SideMenuDarkTheme = /** @class */ (function (_super) {
|
|
|
41
39
|
// #region SeparatedSubMenu
|
|
42
40
|
SideMenuDarkTheme.sideMenuSeparatedSubMenuBg = colors.surfaceBase;
|
|
43
41
|
SideMenuDarkTheme.sideMenuSeparatedSubMenuBorderRightColor = colors.lineNeutralFaint;
|
|
44
|
-
SideMenuDarkTheme.sideMenuSeparatedSubMenuBoxShadowRadius = '40px';
|
|
45
42
|
// #endregion
|
|
46
43
|
// #region SubItemHeader
|
|
47
44
|
SideMenuDarkTheme.sideMenuSubItemHeaderColor = colors.textNeutralPale;
|
|
@@ -10,7 +10,6 @@ export declare class SideMenuTheme extends BasicThemeClassForExtension {
|
|
|
10
10
|
static sideMenuItemsMarginXCollapsedLarge: string;
|
|
11
11
|
static sideMenuBg: string;
|
|
12
12
|
static sideMenuBgHover: string;
|
|
13
|
-
static sideMenuBgPressed: string;
|
|
14
13
|
static sideMenuBoxShadow: string;
|
|
15
14
|
static sideMenuLineHeight: string;
|
|
16
15
|
static sideMenuLineHeightLarge: string;
|
|
@@ -60,7 +59,6 @@ export declare class SideMenuTheme extends BasicThemeClassForExtension {
|
|
|
60
59
|
static sideMenuItemPaddingRight: string;
|
|
61
60
|
static sideMenuItemBgHover: string;
|
|
62
61
|
static sideMenuItemBgActive: string;
|
|
63
|
-
static sideMenuItemBgActivePressed: string;
|
|
64
62
|
static sideMenuItemBgPressed: string;
|
|
65
63
|
static sideMenuItemColor: string;
|
|
66
64
|
static sideMenuItemColorDisabled: string;
|
|
@@ -146,7 +144,6 @@ export declare class SideMenuTheme extends BasicThemeClassForExtension {
|
|
|
146
144
|
static sideMenuSeparatedSubMenuBorderRightColor: string;
|
|
147
145
|
static sideMenuSeparatedSubMenuPaddingY: string;
|
|
148
146
|
static sideMenuSeparatedSubMenuPaddingX: string;
|
|
149
|
-
static sideMenuSeparatedSubMenuBoxShadowRadius: string;
|
|
150
147
|
static sideMenuSubItemHeaderFontSize: string;
|
|
151
148
|
static sideMenuSubItemHeaderColor: string;
|
|
152
149
|
static sideMenuSubItemHeaderPadding: string;
|
|
@@ -154,7 +151,6 @@ export declare class SideMenuTheme extends BasicThemeClassForExtension {
|
|
|
154
151
|
static sideMenuSubItemHeaderPaddingInSeparatedSubMenu: string;
|
|
155
152
|
static sideMenuSubItemHeaderFontSizeLargeInSeparatedSubMenu: string;
|
|
156
153
|
static sideMenuSubItemHeaderLineHeightLargeInSeparatedSubMenu: string;
|
|
157
|
-
static sideMenuRightBorderWidth: string;
|
|
158
154
|
static sideMenuRightBorderIconColor: string;
|
|
159
155
|
static sideMenuRightBorderIconColorHover: string;
|
|
160
156
|
static sideMenuBurgerColor: string;
|
|
@@ -136,7 +136,6 @@ var SideMenuTheme = /** @class */ (function (_super) {
|
|
|
136
136
|
SideMenuTheme.sideMenuItemsMarginXCollapsedLarge = '12px';
|
|
137
137
|
SideMenuTheme.sideMenuBg = colors.surfaceLow;
|
|
138
138
|
SideMenuTheme.sideMenuBgHover = colors.shapeFaintNeutralSolid;
|
|
139
|
-
SideMenuTheme.sideMenuBgPressed = colors.shapeFaintNeutralSolidPressed;
|
|
140
139
|
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 ";
|
|
141
140
|
SideMenuTheme.sideMenuLineHeight = '20px';
|
|
142
141
|
SideMenuTheme.sideMenuLineHeightLarge = '22px';
|
|
@@ -191,7 +190,6 @@ var SideMenuTheme = /** @class */ (function (_super) {
|
|
|
191
190
|
SideMenuTheme.sideMenuItemPaddingRight = '12px';
|
|
192
191
|
SideMenuTheme.sideMenuItemBgHover = colors.shapeOtherBacklessAlphaHover;
|
|
193
192
|
SideMenuTheme.sideMenuItemBgActive = colors.shapeOtherBase;
|
|
194
|
-
SideMenuTheme.sideMenuItemBgActivePressed = colors.shapeOtherBasePressed;
|
|
195
193
|
SideMenuTheme.sideMenuItemBgPressed = colors.shapeOtherBacklessAlphaPressed;
|
|
196
194
|
SideMenuTheme.sideMenuItemColor = colors.textNeutralHeavy;
|
|
197
195
|
SideMenuTheme.sideMenuItemColorDisabled = colors.textNeutralFaint;
|
|
@@ -280,7 +278,6 @@ var SideMenuTheme = /** @class */ (function (_super) {
|
|
|
280
278
|
SideMenuTheme.sideMenuSeparatedSubMenuBorderRightColor = colors.lineNeutralFaint;
|
|
281
279
|
SideMenuTheme.sideMenuSeparatedSubMenuPaddingY = '12px';
|
|
282
280
|
SideMenuTheme.sideMenuSeparatedSubMenuPaddingX = '8px';
|
|
283
|
-
SideMenuTheme.sideMenuSeparatedSubMenuBoxShadowRadius = '24px';
|
|
284
281
|
// #endregion
|
|
285
282
|
// #region SubItemHeader
|
|
286
283
|
SideMenuTheme.sideMenuSubItemHeaderFontSize = '12px';
|
|
@@ -292,7 +289,6 @@ var SideMenuTheme = /** @class */ (function (_super) {
|
|
|
292
289
|
SideMenuTheme.sideMenuSubItemHeaderLineHeightLargeInSeparatedSubMenu = '20px';
|
|
293
290
|
// #endregion
|
|
294
291
|
// #region RightBorder
|
|
295
|
-
SideMenuTheme.sideMenuRightBorderWidth = '16px';
|
|
296
292
|
SideMenuTheme.sideMenuRightBorderIconColor = colors.textNeutralFaint;
|
|
297
293
|
SideMenuTheme.sideMenuRightBorderIconColorHover = colors.textNeutralHeavy;
|
|
298
294
|
// #endregion
|
package/package.json
CHANGED
package/src/SideMenu/SideMenu.js
CHANGED
|
@@ -7,8 +7,9 @@ import { mergeRefs } from '@skbkontur/react-ui/lib/mergeRefs';
|
|
|
7
7
|
import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
|
|
8
8
|
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
9
9
|
import { LIGHT_THEME } from '@skbkontur/react-ui/lib/theming/themes/LightTheme';
|
|
10
|
-
import React, { forwardRef, useCallback, useContext, useEffect,
|
|
10
|
+
import React, { forwardRef, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
11
11
|
import { useAnimateOnMount } from '../../hooks/useAnimateOnMount.js';
|
|
12
|
+
import { useIsoLayoutEffect } from '../../hooks/useIsoLayoutEffect.js';
|
|
12
13
|
import { useSideMenuReducer } from '../../hooks/useSideMenuReducer.js';
|
|
13
14
|
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
14
15
|
import { flattenChildren, isTouchDevice } from '../../lib/utils/scripts.js';
|
|
@@ -43,7 +44,6 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
43
44
|
var sideMenuRef = useRef(null);
|
|
44
45
|
var containerRef = useRef(null);
|
|
45
46
|
var collapseToggleRef = useRef(null);
|
|
46
|
-
var contentWrapperRef = useRef(null);
|
|
47
47
|
var scrollContainerRef = useRef(null);
|
|
48
48
|
var _k = __read(useState(0), 2), itemIconsCount = _k[0], setItemIconsCount = _k[1];
|
|
49
49
|
var registerItemIcon = useCallback(function () {
|
|
@@ -85,11 +85,16 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
85
85
|
viewport = 'mobile';
|
|
86
86
|
}
|
|
87
87
|
var manual = isOpen !== undefined;
|
|
88
|
-
var initialIsOpen =
|
|
88
|
+
var initialIsOpen = !isNarrowDesktop && !isPinned;
|
|
89
89
|
// Собственное состояние нужно только без `isOpen`. В управляемом режиме видимое состояние —
|
|
90
90
|
// всегда проп: так оно не расходится с родителем и совпадает на сервере и на первой отрисовке.
|
|
91
91
|
var _m = __read(useState(isDesktop && initialIsOpen), 2), internalIsOpened = _m[0], setInternalIsOpened = _m[1];
|
|
92
92
|
var isOpened = manual ? !!isOpen : internalIsOpened;
|
|
93
|
+
useEffect(function () {
|
|
94
|
+
if (manual) {
|
|
95
|
+
setInternalIsOpened(!!isOpen);
|
|
96
|
+
}
|
|
97
|
+
}, [manual, isOpen]);
|
|
93
98
|
var _o = __read(useState(false), 2), isBeingTransitioned = _o[0], setIsBeingTransitioned = _o[1];
|
|
94
99
|
var _p = __read(useState(0), 2), headerHeight = _p[0], setHeaderHeight = _p[1];
|
|
95
100
|
var _q = __read(useState(0), 2), footerHeight = _q[0], setFooterHeight = _q[1];
|
|
@@ -98,21 +103,24 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
98
103
|
var isDesktopNarrow = isDesktopViewport && !isOpened;
|
|
99
104
|
var wasDesktopNarrow = useRef(isDesktopNarrow);
|
|
100
105
|
var _t = __read(useState(false), 2), isDesktopOpening = _t[0], setIsDesktopOpening = _t[1];
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
var justOpened = wasDesktopNarrow.current && isDesktopViewport && isOpened;
|
|
106
|
+
var justOpenedOnDesktop = wasDesktopNarrow.current && isDesktopViewport && isOpened;
|
|
107
|
+
if (wasDesktopNarrow.current !== isDesktopNarrow || (isDesktopOpening && !isDesktopViewport)) {
|
|
104
108
|
wasDesktopNarrow.current = isDesktopNarrow;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
setIsDesktopOpening(!!justOpenedOnDesktop);
|
|
110
|
+
}
|
|
111
|
+
useIsoLayoutEffect(function () {
|
|
112
|
+
var _a;
|
|
113
|
+
if (!isDesktopOpening) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
108
117
|
setIsDesktopOpening(false);
|
|
109
118
|
return;
|
|
110
119
|
}
|
|
111
|
-
setIsDesktopOpening(true);
|
|
112
120
|
// A width change can be interrupted by a resize or skipped by the browser.
|
|
113
121
|
var fallback = setTimeout(function () { return setIsDesktopOpening(false); }, transitionDuration + 50);
|
|
114
122
|
return function () { return clearTimeout(fallback); };
|
|
115
|
-
}, [
|
|
123
|
+
}, [isDesktopOpening]);
|
|
116
124
|
var handleContainerTransitionEnd = function (event) {
|
|
117
125
|
if (event.target === event.currentTarget && event.propertyName === 'width') {
|
|
118
126
|
setIsDesktopOpening(false);
|
|
@@ -129,7 +137,6 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
129
137
|
activeItem: activeItem,
|
|
130
138
|
isSeparatedMenu: isSeparatedMenu,
|
|
131
139
|
viewport: viewport,
|
|
132
|
-
isOpened: !!isOpened,
|
|
133
140
|
}), machineState = _u.state, machineDispatch = _u.dispatch;
|
|
134
141
|
var isSeparatedMenuShown = separatedShown(machineState);
|
|
135
142
|
// Lift state up: notify the parent only when the machine arrives at a new active id.
|
|
@@ -180,9 +187,8 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
180
187
|
clearTimeout((_a = timerScrollbar.current) !== null && _a !== void 0 ? _a : undefined);
|
|
181
188
|
timerScrollbar.current = setTimeout(function () {
|
|
182
189
|
var _a;
|
|
183
|
-
var contentWrapper = contentWrapperRef.current;
|
|
184
190
|
var scrollContainer = (_a = scrollContainerRef.current) === null || _a === void 0 ? void 0 : _a.inner;
|
|
185
|
-
if (!
|
|
191
|
+
if (!scrollContainer) {
|
|
186
192
|
return;
|
|
187
193
|
}
|
|
188
194
|
// Сравниваем с самим контейнером прокрутки: выступающее за обёртку содержимое
|
|
@@ -221,7 +227,7 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
221
227
|
if (!isDesktopViewport) {
|
|
222
228
|
return;
|
|
223
229
|
}
|
|
224
|
-
var defaultIsOpened =
|
|
230
|
+
var defaultIsOpened = !isNarrowDesktop && (manual || !isPinned);
|
|
225
231
|
// На широком десктопе меню может быть свёрнуто намеренно (например, сохранённый выбор пользователя),
|
|
226
232
|
// поэтому при монтировании не просим родителя его развернуть
|
|
227
233
|
if (manual && !isMountedRef.current && defaultIsOpened) {
|
|
@@ -289,7 +295,7 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
289
295
|
}, {
|
|
290
296
|
opacity: 0,
|
|
291
297
|
}), 2), shouldShowBackdrop = _v[0], backdropStyle = _v[1];
|
|
292
|
-
var contextValue =
|
|
298
|
+
var contextValue = {
|
|
293
299
|
isOpened: isOpened,
|
|
294
300
|
disableCollapsing: disableCollapsing,
|
|
295
301
|
toggleIsOpened: function () { return setIsCollapsedTabletAndMobile(!!isOpened); },
|
|
@@ -309,7 +315,6 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
309
315
|
setHasScrollBar: setHasScrollBar,
|
|
310
316
|
headerHeight: headerHeight,
|
|
311
317
|
setHeaderHeight: setHeaderHeight,
|
|
312
|
-
footerHeight: footerHeight,
|
|
313
318
|
setFooterHeight: setFooterHeight,
|
|
314
319
|
showScrollBar: showScrollBar,
|
|
315
320
|
sideMenuRef: sideMenuRef,
|
|
@@ -320,33 +325,7 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
320
325
|
dispatch: machineDispatch,
|
|
321
326
|
parentItemId: ROOT,
|
|
322
327
|
currentItemNestingLevel: 0,
|
|
323
|
-
}
|
|
324
|
-
isOpened,
|
|
325
|
-
disableCollapsing,
|
|
326
|
-
setIsCollapsedTabletAndMobile,
|
|
327
|
-
setMenuOpened,
|
|
328
|
-
isBeingTransitioned,
|
|
329
|
-
isDesktopOpening,
|
|
330
|
-
isSeparatedMenu,
|
|
331
|
-
size,
|
|
332
|
-
isDesktop,
|
|
333
|
-
isNarrowDesktop,
|
|
334
|
-
isTablet,
|
|
335
|
-
isMobile,
|
|
336
|
-
isTouchScreen,
|
|
337
|
-
scrollState,
|
|
338
|
-
setScrollState,
|
|
339
|
-
hasScrollBar,
|
|
340
|
-
setHasScrollBar,
|
|
341
|
-
headerHeight,
|
|
342
|
-
setHeaderHeight,
|
|
343
|
-
showScrollBar,
|
|
344
|
-
sideMenuRef,
|
|
345
|
-
hasItemIcons,
|
|
346
|
-
registerItemIcon,
|
|
347
|
-
machineState,
|
|
348
|
-
machineDispatch,
|
|
349
|
-
]);
|
|
328
|
+
};
|
|
350
329
|
return (React.createElement(SideMenuContext.Provider, { value: contextValue },
|
|
351
330
|
React.createElement(CollapseToggle, null),
|
|
352
331
|
(isOpened || isBeingTransitioned) && isTabletOrMobile && React.createElement("div", { style: { height: headerHeight } }),
|
|
@@ -378,7 +357,7 @@ var SideMenuInner = forwardRef(function (_a, ref) {
|
|
|
378
357
|
_e[styles.contentWrapperCollapsedTabletAndMobile()] = !isOpened && isTabletOrMobile,
|
|
379
358
|
_e[styles.contentWrapperOverContent(theme)] = isSideMenuOverContent,
|
|
380
359
|
_e[styles.contentWrapperWithSeparatedSubMenuMobile(theme)] = isSeparatedMenuShown && isMobile && (isOpened || isBeingTransitioned),
|
|
381
|
-
_e)),
|
|
360
|
+
_e)), style: {
|
|
382
361
|
'--side-menu-scroll-margin-top': "".concat(headerHeight, "px"),
|
|
383
362
|
'--side-menu-scroll-margin-bottom': "".concat(footerHeight, "px"),
|
|
384
363
|
} },
|
package/src/SideMenuContext.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export interface SideMenuContextType {
|
|
|
23
23
|
setHasScrollBar?: (hasScrollBar: boolean) => void;
|
|
24
24
|
headerHeight?: number;
|
|
25
25
|
setHeaderHeight?: (mobileHeaderHeight: number) => void;
|
|
26
|
-
footerHeight?: number;
|
|
27
26
|
setFooterHeight?: (footerHeight: number) => void;
|
|
28
27
|
showScrollBar?: showScrollBarType;
|
|
29
28
|
sideMenuRef?: RefObject<HTMLDivElement>;
|
|
@@ -35,7 +34,6 @@ export interface SideMenuContextType {
|
|
|
35
34
|
state: SideMenuState;
|
|
36
35
|
dispatch: (action: Action) => void;
|
|
37
36
|
parentItemId: string;
|
|
38
|
-
openDropdownCount?: number;
|
|
39
37
|
currentItemNestingLevel?: number;
|
|
40
38
|
closeParentDropdown?: () => void;
|
|
41
39
|
}
|
|
@@ -11,7 +11,7 @@ import { getStyles as getSideMenuStyles } from '../SideMenu/SideMenu.styles.js';
|
|
|
11
11
|
import { SideMenuContext } from '../SideMenuContext.js';
|
|
12
12
|
import { getStyles } from './SideMenuFooter.styles.js';
|
|
13
13
|
var SideMenuFooterInner = forwardRef(function (_a, ref) {
|
|
14
|
-
var _b, _c, _d;
|
|
14
|
+
var _b, _c, _d, _e;
|
|
15
15
|
var className = _a.className, children = _a.children, rest = __rest(_a, ["className", "children"]);
|
|
16
16
|
var context = useContext(SideMenuContext);
|
|
17
17
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
@@ -19,13 +19,13 @@ var SideMenuFooterInner = forwardRef(function (_a, ref) {
|
|
|
19
19
|
var styles = useStyles(getStyles);
|
|
20
20
|
var sideMenuStyles = useStyles(getSideMenuStyles);
|
|
21
21
|
var footerRef = useRef(null);
|
|
22
|
-
var
|
|
22
|
+
var _f = __read(useState(false), 2), isFixed = _f[0], setIsFixed = _f[1];
|
|
23
23
|
useEffect(function () {
|
|
24
24
|
var _a;
|
|
25
25
|
if (footerRef.current) {
|
|
26
26
|
(_a = context.setFooterHeight) === null || _a === void 0 ? void 0 : _a.call(context, getDOMRect(footerRef.current).height);
|
|
27
27
|
}
|
|
28
|
-
}, [children, context.isOpened, context.setFooterHeight]);
|
|
28
|
+
}, [children, context.isOpened, context.isDesktopOpening, context.setFooterHeight]);
|
|
29
29
|
var isTabletOrMobile = context.isTablet || context.isMobile;
|
|
30
30
|
var isLarge = context.size === 'large';
|
|
31
31
|
var showCollapseToggle = (context.isDesktop || context.isNarrowDesktop) && !context.disableCollapsing;
|
|
@@ -35,6 +35,7 @@ var SideMenuFooterInner = forwardRef(function (_a, ref) {
|
|
|
35
35
|
var useCollapsedMargins = !context.isOpened || isEmpty;
|
|
36
36
|
var trailingItem = showTrailingItem ? footerItems[footerItems.length - 1] : null;
|
|
37
37
|
var leadingItems = trailingItem ? footerItems.slice(0, -1) : footerItems;
|
|
38
|
+
var reserveTrailingOffset = context.isOpened && !isEmpty;
|
|
38
39
|
useEffect(function () {
|
|
39
40
|
setIsFixed(!!context.hasScrollBar && !(context.scrollState === 'bottom'));
|
|
40
41
|
}, [context.hasScrollBar, context.scrollState]);
|
|
@@ -49,15 +50,15 @@ var SideMenuFooterInner = forwardRef(function (_a, ref) {
|
|
|
49
50
|
_b[styles.rootTransitionedTabletAndMobile()] = context.isBeingTransitioned && isTabletOrMobile,
|
|
50
51
|
_b), className), ref: mergeRefs(footerRef, ref) }, rest),
|
|
51
52
|
leadingItems.length > 0 && React.createElement("ul", { className: cx(sideMenuStyles.list(), styles.list()) }, leadingItems),
|
|
52
|
-
(trailingItem || showCollapseToggle) && (React.createElement("div", { className: cx(styles.trailingRow()) },
|
|
53
|
-
trailingItem && (React.createElement("ul", { className: cx(sideMenuStyles.list(), styles.list(), styles.trailingItem(theme), (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
showCollapseToggle && (React.createElement("span", { ref: context.collapseToggleRef, className: cx(styles.collapseToggleSlot(theme), (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
(trailingItem || showCollapseToggle) && (React.createElement("div", { className: cx(styles.trailingRow(), (_c = {}, _c[styles.trailingRowEmpty()] = isEmpty, _c)) },
|
|
54
|
+
trailingItem && (React.createElement("ul", { className: cx(sideMenuStyles.list(), styles.list(), styles.trailingItem(theme), (_d = {},
|
|
55
|
+
_d[styles.trailingItemLarge(theme)] = isLarge,
|
|
56
|
+
_d)) }, trailingItem)),
|
|
57
|
+
showCollapseToggle && (React.createElement("span", { ref: context.collapseToggleRef, className: cx(styles.collapseToggleSlot(theme), (_e = {},
|
|
58
|
+
_e[styles.collapseToggleSlotOpened(theme)] = reserveTrailingOffset,
|
|
59
|
+
_e[styles.collapseToggleSlotLarge(theme)] = isLarge,
|
|
60
|
+
_e[styles.collapseToggleSlotOpenedLarge(theme)] = reserveTrailingOffset && isLarge,
|
|
61
|
+
_e)) }))))));
|
|
61
62
|
}
|
|
62
63
|
return null;
|
|
63
64
|
});
|
|
@@ -4,6 +4,7 @@ export declare const getStyles: import("../../lib/theming/ThemeHelpers.js").Styl
|
|
|
4
4
|
rootLarge(t: SideMenuTheme): string;
|
|
5
5
|
list(): string;
|
|
6
6
|
trailingRow(): string;
|
|
7
|
+
trailingRowEmpty(): string;
|
|
7
8
|
trailingItem(t: SideMenuTheme): string;
|
|
8
9
|
trailingItemLarge(t: SideMenuTheme): string;
|
|
9
10
|
collapseToggleSlot(t: SideMenuTheme): string;
|
|
@@ -15,37 +15,40 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
15
15
|
trailingRow: function () {
|
|
16
16
|
return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: flex-end;\n min-width: 0;\n "], ["\n display: flex;\n align-items: center;\n justify-content: flex-end;\n min-width: 0;\n "])));
|
|
17
17
|
},
|
|
18
|
+
trailingRowEmpty: function () {
|
|
19
|
+
return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n justify-content: flex-start;\n "], ["\n justify-content: flex-start;\n "])));
|
|
20
|
+
},
|
|
18
21
|
trailingItem: function (t) {
|
|
19
|
-
return css(
|
|
22
|
+
return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n flex: 1 1 auto;\n min-width: 0;\n --side-menu-footer-trailing-reserved-width: calc(\n ", " + ", "\n );\n "], ["\n flex: 1 1 auto;\n min-width: 0;\n --side-menu-footer-trailing-reserved-width: calc(\n ", " + ", "\n );\n "])), t.sideMenuCollapseToggleSize, t.sideMenuCollapseToggleOffsetRight);
|
|
20
23
|
},
|
|
21
24
|
trailingItemLarge: function (t) {
|
|
22
|
-
return css(
|
|
25
|
+
return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n --side-menu-footer-trailing-reserved-width: calc(\n ", " + ", "\n );\n "], ["\n --side-menu-footer-trailing-reserved-width: calc(\n ", " + ", "\n );\n "])), t.sideMenuCollapseToggleSizeLarge, t.sideMenuCollapseToggleOffsetRight);
|
|
23
26
|
},
|
|
24
27
|
collapseToggleSlot: function (t) {
|
|
25
|
-
return css(
|
|
28
|
+
return css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n width: ", ";\n height: ", ";\n flex-shrink: 0;\n "], ["\n width: ", ";\n height: ", ";\n flex-shrink: 0;\n "])), t.sideMenuCollapseToggleSize, t.sideMenuCollapseToggleSize);
|
|
26
29
|
},
|
|
27
30
|
collapseToggleSlotOpened: function (t) {
|
|
28
|
-
return css(
|
|
31
|
+
return css(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n width: calc(", " + ", ");\n "], ["\n width: calc(", " + ", ");\n "])), t.sideMenuCollapseToggleSize, t.sideMenuCollapseToggleOffsetRight);
|
|
29
32
|
},
|
|
30
33
|
collapseToggleSlotLarge: function (t) {
|
|
31
|
-
return css(
|
|
34
|
+
return css(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n width: ", ";\n height: ", ";\n "], ["\n width: ", ";\n height: ", ";\n "])), t.sideMenuCollapseToggleSizeLarge, t.sideMenuCollapseToggleSizeLarge);
|
|
32
35
|
},
|
|
33
36
|
collapseToggleSlotOpenedLarge: function (t) {
|
|
34
|
-
return css(
|
|
37
|
+
return css(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n width: calc(", " + ", ");\n "], ["\n width: calc(", " + ", ");\n "])), t.sideMenuCollapseToggleSizeLarge, t.sideMenuCollapseToggleOffsetRight);
|
|
35
38
|
},
|
|
36
39
|
// Разделитель выравнивается по разделителю шапки, а не по краям пунктов
|
|
37
40
|
rootFixed: function (t) {
|
|
38
|
-
return css(
|
|
41
|
+
return css(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n &::before {\n content: '';\n position: absolute;\n top: 0;\n left: calc(", " - ", ");\n right: calc(", " - ", ");\n border-top: 1px solid ", ";\n }\n "], ["\n &::before {\n content: '';\n position: absolute;\n top: 0;\n left: calc(", " - ", ");\n right: calc(", " - ", ");\n border-top: 1px solid ", ";\n }\n "])), t.sideMenuMarginX, t.sideMenuItemsMarginX, t.sideMenuMarginX, t.sideMenuItemsMarginX, t.sideMenuFooterDividerColor);
|
|
39
42
|
},
|
|
40
43
|
rootFixedCollapsed: function (t) {
|
|
41
|
-
return css(
|
|
44
|
+
return css(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n &::before {\n left: calc(", " - ", ");\n right: calc(", " - ", ");\n }\n "], ["\n &::before {\n left: calc(", " - ", ");\n right: calc(", " - ", ");\n }\n "])), t.sideMenuMarginX, t.sideMenuItemsMarginXCollapsed, t.sideMenuMarginX, t.sideMenuItemsMarginXCollapsed);
|
|
42
45
|
},
|
|
43
46
|
rootFixedCollapsedLarge: function (t) {
|
|
44
|
-
return css(
|
|
47
|
+
return css(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n &::before {\n left: calc(", " - ", ");\n right: calc(", " - ", ");\n }\n "], ["\n &::before {\n left: calc(", " - ", ");\n right: calc(", " - ", ");\n }\n "])), t.sideMenuMarginX, t.sideMenuItemsMarginXCollapsedLarge, t.sideMenuMarginX, t.sideMenuItemsMarginXCollapsedLarge);
|
|
45
48
|
},
|
|
46
49
|
rootTransitionedTabletAndMobile: function () {
|
|
47
|
-
return css(
|
|
50
|
+
return css(templateObject_15 || (templateObject_15 = __makeTemplateObject(["\n position: static;\n "], ["\n position: static;\n "])));
|
|
48
51
|
},
|
|
49
52
|
});
|
|
50
53
|
});
|
|
51
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14;
|
|
54
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15;
|
|
@@ -150,13 +150,8 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
150
150
|
setIsAccordionOpen(false);
|
|
151
151
|
}
|
|
152
152
|
}, [isCollapsedAccordionSection]);
|
|
153
|
-
var toggleIsShown = function (lastElementInTheHierarchy) {
|
|
154
|
-
var _a;
|
|
155
|
-
if ((context.isMobile || context.isTablet) && lastElementInTheHierarchy) {
|
|
156
|
-
(_a = context.toggleIsOpened) === null || _a === void 0 ? void 0 : _a.call(context);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
153
|
var handleClick = function (e) {
|
|
154
|
+
var _a;
|
|
160
155
|
if (disabled) {
|
|
161
156
|
return;
|
|
162
157
|
}
|
|
@@ -167,7 +162,7 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
167
162
|
if (_isBackButton || _isDropdown) {
|
|
168
163
|
return;
|
|
169
164
|
}
|
|
170
|
-
var hasKids =
|
|
165
|
+
var hasKids = hasChildren(context.state, currentId);
|
|
171
166
|
// A leaf inside a NarrowAccordionDropdown should dismiss the popup.
|
|
172
167
|
if (!hasKids && context.closeParentDropdown) {
|
|
173
168
|
context.closeParentDropdown();
|
|
@@ -186,8 +181,9 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
186
181
|
}
|
|
187
182
|
else {
|
|
188
183
|
context.dispatch({ type: 'SELECT', id: currentId, isButton: !!isButton });
|
|
189
|
-
|
|
190
|
-
|
|
184
|
+
if (isTouchViewport && !hasKids) {
|
|
185
|
+
(_a = context.toggleIsOpened) === null || _a === void 0 ? void 0 : _a.call(context);
|
|
186
|
+
}
|
|
191
187
|
}
|
|
192
188
|
};
|
|
193
189
|
var handleFocus = function (e) {
|
|
@@ -236,9 +232,8 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
236
232
|
_c[styles.rootSubItemInSeparatedSubMenuActive(theme)] = isActive && context.isSeparatedMenu && _isSubMenu,
|
|
237
233
|
_c[styles.rootSubItemInDropdownActive(theme)] = isActive && !context.isSeparatedMenu && _isSubMenu && isDesktopCollapsedMode,
|
|
238
234
|
_c[styles.rootSubItemInDropdownButton(theme)] = !disabled && !context.isSeparatedMenu && _isSubMenu && isDesktopCollapsedMode,
|
|
239
|
-
_c), className), onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur, children: (React.createElement(ItemContent, { _isSubMenu: _isSubMenu, icon: _isSubMenu && !_isBackButton ? subMenuIcon : icon, isNestedSubMenu: isNestedSubMenu, caption: caption, subCaption: subCaption, marker: marker, _isBackButton: _isBackButton, _isDropdown: _isDropdown, _isAvatar: _isAvatar, disabled: disabled, noWrap: noWrap })), href: href,
|
|
240
|
-
//
|
|
241
|
-
// NOTE: Probably it can be calculated using Navigation Tree
|
|
235
|
+
_c), className), onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur, children: (React.createElement(ItemContent, { _isSubMenu: _isSubMenu, icon: _isSubMenu && !_isBackButton ? subMenuIcon : icon, isNestedSubMenu: isNestedSubMenu, caption: caption, subCaption: subCaption, marker: marker, _isBackButton: _isBackButton, _isDropdown: _isDropdown, _isAvatar: _isAvatar, disabled: disabled, noWrap: noWrap })), href: href, 'aria-current': isActive ? 'page' : undefined }, rest);
|
|
236
|
+
// Для SideMenu.SubItem и SideMenu.SubLink добавляем шаг отступа за каждый уровень после первого.
|
|
242
237
|
var currentItemNestingLevel = (_e = context.currentItemNestingLevel) !== null && _e !== void 0 ? _e : 0;
|
|
243
238
|
var nestingLevelPadding = {
|
|
244
239
|
paddingLeft: Math.max(0, currentItemNestingLevel - 1) * parseInt(theme.sideMenuItemNestedPaddingLeft),
|
|
@@ -258,9 +253,6 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
258
253
|
var clickableElement = (React.createElement(Tag, __assign({ state: isActive ? 'active' : undefined, style: nestingLevelPadding }, newProps, { ref: ref, disabled: !isNativeAnchor ? disabled : undefined, "aria-disabled": isNativeAnchor && disabled ? 'true' : undefined, tabIndex: isNativeAnchor && disabled ? -1 : undefined }, (children ? { 'aria-expanded': isExpanded, 'aria-controls': currentId || undefined } : {}))));
|
|
259
254
|
var clickableElementWithHint = (React.createElement(ClickableElementWithHint, { hint: hint === null ? null : (hint !== null && hint !== void 0 ? hint : caption), isOpened: context.isOpened || (_isSubMenu && (context.isSeparatedMenu || isDesktopCollapsedMode)) }, clickableElement));
|
|
260
255
|
var subMenuContextValue = useMemo(function () { return (__assign(__assign({ hasSeparatedSubMenu: hasSeparatedSubMenu }, context), { parentItemId: currentId, currentItemNestingLevel: currentItemNestingLevel + 1 })); }, [hasSeparatedSubMenu, context, currentId, currentItemNestingLevel]);
|
|
261
|
-
// При клике на айтем без детей закрывать дропдаун
|
|
262
|
-
// айтем должен оставаться активным и при разворачивании меню корректно показываться в списке подменю
|
|
263
|
-
// При клике на активный элемент с детьми, он должен закрыться
|
|
264
256
|
return (React.createElement(Component, (_d = { "data-tid": SideMenuDataTids.clickableElement }, _d[navigationAttribute] = currentId || undefined, _d),
|
|
265
257
|
isCollapsedAccordionSection && (React.createElement(NarrowAccordionDropdown, { caption: clickableElementWithHint, htmlId: currentId, disabled: disabled, onOpenChange: setIsAccordionOpen }, subMenuChildren)),
|
|
266
258
|
!isCollapsedAccordionSection && (React.createElement(React.Fragment, null,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
|
+
import { useLocaleForControl } from '@skbkontur/react-ui/lib/locale/useLocaleForControl';
|
|
2
3
|
import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
|
|
3
4
|
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
4
|
-
import React, { useContext,
|
|
5
|
+
import React, { useContext, useState } from 'react';
|
|
5
6
|
import ReactDOM from 'react-dom';
|
|
7
|
+
import { useIsoLayoutEffect } from '../../hooks/useIsoLayoutEffect.js';
|
|
6
8
|
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
7
9
|
import { SideMenuDataTids } from '../../SideMenuDataTids.js';
|
|
10
|
+
import { SideMenuLocaleHelper } from '../locale/index.js';
|
|
8
11
|
import { SideMenuContext } from '../SideMenuContext.js';
|
|
9
12
|
import { ClickableElementWithHint } from './ClickableElement.js';
|
|
10
13
|
import { getStyles } from './CollapseToggle.styles.js';
|
|
@@ -15,6 +18,7 @@ var SideMenuCollapseIcon = function () {
|
|
|
15
18
|
export var CollapseToggle = function () {
|
|
16
19
|
var _a;
|
|
17
20
|
var context = useContext(SideMenuContext);
|
|
21
|
+
var locale = useLocaleForControl('SideMenu', SideMenuLocaleHelper);
|
|
18
22
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
19
23
|
var styles = useStyles(getStyles);
|
|
20
24
|
var cx = useEmotion().cx;
|
|
@@ -22,11 +26,11 @@ export var CollapseToggle = function () {
|
|
|
22
26
|
var _b = __read(useState(false), 2), mounted = _b[0], setMounted = _b[1];
|
|
23
27
|
// The slot lives in the Footer, which mounts in the same commit. Refs are assigned
|
|
24
28
|
// before layout effects run, so after this effect the portal target is ready.
|
|
25
|
-
|
|
29
|
+
useIsoLayoutEffect(function () {
|
|
26
30
|
setMounted(true);
|
|
27
31
|
}, []);
|
|
28
32
|
var isOpened = !!context.isOpened;
|
|
29
|
-
var hintText = isOpened ?
|
|
33
|
+
var hintText = isOpened ? locale.collapseMenu : locale.expandMenu;
|
|
30
34
|
var handleClick = function () {
|
|
31
35
|
var _a;
|
|
32
36
|
(_a = context.setMenuOpened) === null || _a === void 0 ? void 0 : _a.call(context, !isOpened);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
|
|
2
|
-
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
3
2
|
import React, { forwardRef, useContext } from 'react';
|
|
4
|
-
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
5
3
|
import { getStyles as getSideMenuStyles } from '../SideMenu/SideMenu.styles.js';
|
|
6
4
|
import { SideMenuContext } from '../SideMenuContext.js';
|
|
7
5
|
/**
|
|
@@ -13,11 +11,10 @@ var InnerSubMenu = forwardRef(function (_a, ref) {
|
|
|
13
11
|
var _b;
|
|
14
12
|
var children = _a.children, htmlId = _a.htmlId, isOpened = _a.isOpened;
|
|
15
13
|
var context = useContext(SideMenuContext);
|
|
16
|
-
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
17
14
|
var sideMenuStyles = useStyles(getSideMenuStyles);
|
|
18
15
|
var cx = useEmotion().cx;
|
|
19
16
|
return (React.createElement("ul", { ref: ref, id: htmlId, className: cx(sideMenuStyles.list(), (_b = {},
|
|
20
|
-
_b[sideMenuStyles.hidden()] = !isOpened || !context.isOpened
|
|
17
|
+
_b[sideMenuStyles.hidden()] = !isOpened || !context.isOpened,
|
|
21
18
|
_b)) }, children));
|
|
22
19
|
});
|
|
23
20
|
InnerSubMenu.displayName = 'InnerSubMenu';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { __read, __values } from "tslib";
|
|
2
2
|
import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
|
|
3
3
|
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
4
|
-
import React, { forwardRef, useContext,
|
|
4
|
+
import React, { forwardRef, useContext, useRef, useState } from 'react';
|
|
5
5
|
import { flushSync } from 'react-dom';
|
|
6
|
+
import { useIsoLayoutEffect } from '../../../hooks/useIsoLayoutEffect.js';
|
|
6
7
|
import { getSideMenuTheme } from '../../../lib/theming/ThemeHelpers.js';
|
|
7
8
|
import { getStyles as getSideMenuStyles } from '../../SideMenu/SideMenu.styles.js';
|
|
8
9
|
import { SideMenuContext } from '../../SideMenuContext.js';
|
|
@@ -24,8 +25,9 @@ var getCaptionLineHeight = function (theme, isTouchScreen, _isSubMenu, size) {
|
|
|
24
25
|
};
|
|
25
26
|
var getFirstLetter = function (node) {
|
|
26
27
|
var e_1, _a;
|
|
28
|
+
var _b, _c;
|
|
27
29
|
if (typeof node === 'string' || typeof node === 'number') {
|
|
28
|
-
return String(node).trim()
|
|
30
|
+
return (_c = (_b = Array.from(String(node).trim())[0]) === null || _b === void 0 ? void 0 : _b.toUpperCase()) !== null && _c !== void 0 ? _c : '';
|
|
29
31
|
}
|
|
30
32
|
if (Array.isArray(node)) {
|
|
31
33
|
try {
|
|
@@ -65,12 +67,12 @@ var ItemContent = forwardRef(function (_a, ref) {
|
|
|
65
67
|
var isTopLevelItem = !_isSubMenu && !_isAvatar && !_isBackButton;
|
|
66
68
|
var registerItemIcon = context.registerItemIcon;
|
|
67
69
|
var countsAsItemIcon = isTopLevelItem && !!icon;
|
|
68
|
-
|
|
70
|
+
useIsoLayoutEffect(function () { return (countsAsItemIcon ? registerItemIcon === null || registerItemIcon === void 0 ? void 0 : registerItemIcon() : undefined); }, [countsAsItemIcon, registerItemIcon]);
|
|
69
71
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
70
72
|
var styles = useStyles(getStyles);
|
|
71
73
|
var sideMenuStyles = useStyles(getSideMenuStyles);
|
|
72
74
|
var cx = useEmotion().cx;
|
|
73
|
-
|
|
75
|
+
useIsoLayoutEffect(function () {
|
|
74
76
|
if (noWrap) {
|
|
75
77
|
setIsMultiline(false);
|
|
76
78
|
return;
|
|
@@ -132,7 +134,8 @@ var ItemContent = forwardRef(function (_a, ref) {
|
|
|
132
134
|
React.createElement("div", { className: cx(styles.textAndMarkerWrapper(), (_c = {},
|
|
133
135
|
_c[styles.textAndMarkerWrapperTopLevel(theme)] = !_isSubMenu,
|
|
134
136
|
_c[styles.textAndMarkerWrapperTopLevelLarge(theme)] = !_isSubMenu && isLarge,
|
|
135
|
-
_c[sideMenuStyles.hidden()] =
|
|
137
|
+
_c[sideMenuStyles.hidden()] = !context.isOpened && !_isSubMenu,
|
|
138
|
+
_c[styles.textAndMarkerWrapperOpening()] = context.isDesktopOpening,
|
|
136
139
|
_c)) },
|
|
137
140
|
React.createElement(Caption, { _isSubMenu: _isSubMenu, isNestedSubMenu: isNestedSubMenu, caption: caption, subCaption: subCaption, hasIcon: !!icon, hasMarker: !!marker, isMultiline: isMultiline, noWrap: noWrap, _isBackButton: _isBackButton, _isDropdown: _isDropdown, _isAvatar: _isAvatar, ref: textRef })),
|
|
138
141
|
marker && !disabled && (React.createElement(Marker, { _isSubMenu: _isSubMenu, marker: marker, isMultiline: isMultiline, isCollapsed: !context.isOpened }))));
|
|
@@ -11,6 +11,7 @@ export declare const getStyles: import("../../../lib/theming/ThemeHelpers.js").S
|
|
|
11
11
|
rootInDropdown(t: SideMenuTheme): string;
|
|
12
12
|
letterIcon(t: SideMenuTheme): string;
|
|
13
13
|
textAndMarkerWrapper(): string;
|
|
14
|
+
textAndMarkerWrapperOpening(): string;
|
|
14
15
|
textAndMarkerWrapperTopLevel(t: SideMenuTheme): string;
|
|
15
16
|
textAndMarkerWrapperTopLevelLarge(t: SideMenuTheme): string;
|
|
16
17
|
}>;
|
|
@@ -36,12 +36,15 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
36
36
|
textAndMarkerWrapper: function () {
|
|
37
37
|
return css(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n display: flex;\n flex-grow: 1;\n align-items: center;\n min-width: 0;\n "], ["\n display: flex;\n flex-grow: 1;\n align-items: center;\n min-width: 0;\n "])));
|
|
38
38
|
},
|
|
39
|
+
textAndMarkerWrapperOpening: function () {
|
|
40
|
+
return css(templateObject_12 || (templateObject_12 = __makeTemplateObject(["\n overflow: hidden;\n white-space: nowrap;\n "], ["\n overflow: hidden;\n white-space: nowrap;\n "])));
|
|
41
|
+
},
|
|
39
42
|
textAndMarkerWrapperTopLevel: function (t) {
|
|
40
|
-
return css(
|
|
43
|
+
return css(templateObject_13 || (templateObject_13 = __makeTemplateObject(["\n min-height: ", ";\n "], ["\n min-height: ", ";\n "])), t.sideMenuIconMinHeight);
|
|
41
44
|
},
|
|
42
45
|
textAndMarkerWrapperTopLevelLarge: function (t) {
|
|
43
|
-
return css(
|
|
46
|
+
return css(templateObject_14 || (templateObject_14 = __makeTemplateObject(["\n min-height: ", ";\n "], ["\n min-height: ", ";\n "])), t.sideMenuIconMinHeightLarge);
|
|
44
47
|
},
|
|
45
48
|
});
|
|
46
49
|
});
|
|
47
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13;
|
|
50
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14;
|
|
@@ -3,12 +3,11 @@ interface NarrowAccordionDropdownProps {
|
|
|
3
3
|
caption: React.ReactNode;
|
|
4
4
|
children?: React.ReactNode;
|
|
5
5
|
htmlId: string;
|
|
6
|
-
'aria-label'?: string;
|
|
7
6
|
disabled?: boolean;
|
|
8
7
|
onOpenChange?: (isOpen: boolean) => void;
|
|
9
8
|
}
|
|
10
9
|
export declare const NarrowAccordionDropdown: {
|
|
11
|
-
({ caption, children, htmlId,
|
|
10
|
+
({ caption, children, htmlId, disabled, onOpenChange, }: NarrowAccordionDropdownProps): JSX.Element;
|
|
12
11
|
displayName: string;
|
|
13
12
|
};
|
|
14
13
|
export {};
|
|
@@ -11,7 +11,7 @@ import { getStyles as getDropdownStyles } from '../SideMenuDropdown/SideMenuDrop
|
|
|
11
11
|
export var NarrowAccordionDropdown = function (_a) {
|
|
12
12
|
var _b;
|
|
13
13
|
var _c;
|
|
14
|
-
var caption = _a.caption, children = _a.children, htmlId = _a.htmlId,
|
|
14
|
+
var caption = _a.caption, children = _a.children, htmlId = _a.htmlId, disabled = _a.disabled, onOpenChange = _a.onOpenChange;
|
|
15
15
|
var context = useContext(SideMenuContext);
|
|
16
16
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
17
17
|
var sideMenuStyles = useStyles(getSideMenuStyles);
|
|
@@ -23,7 +23,7 @@ export var NarrowAccordionDropdown = function (_a) {
|
|
|
23
23
|
React.createElement(DropdownMenu, { ref: dropdownMenuRef, width: "100%", caption: React.createElement("div", { className: cx(dropdownStyles.label(theme), (_b = {},
|
|
24
24
|
_b[dropdownStyles.labelTouchScreen(theme)] = context.isTouchScreen,
|
|
25
25
|
_b[dropdownStyles.labelCollapsed()] = isMenuCollapsed,
|
|
26
|
-
_b)), onClick: disabled ? function (e) { return e.stopPropagation(); } : undefined }, caption), positions: ['right top', 'right middle', 'right bottom'], disableAnimations: true, popupMenuId: htmlId,
|
|
26
|
+
_b)), onClick: disabled ? function (e) { return e.stopPropagation(); } : undefined }, caption), positions: ['right top', 'right middle', 'right bottom'], disableAnimations: true, popupMenuId: htmlId, onOpen: function () { return onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(true); }, onClose: function () { return onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false); } },
|
|
27
27
|
React.createElement("ul", { className: cx(sideMenuStyles.list(), dropdownStyles.collapsedDropdownList(theme)), "data-tid": SideMenuDataTids.narrowAccordionDropdown },
|
|
28
28
|
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(); } }) }, children)))));
|
|
29
29
|
};
|
|
@@ -3,7 +3,8 @@ import { Logotype } from '@skbkontur/react-ui-addons/components/Logotype/Logotyp
|
|
|
3
3
|
import { mergeRefs } from '@skbkontur/react-ui/lib/mergeRefs';
|
|
4
4
|
import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
|
|
5
5
|
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
6
|
-
import React, { forwardRef, useContext,
|
|
6
|
+
import React, { forwardRef, useContext, useRef, useState } from 'react';
|
|
7
|
+
import { useIsoLayoutEffect } from '../../hooks/useIsoLayoutEffect.js';
|
|
7
8
|
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
8
9
|
import { SideMenuContext } from '../SideMenuContext.js';
|
|
9
10
|
import { Burger } from './Burger.js';
|
|
@@ -66,7 +67,7 @@ var SideMenuLogotype = forwardRef(function (_a, ref) {
|
|
|
66
67
|
var oneLineLogo = isTabletOrMobile ? getOneLineLogo(productLogo) : null;
|
|
67
68
|
var isOneLine = !!oneLineLogo && (!context.isOpened || oneLineLogoFits);
|
|
68
69
|
var shownProductLogo = isOneLine ? oneLineLogo : productLogo;
|
|
69
|
-
|
|
70
|
+
useIsoLayoutEffect(function () {
|
|
70
71
|
var root = rootRef.current;
|
|
71
72
|
if (root && isOneLine && context.isOpened && root.scrollWidth > root.clientWidth) {
|
|
72
73
|
setOneLineLogoFits(false);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import { LocaleHelper } from '@skbkontur/react-ui/lib/locale/LocaleHelper';
|
|
3
|
+
import { componentsLocales as en_GB } from './locales/en.js';
|
|
4
|
+
import { componentsLocales as ru_RU } from './locales/ru.js';
|
|
5
|
+
export var SideMenuLocaleHelper = new LocaleHelper({
|
|
6
|
+
ru_RU: ru_RU,
|
|
7
|
+
en_GB: en_GB,
|
|
8
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/state/reducer.js
CHANGED
|
@@ -263,8 +263,6 @@ export function sideMenuReducer(state, action) {
|
|
|
263
263
|
return setActiveItem(state, action.id);
|
|
264
264
|
case 'SET_VIEWPORT':
|
|
265
265
|
return action.viewport === state.viewport ? state : __assign(__assign({}, state), { viewport: action.viewport });
|
|
266
|
-
case 'SET_OPENED':
|
|
267
|
-
return action.open === state.isOpened ? state : __assign(__assign({}, state), { isOpened: action.open });
|
|
268
266
|
case 'SET_SEPARATED_MENU': {
|
|
269
267
|
if (action.isSeparatedMenu === state.isSeparatedMenu) {
|
|
270
268
|
return state;
|
package/src/state/selectors.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type SideMenuState } from './types.js';
|
|
2
2
|
export declare function isActive(state: SideMenuState, id: string): boolean;
|
|
3
|
-
export declare function isRegistered(state: SideMenuState, id: string): boolean;
|
|
4
3
|
export declare function isSubMenu(state: SideMenuState, id: string): boolean;
|
|
5
4
|
export declare function hasChildren(state: SideMenuState, id: string): boolean;
|
|
6
5
|
export declare function isExpanded(state: SideMenuState, id: string): boolean;
|
package/src/state/selectors.js
CHANGED
|
@@ -2,9 +2,6 @@ import { ROOT } from './types.js';
|
|
|
2
2
|
export function isActive(state, id) {
|
|
3
3
|
return state.activeItemId === id;
|
|
4
4
|
}
|
|
5
|
-
export function isRegistered(state, id) {
|
|
6
|
-
return state.parentOf.has(id);
|
|
7
|
-
}
|
|
8
5
|
export function isSubMenu(state, id) {
|
|
9
6
|
return state.subMenuIds.has(id);
|
|
10
7
|
}
|
package/src/state/types.d.ts
CHANGED
|
@@ -23,8 +23,6 @@ export interface SideMenuState {
|
|
|
23
23
|
separatedMenuShown: boolean;
|
|
24
24
|
/** resolved viewport, set via SET_VIEWPORT. */
|
|
25
25
|
viewport: Viewport;
|
|
26
|
-
/** resolved root open state, set via SET_OPENED. */
|
|
27
|
-
isOpened: boolean;
|
|
28
26
|
/** separated-menu mode, set via SET_SEPARATED_MENU. */
|
|
29
27
|
isSeparatedMenu: boolean;
|
|
30
28
|
}
|
|
@@ -49,9 +47,6 @@ export type Action = {
|
|
|
49
47
|
} | {
|
|
50
48
|
type: 'SET_VIEWPORT';
|
|
51
49
|
viewport: Viewport;
|
|
52
|
-
} | {
|
|
53
|
-
type: 'SET_OPENED';
|
|
54
|
-
open: boolean;
|
|
55
50
|
} | {
|
|
56
51
|
type: 'SET_SEPARATED_MENU';
|
|
57
52
|
isSeparatedMenu: boolean;
|