@skbkontur/side-menu 4.0.10 → 5.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -15
- package/README.md +38 -11
- package/SideMenuDataTids.d.ts +2 -1
- package/SideMenuDataTids.js +2 -1
- package/hooks/useMemoIcon.d.ts +1 -2
- package/hooks/useMemoIcon.js +0 -9
- package/hooks/useNodeState.d.ts +7 -0
- package/hooks/useNodeState.js +12 -0
- package/hooks/useSideMenuReducer.d.ts +13 -0
- package/hooks/useSideMenuReducer.js +23 -0
- package/internal/themes/SideMenuDarkTheme.js +4 -0
- package/internal/themes/SideMenuTheme.d.ts +7 -7
- package/internal/themes/SideMenuTheme.js +9 -23
- package/lib/theming/ThemeHelpers.js +0 -4
- package/lib/utils/scripts.d.ts +1 -0
- package/lib/utils/scripts.js +9 -0
- package/package.json +1 -1
- package/src/SideMenu/SideMenu.d.ts +7 -4
- package/src/SideMenu/SideMenu.js +165 -179
- package/src/SideMenu/SideMenu.styles.d.ts +1 -0
- package/src/SideMenu/SideMenu.styles.js +12 -6
- package/src/SideMenuAvatar/SideMenuAvatar.js +7 -2
- package/src/SideMenuContext.d.ts +21 -9
- package/src/SideMenuContext.js +6 -1
- package/src/SideMenuDropdown/SideMenuDropdown.js +19 -19
- package/src/SideMenuDropdown/SideMenuDropdown.styles.js +9 -8
- package/src/SideMenuFooter/SideMenuFooter.js +21 -3
- package/src/SideMenuFooter/SideMenuFooter.styles.d.ts +4 -0
- package/src/SideMenuFooter/SideMenuFooter.styles.js +16 -4
- package/src/SideMenuHeader/SideMenuHeader.js +6 -5
- package/src/SideMenuNotifications/BellWidget.js +6 -13
- package/src/SideMenuNotifications/BellWidgetError.js +3 -6
- package/src/SideMenuNotifications/BellWidgetView.styles.d.ts +4 -7
- package/src/SideMenuNotifications/BellWidgetView.styles.js +9 -20
- package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.js +1 -0
- package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.d.ts +1 -0
- package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.js +5 -2
- package/src/SideMenuSubLink/SideMenuSubLink.d.ts +1 -1
- package/src/internal/BackButton.d.ts +1 -3
- package/src/internal/BackButton.js +4 -3
- package/src/internal/ClickableElement.d.ts +18 -2
- package/src/internal/ClickableElement.js +190 -69
- package/src/internal/ClickableElement.styles.d.ts +4 -0
- package/src/internal/ClickableElement.styles.js +19 -7
- package/src/internal/CollapseToggle.d.ts +2 -0
- package/src/internal/CollapseToggle.js +40 -0
- package/src/internal/{RightBorder.styles.d.ts → CollapseToggle.styles.d.ts} +0 -1
- package/src/internal/CollapseToggle.styles.js +13 -0
- package/src/internal/ItemContent/Caption.d.ts +1 -1
- package/src/internal/ItemContent/Caption.js +9 -26
- package/src/internal/ItemContent/Icon.js +3 -2
- package/src/internal/ItemContent/Icon.styles.d.ts +1 -0
- package/src/internal/ItemContent/Icon.styles.js +6 -3
- package/src/internal/ItemContent/ItemContent.js +17 -5
- package/src/internal/ItemContent/ItemContent.styles.d.ts +1 -0
- package/src/internal/ItemContent/ItemContent.styles.js +7 -4
- package/src/internal/NarrowAccordionDropdown.d.ts +15 -0
- package/src/internal/NarrowAccordionDropdown.js +35 -0
- package/src/internal/SeparatedSubMenu.js +7 -9
- package/src/internal/SeparatedSubMenu.styles.d.ts +0 -3
- package/src/internal/SeparatedSubMenu.styles.js +6 -15
- package/src/internal/SideMenuLogotype.js +13 -11
- package/src/internal/SubMenu.js +3 -2
- package/src/navigationAttributes.d.ts +3 -0
- package/src/navigationAttributes.js +3 -0
- package/src/state/reducer.d.ts +2 -0
- package/src/state/reducer.js +258 -0
- package/src/state/selectors.d.ts +16 -0
- package/src/state/selectors.js +71 -0
- package/src/state/types.d.ts +59 -0
- package/src/state/types.js +17 -0
- package/src/Navigation.d.ts +0 -53
- package/src/Navigation.js +0 -194
- package/src/SideMenuNotifications/utils/getWrapperHeightClass.d.ts +0 -11
- package/src/SideMenuNotifications/utils/getWrapperHeightClass.js +0 -10
- package/src/Tree.d.ts +0 -17
- package/src/Tree.js +0 -135
- package/src/internal/RightBorder.d.ts +0 -9
- package/src/internal/RightBorder.js +0 -37
- package/src/internal/RightBorder.styles.js +0 -14
|
@@ -1,17 +1,85 @@
|
|
|
1
1
|
import { __assign, __read, __rest } from "tslib";
|
|
2
|
+
import { Hint } from '@skbkontur/react-ui/components/Hint/Hint';
|
|
2
3
|
import { useKeyListener } from '@skbkontur/react-ui/lib/events/keyListener';
|
|
3
4
|
import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
|
|
4
5
|
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
5
|
-
import React, { forwardRef, useContext, useEffect, useState } from 'react';
|
|
6
|
+
import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
7
|
import { useMemoIcon } from '../../hooks/useMemoIcon.js';
|
|
8
|
+
import { useNodeState } from '../../hooks/useNodeState.js';
|
|
7
9
|
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
8
10
|
import { generateId } from '../../lib/utils/scripts.js';
|
|
9
11
|
import { SideMenuDataTids } from '../../SideMenuDataTids.js';
|
|
10
|
-
import { navigationAttribute } from '../
|
|
12
|
+
import { navigationAttribute } from '../navigationAttributes.js';
|
|
11
13
|
import { SideMenuContext } from '../SideMenuContext.js';
|
|
14
|
+
import { hasChildren } from '../state/selectors.js';
|
|
12
15
|
import { getStyles } from './ClickableElement.styles.js';
|
|
13
16
|
import { ItemContent } from './ItemContent/ItemContent.js';
|
|
17
|
+
import { NarrowAccordionDropdown } from './NarrowAccordionDropdown.js';
|
|
14
18
|
import { SubMenu } from './SubMenu.js';
|
|
19
|
+
var ClickableElementWithHint = function (_a) {
|
|
20
|
+
var hint = _a.hint, isOpened = _a.isOpened, children = _a.children;
|
|
21
|
+
var _b = __read(useState(false), 2), hovered = _b[0], setHovered = _b[1];
|
|
22
|
+
var _c = __read(useState(false), 2), focused = _c[0], setFocused = _c[1];
|
|
23
|
+
var _d = __read(useState(false), 2), tabFocused = _d[0], setTabFocused = _d[1];
|
|
24
|
+
useEffect(function () {
|
|
25
|
+
var handleKeyDown = function (e) {
|
|
26
|
+
if (e.key === 'Tab') {
|
|
27
|
+
setTabFocused(true);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var handleBlur = function () {
|
|
31
|
+
setTabFocused(false);
|
|
32
|
+
};
|
|
33
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
34
|
+
window.addEventListener('blur', handleBlur);
|
|
35
|
+
return function () {
|
|
36
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
37
|
+
window.removeEventListener('blur', handleBlur);
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
var handleMouseEnter = useCallback(function () { return setHovered(true); }, []);
|
|
41
|
+
var handleMouseLeave = useCallback(function () { return setHovered(false); }, []);
|
|
42
|
+
var handleFocus = useCallback(function () {
|
|
43
|
+
setFocused(true);
|
|
44
|
+
}, []);
|
|
45
|
+
var handleBlur = useCallback(function () {
|
|
46
|
+
setFocused(false);
|
|
47
|
+
setTabFocused(false);
|
|
48
|
+
}, []);
|
|
49
|
+
if (hint === null || hint === undefined) {
|
|
50
|
+
return children;
|
|
51
|
+
}
|
|
52
|
+
if (isOpened) {
|
|
53
|
+
return children;
|
|
54
|
+
}
|
|
55
|
+
var shouldShow = hovered || (tabFocused && focused);
|
|
56
|
+
var childrenWithHandlers = React.cloneElement(children, {
|
|
57
|
+
onMouseEnter: function (e) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
(_b = (_a = children.props).onMouseEnter) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
60
|
+
handleMouseEnter();
|
|
61
|
+
},
|
|
62
|
+
onMouseLeave: function (e) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
(_b = (_a = children.props).onMouseLeave) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
65
|
+
handleMouseLeave();
|
|
66
|
+
},
|
|
67
|
+
onFocus: function (e) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
(_b = (_a = children.props).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
70
|
+
handleFocus();
|
|
71
|
+
},
|
|
72
|
+
onBlur: function (e) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
(_b = (_a = children.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
75
|
+
handleBlur();
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
if (!shouldShow) {
|
|
79
|
+
return (React.createElement(Hint, { text: null, pos: 'right', manual: true, opened: false }, childrenWithHandlers));
|
|
80
|
+
}
|
|
81
|
+
return (React.createElement(Hint, { text: hint, pos: 'right', manual: true, opened: true }, childrenWithHandlers));
|
|
82
|
+
};
|
|
15
83
|
/**
|
|
16
84
|
* Элемент списка (пункт меню либо ссылка)
|
|
17
85
|
*
|
|
@@ -20,90 +88,112 @@ import { SubMenu } from './SubMenu.js';
|
|
|
20
88
|
var ClickableElement = forwardRef(function (_a, ref) {
|
|
21
89
|
var _b, _c, _d;
|
|
22
90
|
var _e;
|
|
23
|
-
var onClick = _a.onClick, icon = _a.icon, marker = _a.marker, caption = _a.caption, subCaption = _a.subCaption, id = _a.id, _isSubMenu = _a._isSubMenu, children = _a.children, Tag = _a.element, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onBlur = _a.onBlur, className = _a.className, _isDropdown = _a._isDropdown, _isBackButton = _a._isBackButton, _isAvatar = _a._isAvatar, isButton = _a.isButton, href = _a.href, disabled = _a.disabled, noWrap = _a.noWrap, rest = __rest(_a, ["onClick", "icon", "marker", "caption", "subCaption", "id", "_isSubMenu", "children", "element", "onKeyDown", "onFocus", "onBlur", "className", "_isDropdown", "_isBackButton", "_isAvatar", "isButton", "href", "disabled", "noWrap"]);
|
|
91
|
+
var onClick = _a.onClick, icon = _a.icon, marker = _a.marker, caption = _a.caption, subCaption = _a.subCaption, id = _a.id, _isSubMenu = _a._isSubMenu, children = _a.children, Tag = _a.element, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onBlur = _a.onBlur, className = _a.className, _isDropdown = _a._isDropdown, _isDropdownOpen = _a._isDropdownOpen, _isBackButton = _a._isBackButton, _isAvatar = _a._isAvatar, isButton = _a.isButton, href = _a.href, disabled = _a.disabled, noWrap = _a.noWrap, hint = _a.hint, rest = __rest(_a, ["onClick", "icon", "marker", "caption", "subCaption", "id", "_isSubMenu", "children", "element", "onKeyDown", "onFocus", "onBlur", "className", "_isDropdown", "_isDropdownOpen", "_isBackButton", "_isAvatar", "isButton", "href", "disabled", "noWrap", "hint"]);
|
|
24
92
|
var context = useContext(SideMenuContext);
|
|
25
93
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
26
94
|
var styles = useStyles(getStyles);
|
|
27
95
|
var cx = useEmotion().cx;
|
|
28
96
|
var keyListener = useKeyListener();
|
|
29
|
-
var _f = __read(useState(false), 2),
|
|
30
|
-
var _g = __read(useState(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
97
|
+
var _f = __read(useState(false), 2), isFocusedByTab = _f[0], setIsFocusedByTab = _f[1];
|
|
98
|
+
var _g = __read(useState(function () {
|
|
99
|
+
if (id) {
|
|
100
|
+
return id;
|
|
101
|
+
}
|
|
102
|
+
if (href) {
|
|
103
|
+
return href;
|
|
104
|
+
}
|
|
105
|
+
var counter = context.childIdCounterRef;
|
|
106
|
+
if (counter) {
|
|
107
|
+
var index = counter.current;
|
|
108
|
+
counter.current += 1;
|
|
109
|
+
return "".concat(context.parentItemId, "__").concat(index);
|
|
110
|
+
}
|
|
111
|
+
return generateId();
|
|
112
|
+
}), 1), currentId = _g[0];
|
|
113
|
+
var focusRafRef = useRef(null);
|
|
114
|
+
var childIdCounterRef = useRef(0);
|
|
36
115
|
useEffect(function () {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
116
|
+
return function () {
|
|
117
|
+
if (focusRafRef.current !== null) {
|
|
118
|
+
cancelAnimationFrame(focusRafRef.current);
|
|
119
|
+
focusRafRef.current = null;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}, []);
|
|
123
|
+
var _h = useNodeState(currentId), isActive = _h.isActive, isExpanded = _h.isExpanded, isNestedSubMenu = _h.isNestedSubMenu, hasSeparatedSubMenu = _h.hasSeparatedSubMenu;
|
|
124
|
+
useEffect(function () {
|
|
125
|
+
context.dispatch({
|
|
126
|
+
type: 'REGISTER',
|
|
127
|
+
id: currentId,
|
|
128
|
+
parentId: context.parentItemId,
|
|
129
|
+
isSubMenu: !!_isSubMenu,
|
|
49
130
|
});
|
|
50
131
|
return function () {
|
|
51
|
-
|
|
52
|
-
(_a = context.navigation) === null || _a === void 0 ? void 0 : _a.updateNavigationTree();
|
|
132
|
+
context.dispatch({ type: 'UNREGISTER', id: currentId });
|
|
53
133
|
};
|
|
54
|
-
});
|
|
134
|
+
}, [currentId, context.parentItemId, _isSubMenu, context.dispatch]);
|
|
135
|
+
var Component = _isSubMenu || _isDropdown ? 'div' : 'li';
|
|
136
|
+
var isDesktopCollapsedMode = (context.isDesktop || context.isNarrowDesktop) && !context.isOpened;
|
|
137
|
+
var isActiveSection = context.state.activeFirstLevelParentId === currentId;
|
|
138
|
+
var isHighlighted = isActive || (isActiveSection && (context.isSeparatedMenu || isDesktopCollapsedMode));
|
|
139
|
+
var isCollapsedTopLevelSection = isDesktopCollapsedMode && !_isSubMenu && !_isDropdown && !_isBackButton && !_isAvatar;
|
|
140
|
+
var isCollapsedAccordionSection = isCollapsedTopLevelSection && !!children && !context.isSeparatedMenu;
|
|
141
|
+
var _j = __read(useState(false), 2), isAccordionOpen = _j[0], setIsAccordionOpen = _j[1];
|
|
142
|
+
useEffect(function () {
|
|
143
|
+
if (!isCollapsedAccordionSection) {
|
|
144
|
+
setIsAccordionOpen(false);
|
|
145
|
+
}
|
|
146
|
+
}, [isCollapsedAccordionSection]);
|
|
55
147
|
var toggleIsShown = function (lastElementInTheHierarchy) {
|
|
56
148
|
var _a;
|
|
57
149
|
if ((context.isMobile || context.isTablet) && lastElementInTheHierarchy) {
|
|
58
150
|
(_a = context.toggleIsOpened) === null || _a === void 0 ? void 0 : _a.call(context);
|
|
59
151
|
}
|
|
60
152
|
};
|
|
61
|
-
var setIsCollapsed = function (lastElementInTheHierarchy) {
|
|
62
|
-
var _a, _b;
|
|
63
|
-
if (context.isMobile || context.isTablet || (context.isDesktop && !context.isCollapsable)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
var topLevelItemInSeparatedSideMenu = context.isSeparatedMenu && !_isSubMenu && children;
|
|
67
|
-
if (context.isCollapsable && (lastElementInTheHierarchy || topLevelItemInSeparatedSideMenu)) {
|
|
68
|
-
(_a = context.setIsCollapsed) === null || _a === void 0 ? void 0 : _a.call(context, true);
|
|
69
|
-
}
|
|
70
|
-
if (!_isSubMenu) {
|
|
71
|
-
(_b = context.setIsCollapsed) === null || _b === void 0 ? void 0 : _b.call(context, false);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var setMouseIsOutside = function (lastElementInTheHierarchy) {
|
|
75
|
-
var _a;
|
|
76
|
-
if (lastElementInTheHierarchy) {
|
|
77
|
-
(_a = context.setIsMouseOutside) === null || _a === void 0 ? void 0 : _a.call(context, true);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
153
|
var handleClick = function (e) {
|
|
81
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
82
154
|
if (disabled) {
|
|
83
155
|
return;
|
|
84
156
|
}
|
|
157
|
+
if (isCollapsedAccordionSection) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
85
160
|
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
161
|
+
if (e.defaultPrevented) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
86
164
|
if (_isBackButton || _isDropdown) {
|
|
87
165
|
return;
|
|
88
166
|
}
|
|
89
|
-
var
|
|
90
|
-
|
|
167
|
+
var hasKids = context.state ? hasChildren(context.state, currentId) : false;
|
|
168
|
+
// A leaf inside a NarrowAccordionDropdown should dismiss the popup.
|
|
169
|
+
if (!hasKids && context.closeParentDropdown) {
|
|
170
|
+
context.closeParentDropdown();
|
|
171
|
+
}
|
|
172
|
+
if (isButton && !hasKids) {
|
|
91
173
|
return;
|
|
92
174
|
}
|
|
93
|
-
|
|
94
|
-
|
|
175
|
+
// An expanded item collapses on click (toggle), except in separated mode:
|
|
176
|
+
// - a top-level item on desktop keeps its column open on a repeated click
|
|
177
|
+
// (collapsing it would hide the whole column), and
|
|
178
|
+
// - touch (mobile/tablet) has its own BackButton toggle driven by SELECT.
|
|
179
|
+
var isTouchViewport = !!(context.isMobile || context.isTablet);
|
|
180
|
+
var isProtectedSeparatedTopLevel = context.isSeparatedMenu && !_isSubMenu && hasKids && !isTouchViewport;
|
|
181
|
+
if (isExpanded && !isProtectedSeparatedTopLevel && !(context.isSeparatedMenu && isTouchViewport)) {
|
|
182
|
+
context.dispatch({ type: 'CLOSE_NODE', id: currentId });
|
|
95
183
|
}
|
|
96
184
|
else {
|
|
97
|
-
|
|
98
|
-
var lastElementInTheHierarchy = !_isDropdown && !_isBackButton && !
|
|
185
|
+
context.dispatch({ type: 'SELECT', id: currentId, isButton: !!isButton });
|
|
186
|
+
var lastElementInTheHierarchy = !_isDropdown && !_isBackButton && !hasKids;
|
|
99
187
|
toggleIsShown(lastElementInTheHierarchy);
|
|
100
|
-
setIsCollapsed(lastElementInTheHierarchy);
|
|
101
|
-
setMouseIsOutside(lastElementInTheHierarchy);
|
|
102
188
|
}
|
|
103
189
|
};
|
|
104
190
|
var handleFocus = function (e) {
|
|
105
191
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
|
|
106
|
-
|
|
192
|
+
if (focusRafRef.current !== null) {
|
|
193
|
+
cancelAnimationFrame(focusRafRef.current);
|
|
194
|
+
}
|
|
195
|
+
focusRafRef.current = requestAnimationFrame(function () {
|
|
196
|
+
focusRafRef.current = null;
|
|
107
197
|
if (keyListener.isTabPressed) {
|
|
108
198
|
setIsFocusedByTab(true);
|
|
109
199
|
}
|
|
@@ -113,42 +203,73 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
113
203
|
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
114
204
|
setIsFocusedByTab(false);
|
|
115
205
|
};
|
|
116
|
-
var Component = _isSubMenu || _isDropdown ? 'div' : 'li';
|
|
117
|
-
var isHighlighted = isActive ||
|
|
118
|
-
(isFirstLevelParentOfActiveMenuItem && !context.isOpened && context.isCollapsable) ||
|
|
119
|
-
(isFirstLevelParentOfActiveMenuItem && context.isSeparatedMenu);
|
|
120
206
|
var handleCollapse = function (e) {
|
|
121
|
-
var _a, _b, _c, _d;
|
|
122
207
|
if (disabled) {
|
|
123
208
|
return;
|
|
124
209
|
}
|
|
125
210
|
e.stopPropagation();
|
|
126
|
-
|
|
211
|
+
context.dispatch({ type: 'CLOSE_NODE', id: currentId });
|
|
212
|
+
};
|
|
213
|
+
var subMenuIcon = useMemoIcon(children, { isOpened: isExpanded, onClick: handleCollapse });
|
|
214
|
+
var isNativeAnchor = Tag === 'a';
|
|
215
|
+
var handleKeyDown = function (e) {
|
|
216
|
+
if (isNativeAnchor && disabled && e.key === 'Enter') {
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
}
|
|
219
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
127
220
|
};
|
|
128
221
|
var newProps = __assign({ className: cx(styles.root(theme), (_b = {},
|
|
129
|
-
_b[styles.rootButton(theme)] =
|
|
222
|
+
_b[styles.rootButton(theme)] = !disabled,
|
|
130
223
|
_b[styles.rootFocus(theme)] = isFocusedByTab,
|
|
131
224
|
_b[styles.rootDisabled(theme)] = disabled,
|
|
132
225
|
_b[styles.rootActive(theme)] = isHighlighted,
|
|
226
|
+
_b[styles.rootDropdownOpen(theme)] = (_isDropdown && _isDropdownOpen) || isAccordionOpen,
|
|
133
227
|
_b), (_c = {},
|
|
134
228
|
_c[styles.rootSubItemInSeparatedSubMenu(theme)] = context.isSeparatedMenu && _isSubMenu,
|
|
229
|
+
_c[styles.rootSubItemInSeparatedSubMenuButton(theme)] = !disabled && context.isSeparatedMenu && _isSubMenu,
|
|
135
230
|
_c[styles.rootSubItemInSeparatedSubMenuActive(theme)] = isActive && context.isSeparatedMenu && _isSubMenu,
|
|
136
|
-
_c)
|
|
231
|
+
_c[styles.rootSubItemInDropdownActive(theme)] = isActive && !context.isSeparatedMenu && _isSubMenu && isDesktopCollapsedMode,
|
|
232
|
+
_c[styles.rootSubItemInDropdownButton(theme)] = !disabled && !context.isSeparatedMenu && _isSubMenu && isDesktopCollapsedMode,
|
|
233
|
+
_c), className), onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur, children: (React.createElement(ItemContent, { _isSubMenu: _isSubMenu,
|
|
137
234
|
// @ts-expect-error: SideMenuItem should have icon
|
|
138
|
-
icon: _isSubMenu && !_isBackButton ?
|
|
235
|
+
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, disabled: !isNativeAnchor ? disabled : undefined, 'aria-current': isActive ? 'page' : undefined }, rest);
|
|
139
236
|
// Подсчет смещения вправо для текущего уровня вложенности
|
|
237
|
+
// NOTE: Probably it can be calculated using Navigation Tree
|
|
140
238
|
var currentItemNestingLevel = (_e = context.currentItemNestingLevel) !== null && _e !== void 0 ? _e : 0;
|
|
141
239
|
var nestingLevelPadding = {
|
|
142
|
-
paddingLeft: (currentItemNestingLevel - 1) * parseInt(theme.sideMenuItemNestedPaddingLeft),
|
|
240
|
+
paddingLeft: Math.max(0, currentItemNestingLevel - 1) * parseInt(theme.sideMenuItemNestedPaddingLeft),
|
|
143
241
|
};
|
|
242
|
+
// NOTE: In the collapsed-accordion path (`isCollapsedAccordionSection`) this element is
|
|
243
|
+
// wrapped by `NarrowAccordionDropdown` → `DropdownMenu` → `PopupMenu`. `PopupMenu` adds
|
|
244
|
+
// its own correct `aria-expanded`/`aria-controls` to the outer caption wrapper, but
|
|
245
|
+
// this inner focusable element still keeps the `aria-expanded` set below. Because
|
|
246
|
+
// `handleClick` bails out early in accordion mode, the reducer never marks the section
|
|
247
|
+
// as opened, so the inner element always reports `aria-expanded="false"` while the
|
|
248
|
+
// popup is actually open. Screen readers announce the focused element's state, so
|
|
249
|
+
// the user can hear "collapsed" for an open section.
|
|
250
|
+
//
|
|
251
|
+
// The proper fix is to either sync the dropdown's opened state into this element, or
|
|
252
|
+
// to omit `aria-expanded` here in accordion mode and make the outer caption wrapper
|
|
253
|
+
// the accessible control (focusable + correct `aria-expanded`).
|
|
254
|
+
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 } : {}))));
|
|
255
|
+
var clickableElementWithHint = (React.createElement(ClickableElementWithHint, { hint: hint === null ? null : (hint !== null && hint !== void 0 ? hint : caption), isOpened: context.isOpened || (_isSubMenu && (context.isSeparatedMenu || isDesktopCollapsedMode)) }, clickableElement));
|
|
256
|
+
// Reset the child id counter on every render so children at this nesting level get stable,
|
|
257
|
+
// position-based generated ids across unmount → re-mount transitions (e.g. narrow
|
|
258
|
+
// accordion dropdown closing → inline submenu opening).
|
|
259
|
+
childIdCounterRef.current = 0;
|
|
260
|
+
var subMenuContextValue = useMemo(function () { return (__assign(__assign({ hasSeparatedSubMenu: hasSeparatedSubMenu }, context), { parentItemId: currentId, currentItemNestingLevel: currentItemNestingLevel + 1, childIdCounterRef: childIdCounterRef })); }, [hasSeparatedSubMenu, context, currentId, currentItemNestingLevel]);
|
|
261
|
+
// При клике на айтем без детей закрывать дропдаун
|
|
262
|
+
// айтем должен оставаться активным и при разворачивании меню корректно показываться в списке подменю
|
|
263
|
+
// При клике на активный элемент с детьми, он должен закрыться
|
|
144
264
|
return (React.createElement(Component, (_d = { "data-tid": SideMenuDataTids.clickableElement }, _d[navigationAttribute] = currentId, _d),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
React.createElement(
|
|
265
|
+
isCollapsedAccordionSection && (React.createElement(NarrowAccordionDropdown, { caption: clickableElementWithHint, htmlId: currentId, childIdCounterRef: childIdCounterRef, disabled: disabled, onOpenChange: setIsAccordionOpen }, children)),
|
|
266
|
+
!isCollapsedAccordionSection && (React.createElement(React.Fragment, null,
|
|
267
|
+
clickableElementWithHint,
|
|
268
|
+
React.createElement(SubMenu, { caption: caption, isSubMenu: _isSubMenu, isSeparatedMenu: context.isSeparatedMenu, htmlId: currentId, isOpened: isExpanded },
|
|
269
|
+
React.createElement(SideMenuContext.Provider, { value: subMenuContextValue }, children))))));
|
|
149
270
|
});
|
|
150
271
|
ClickableElement.displayName = 'ClickableElement';
|
|
151
272
|
var ClickableElementWithStaticFields = Object.assign(ClickableElement, {
|
|
152
273
|
__KONTUR_REACT_UI__: 'ClickableElement',
|
|
153
274
|
});
|
|
154
|
-
export { ClickableElementWithStaticFields as ClickableElement };
|
|
275
|
+
export { ClickableElementWithStaticFields as ClickableElement, ClickableElementWithHint };
|
|
@@ -3,8 +3,12 @@ export declare const getStyles: import("../../lib/theming/ThemeHelpers.js").Styl
|
|
|
3
3
|
root(t: SideMenuTheme): string;
|
|
4
4
|
rootButton(t: SideMenuTheme): string;
|
|
5
5
|
rootSubItemInSeparatedSubMenu(t: SideMenuTheme): string;
|
|
6
|
+
rootSubItemInSeparatedSubMenuButton(t: SideMenuTheme): string;
|
|
6
7
|
rootFocus(t: SideMenuTheme): string;
|
|
7
8
|
rootDisabled(t: SideMenuTheme): string;
|
|
8
9
|
rootActive(t: SideMenuTheme): string;
|
|
10
|
+
rootDropdownOpen(t: SideMenuTheme): string;
|
|
11
|
+
rootSubItemInDropdownActive(t: SideMenuTheme): string;
|
|
12
|
+
rootSubItemInDropdownButton(t: SideMenuTheme): string;
|
|
9
13
|
rootSubItemInSeparatedSubMenuActive(t: SideMenuTheme): string;
|
|
10
14
|
}>;
|
|
@@ -5,26 +5,38 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
5
5
|
var css = _a.css;
|
|
6
6
|
return ({
|
|
7
7
|
root: function (t) {
|
|
8
|
-
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n user-select: text;\n ", ";\n color: ", ";\n width: 100%;\n border-radius: ", ";\n cursor: pointer;\n box-sizing: border-box;\n\n &:hover {\n background: ", ";\n }\n "], ["\n user-select: text;\n ", ";\n color: ", ";\n width: 100%;\n border-radius: ", ";\n cursor: pointer;\n box-sizing: border-box;\n\n &:hover {\n background: ", ";\n }\n "])), resetButton(), t.sideMenuItemColor, t.sideMenuItemBorderRadius, t.sideMenuItemBgHover);
|
|
8
|
+
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n user-select: text;\n ", ";\n color: ", ";\n width: 100%;\n border-radius: ", ";\n cursor: pointer;\n box-sizing: border-box;\n scroll-margin-top: var(--side-menu-scroll-margin-top, 0);\n scroll-margin-bottom: var(--side-menu-scroll-margin-bottom, 0);\n transition: background ", " ease-out;\n\n &:hover {\n background: ", ";\n }\n "], ["\n user-select: text;\n ", ";\n color: ", ";\n width: 100%;\n border-radius: ", ";\n cursor: pointer;\n box-sizing: border-box;\n scroll-margin-top: var(--side-menu-scroll-margin-top, 0);\n scroll-margin-bottom: var(--side-menu-scroll-margin-bottom, 0);\n transition: background ", " ease-out;\n\n &:hover {\n background: ", ";\n }\n "])), resetButton(), t.sideMenuItemColor, t.sideMenuItemBorderRadius, t.transitionDuration, t.sideMenuItemBgHover);
|
|
9
9
|
},
|
|
10
10
|
rootButton: function (t) {
|
|
11
|
-
return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n &:active {\n background: ", ";\n }\n "], ["\n &:active {\n background: ", ";\n }\n "])), t.
|
|
11
|
+
return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n &:active {\n background: ", ";\n }\n "], ["\n &:active {\n background: ", ";\n }\n "])), t.sideMenuItemBgPressed);
|
|
12
12
|
},
|
|
13
13
|
rootSubItemInSeparatedSubMenu: function (t) {
|
|
14
14
|
return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n &:hover {\n background: ", ";\n }\n "], ["\n &:hover {\n background: ", ";\n }\n "])), t.sideMenuSubItemWithSeparatedSubMenuBgHover);
|
|
15
15
|
},
|
|
16
|
+
rootSubItemInSeparatedSubMenuButton: function (t) {
|
|
17
|
+
return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n &:active {\n background: ", ";\n }\n "], ["\n &:active {\n background: ", ";\n }\n "])), t.sideMenuSubItemWithSeparatedSubMenuBgPressed);
|
|
18
|
+
},
|
|
16
19
|
rootFocus: function (t) {
|
|
17
|
-
return css(
|
|
20
|
+
return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n box-shadow: ", ";\n "], ["\n box-shadow: ", ";\n "])), t.sideMenuItemBoxShadowFocus);
|
|
18
21
|
},
|
|
19
22
|
rootDisabled: function (t) {
|
|
20
|
-
return css(
|
|
23
|
+
return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n color: ", ";\n pointer-events: none;\n "], ["\n color: ", ";\n pointer-events: none;\n "])), t.sideMenuItemColorDisabled);
|
|
21
24
|
},
|
|
22
25
|
rootActive: function (t) {
|
|
23
|
-
return css(
|
|
26
|
+
return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n background: ", " !important;\n "], ["\n background: ", " !important;\n "])), t.sideMenuItemBgActive);
|
|
27
|
+
},
|
|
28
|
+
rootDropdownOpen: function (t) {
|
|
29
|
+
return css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n background: ", " !important;\n "], ["\n background: ", " !important;\n "])), t.sideMenuItemBgHover);
|
|
30
|
+
},
|
|
31
|
+
rootSubItemInDropdownActive: function (t) {
|
|
32
|
+
return css(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n background: ", " !important;\n "], ["\n background: ", " !important;\n "])), t.sideMenuItemBgHover);
|
|
33
|
+
},
|
|
34
|
+
rootSubItemInDropdownButton: function (t) {
|
|
35
|
+
return css(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n &:active {\n background: ", ";\n }\n "], ["\n &:active {\n background: ", ";\n }\n "])), t.sideMenuItemBgPressed);
|
|
24
36
|
},
|
|
25
37
|
rootSubItemInSeparatedSubMenuActive: function (t) {
|
|
26
|
-
return css(
|
|
38
|
+
return css(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n background: ", " !important;\n "], ["\n background: ", " !important;\n "])), t.sideMenuSubItemWithSeparatedSubMenuBgActive);
|
|
27
39
|
},
|
|
28
40
|
});
|
|
29
41
|
});
|
|
30
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
|
|
42
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __read } from "tslib";
|
|
2
|
+
import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
|
|
3
|
+
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
4
|
+
import React, { useContext, useLayoutEffect, useState } from 'react';
|
|
5
|
+
import ReactDOM from 'react-dom';
|
|
6
|
+
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
7
|
+
import { SideMenuDataTids } from '../../SideMenuDataTids.js';
|
|
8
|
+
import { SideMenuContext } from '../SideMenuContext.js';
|
|
9
|
+
import { ClickableElementWithHint } from './ClickableElement.js';
|
|
10
|
+
import { getStyles } from './CollapseToggle.styles.js';
|
|
11
|
+
var SideMenuCollapseIcon = function () {
|
|
12
|
+
return (React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "none" },
|
|
13
|
+
React.createElement("path", { stroke: "currentColor", strokeWidth: 1.5, d: "M8.5 19V5M6 19h12a3 3 0 0 0 3-3V8a3 3 0 0 0-3-3H6a3 3 0 0 0-3 3v8a3 3 0 0 0 3 3Z" })));
|
|
14
|
+
};
|
|
15
|
+
export var CollapseToggle = function () {
|
|
16
|
+
var context = useContext(SideMenuContext);
|
|
17
|
+
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
18
|
+
var styles = useStyles(getStyles);
|
|
19
|
+
var cx = useEmotion().cx;
|
|
20
|
+
var slotRef = context.collapseToggleRef;
|
|
21
|
+
var _a = __read(useState(false), 2), mounted = _a[0], setMounted = _a[1];
|
|
22
|
+
// The slot lives in the Footer, which mounts in the same commit. Refs are assigned
|
|
23
|
+
// before layout effects run, so after this effect the portal target is ready.
|
|
24
|
+
useLayoutEffect(function () {
|
|
25
|
+
setMounted(true);
|
|
26
|
+
}, []);
|
|
27
|
+
var isOpened = !!context.isOpened;
|
|
28
|
+
var hintText = isOpened ? 'Свернуть меню' : 'Развернуть меню';
|
|
29
|
+
var handleClick = function () {
|
|
30
|
+
var _a;
|
|
31
|
+
(_a = context.setMenuOpened) === null || _a === void 0 ? void 0 : _a.call(context, !isOpened);
|
|
32
|
+
};
|
|
33
|
+
var button = (React.createElement(ClickableElementWithHint, { hint: hintText, isOpened: false },
|
|
34
|
+
React.createElement("button", { type: 'button', className: cx(styles.root(theme)), "aria-label": hintText, "aria-expanded": isOpened, "data-tid": SideMenuDataTids.collapseToggle, onClick: handleClick },
|
|
35
|
+
React.createElement(SideMenuCollapseIcon, null))));
|
|
36
|
+
if (!mounted || !(slotRef === null || slotRef === void 0 ? void 0 : slotRef.current)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return ReactDOM.createPortal(button, slotRef.current);
|
|
40
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __makeTemplateObject } from "tslib";
|
|
2
|
+
import { resetButton } from '@skbkontur/react-ui/lib/styles/Mixins';
|
|
3
|
+
import { memoizeGetStyles } from '../../lib/theming/ThemeHelpers.js';
|
|
4
|
+
import { transitionDuration } from '../SideMenu/SideMenu.js';
|
|
5
|
+
export var getStyles = memoizeGetStyles(function (_a) {
|
|
6
|
+
var css = _a.css;
|
|
7
|
+
return ({
|
|
8
|
+
root: function (t) {
|
|
9
|
+
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 transition: background ", " ease-out;\n\n &:hover {\n color: ", ";\n }\n\n &:focus-visible {\n box-shadow: ", ";\n }\n\n svg {\n transition: opacity ", ";\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 transition: background ", " ease-out;\n\n &:hover {\n color: ", ";\n }\n\n &:focus-visible {\n box-shadow: ", ";\n }\n\n svg {\n transition: opacity ", ";\n }\n "])), resetButton(), t.sideMenuCollapseToggleSize, t.sideMenuCollapseToggleSize, t.sideMenuItemBorderRadius, t.sideMenuRightBorderIconColor, t.transitionDuration, t.sideMenuRightBorderIconColorHover, t.sideMenuItemBoxShadowFocus, transitionDuration);
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
var templateObject_1;
|
|
@@ -7,5 +7,5 @@ interface CaptionProps extends Pick<SideMenuItemProps, '_isSubMenu' | 'caption'
|
|
|
7
7
|
isNestedSubMenu?: boolean;
|
|
8
8
|
noWrap?: boolean;
|
|
9
9
|
}
|
|
10
|
-
export declare const Caption: React.ForwardRefExoticComponent<CaptionProps & React.RefAttributes<
|
|
10
|
+
export declare const Caption: React.ForwardRefExoticComponent<CaptionProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
11
|
export {};
|
|
@@ -5,13 +5,7 @@ import React, { forwardRef, useContext, useEffect, useRef, useState } from 'reac
|
|
|
5
5
|
import { getSideMenuTheme } from '../../../lib/theming/ThemeHelpers.js';
|
|
6
6
|
import { SideMenuContext } from '../../SideMenuContext.js';
|
|
7
7
|
import { getStyles } from './Caption.styles.js';
|
|
8
|
-
|
|
9
|
-
var _a = __read(caption.split(' '), 2), firstName = _a[0], lastName = _a[1];
|
|
10
|
-
if (captionWidth > maxCaptionWidth && lastName) {
|
|
11
|
-
return "".concat(firstName, " ").concat(lastName[0], ".");
|
|
12
|
-
}
|
|
13
|
-
return caption;
|
|
14
|
-
};
|
|
8
|
+
// NOTE: assumes an approximately monospaced character width; proportional fonts give only approximate tail length.
|
|
15
9
|
var getCaptionTail = function (caption, captionWidth, maxCaptionWidth) {
|
|
16
10
|
if (captionWidth > maxCaptionWidth) {
|
|
17
11
|
var symbolsCount = caption.length;
|
|
@@ -25,7 +19,7 @@ export var Caption = forwardRef(function (_a, ref) {
|
|
|
25
19
|
var _b, _c;
|
|
26
20
|
var _isSubMenu = _a._isSubMenu, isNestedSubMenu = _a.isNestedSubMenu, caption = _a.caption, subCaption = _a.subCaption, hasIcon = _a.hasIcon, hasMarker = _a.hasMarker, isMultiline = _a.isMultiline, noWrap = _a.noWrap, _isBackButton = _a._isBackButton, _isDropdown = _a._isDropdown, _isAvatar = _a._isAvatar;
|
|
27
21
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
28
|
-
var _d = useContext(SideMenuContext), isSeparatedMenu = _d.isSeparatedMenu, size = _d.size, isTouchScreen = _d.isTouchScreen,
|
|
22
|
+
var _d = useContext(SideMenuContext), isSeparatedMenu = _d.isSeparatedMenu, size = _d.size, isTouchScreen = _d.isTouchScreen, hasSeparatedSubMenu = _d.hasSeparatedSubMenu, isBeingTransitioned = _d.isBeingTransitioned, sideMenuRef = _d.sideMenuRef, isOpened = _d.isOpened;
|
|
29
23
|
var isLarge = size === 'large';
|
|
30
24
|
var isCaptionPlainText = typeof caption === 'string';
|
|
31
25
|
var captionRef = useRef(null);
|
|
@@ -36,13 +30,9 @@ export var Caption = forwardRef(function (_a, ref) {
|
|
|
36
30
|
if (!caption || !isCaptionPlainText || !captionRef.current || !_isDropdown) {
|
|
37
31
|
return;
|
|
38
32
|
}
|
|
39
|
-
captionRef.current.innerText = caption;
|
|
40
33
|
var captionWidth = captionRef.current.scrollWidth;
|
|
41
34
|
var maxCaptionWidth = captionRef.current.offsetWidth;
|
|
42
|
-
if (_isAvatar) {
|
|
43
|
-
captionRef.current.innerText = getTruncatedUserName(caption, captionWidth, maxCaptionWidth);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
35
|
+
if (!_isAvatar) {
|
|
46
36
|
setTail(getCaptionTail(caption, captionWidth, maxCaptionWidth));
|
|
47
37
|
}
|
|
48
38
|
};
|
|
@@ -50,36 +40,29 @@ export var Caption = forwardRef(function (_a, ref) {
|
|
|
50
40
|
truncateSpecialCaption();
|
|
51
41
|
}, [caption]);
|
|
52
42
|
useEffect(function () {
|
|
53
|
-
var _a;
|
|
54
43
|
var handleTransition = function (e) {
|
|
55
44
|
if (e.propertyName === 'width') {
|
|
56
45
|
truncateSpecialCaption();
|
|
57
46
|
}
|
|
58
47
|
};
|
|
59
|
-
|
|
48
|
+
var sideMenuNode = sideMenuRef === null || sideMenuRef === void 0 ? void 0 : sideMenuRef.current;
|
|
49
|
+
sideMenuNode === null || sideMenuNode === void 0 ? void 0 : sideMenuNode.addEventListener('transitionend', handleTransition);
|
|
60
50
|
return function () {
|
|
61
|
-
removeEventListener('transitionend', handleTransition);
|
|
51
|
+
sideMenuNode === null || sideMenuNode === void 0 ? void 0 : sideMenuNode.removeEventListener('transitionend', handleTransition);
|
|
62
52
|
};
|
|
63
53
|
}, [isBeingTransitioned]);
|
|
64
|
-
var isAvatarCaptionSingleWord = function (userName, _isAvatar) {
|
|
65
|
-
if (userName === void 0) { userName = ''; }
|
|
66
|
-
if (_isAvatar === void 0) { _isAvatar = false; }
|
|
67
|
-
return _isAvatar && userName.split(' ').length === 1;
|
|
68
|
-
};
|
|
69
54
|
var Component = isCaptionPlainText ? 'p' : 'div';
|
|
70
55
|
return (React.createElement("div", { className: cx(styles.root(), (_b = {},
|
|
71
56
|
_b[styles.rootMultiline(theme)] = isMultiline && !noWrap && !_isSubMenu,
|
|
72
57
|
_b)), ref: ref },
|
|
73
58
|
React.createElement(Component, { className: cx(styles.caption(theme), (_c = {},
|
|
74
59
|
_c[styles.captionDropdown()] = _isDropdown,
|
|
75
|
-
_c[styles.captionTruncated()] = isCaptionPlainText &&
|
|
76
|
-
_isDropdown &&
|
|
77
|
-
(!_isAvatar || isAvatarCaptionSingleWord(caption, _isAvatar)),
|
|
60
|
+
_c[styles.captionTruncated()] = isCaptionPlainText && _isDropdown,
|
|
78
61
|
_c[styles.captionSubItem(theme)] = _isSubMenu,
|
|
79
62
|
_c[styles.captionSubItemSeparatedMenuTopLevel()] = isSeparatedMenu && !isNestedSubMenu && _isSubMenu && !hasIcon,
|
|
80
63
|
_c[styles.captionNestedItemSeparatedMenu()] = isSeparatedMenu && isNestedSubMenu && !hasIcon,
|
|
81
|
-
_c[styles.captionWithoutItemIcon()] = !hasIcon && !isSeparatedMenu,
|
|
82
|
-
_c[styles.captionSubItemWithoutColumnIcons()] = _isSubMenu && isSeparatedMenu && !
|
|
64
|
+
_c[styles.captionWithoutItemIcon()] = !hasIcon && !isSeparatedMenu && isOpened,
|
|
65
|
+
_c[styles.captionSubItemWithoutColumnIcons()] = _isSubMenu && isSeparatedMenu && !hasSeparatedSubMenu,
|
|
83
66
|
_c[styles.captionLarge(theme)] = isLarge,
|
|
84
67
|
_c[styles.captionTouchScreen(theme)] = isTouchScreen,
|
|
85
68
|
_c[styles.captionSubItemTouchScreen(theme)] = isTouchScreen && _isSubMenu,
|
|
@@ -17,7 +17,7 @@ export var Icon = function (_a) {
|
|
|
17
17
|
var _b;
|
|
18
18
|
var _isSubMenu = _a._isSubMenu, icon = _a.icon, isMultiline = _a.isMultiline, disabled = _a.disabled, _c = _a._isBackButton, _isBackButton = _c === void 0 ? false : _c;
|
|
19
19
|
var context = useContext(SideMenuContext);
|
|
20
|
-
var isSeparatedMenu = context.isSeparatedMenu, size = context.size;
|
|
20
|
+
var isSeparatedMenu = context.isSeparatedMenu, size = context.size, isOpened = context.isOpened;
|
|
21
21
|
var isLarge = size === 'large';
|
|
22
22
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
23
23
|
var styles = useStyles(getStyles);
|
|
@@ -34,9 +34,10 @@ export var Icon = function (_a) {
|
|
|
34
34
|
return icon;
|
|
35
35
|
};
|
|
36
36
|
return (React.createElement("span", { className: cx(styles.root(theme), (_b = {},
|
|
37
|
-
_b[styles.rootMultiline()] = isMultiline && (
|
|
37
|
+
_b[styles.rootMultiline()] = isMultiline && (isOpened || _isSubMenu),
|
|
38
38
|
_b[styles.rootLarge(theme)] = isLarge,
|
|
39
39
|
_b[styles.rootSubItem(theme)] = _isSubMenu,
|
|
40
|
+
_b[styles.rootSubItemDropdown()] = _isSubMenu && !isOpened && !isSeparatedMenu,
|
|
40
41
|
_b[styles.rootSubItemSeparatedMenu(theme)] = isSeparatedMenu && _isSubMenu,
|
|
41
42
|
_b[styles.rootSubItemLarge(theme)] = _isSubMenu && isLarge,
|
|
42
43
|
_b[styles.rootBackButton(theme)] = _isBackButton,
|
|
@@ -5,6 +5,7 @@ export declare const getStyles: import("../../../lib/theming/ThemeHelpers.js").S
|
|
|
5
5
|
rootLarge(t: SideMenuTheme): string;
|
|
6
6
|
rootSubItemLarge(t: SideMenuTheme): string;
|
|
7
7
|
rootSubItem(t: SideMenuTheme): string;
|
|
8
|
+
rootSubItemDropdown(): string;
|
|
8
9
|
rootSubItemSeparatedMenu(t: SideMenuTheme): string;
|
|
9
10
|
rootBackButton(t: SideMenuTheme): string;
|
|
10
11
|
}>;
|
|
@@ -18,12 +18,15 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
18
18
|
rootSubItem: function (t) {
|
|
19
19
|
return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n margin: 0;\n padding-left: ", ";\n padding-right: ", ";\n min-height: ", ";\n line-height: ", ";\n "], ["\n margin: 0;\n padding-left: ", ";\n padding-right: ", ";\n min-height: ", ";\n line-height: ", ";\n "])), t.sideMenuIconSubItemPaddingLeft, t.sideMenuIconSubItemPaddingRight, t.sideMenuIconSubItemMinHeight, t.sideMenuIconSubItemLineHeight);
|
|
20
20
|
},
|
|
21
|
+
rootSubItemDropdown: function () {
|
|
22
|
+
return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n padding-left: 0;\n "], ["\n padding-left: 0;\n "])));
|
|
23
|
+
},
|
|
21
24
|
rootSubItemSeparatedMenu: function (t) {
|
|
22
|
-
return css(
|
|
25
|
+
return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n padding-left: ", ";\n "], ["\n padding-left: ", ";\n "])), t.sideMenuIconWithSeparatedSubMenuSubItemPaddingLeft);
|
|
23
26
|
},
|
|
24
27
|
rootBackButton: function (t) {
|
|
25
|
-
return css(
|
|
28
|
+
return css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n padding-left: ", ";\n padding-right: ", ";\n "], ["\n padding-left: ", ";\n padding-right: ", ";\n "])), t.sideMenuBackButtonIconPaddingLeft, t.sideMenuBackButtonIconPaddingRight);
|
|
26
29
|
},
|
|
27
30
|
});
|
|
28
31
|
});
|
|
29
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
|
|
32
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
|