@skbkontur/side-menu 5.0.0-alpha.4 → 5.0.0-beta.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 +32 -0
- package/README.md +2 -2
- package/internal/themes/SideMenuDarkTheme.js +7 -6
- package/internal/themes/SideMenuTheme.d.ts +16 -0
- package/internal/themes/SideMenuTheme.js +38 -8
- package/lib/theming/ThemeHelpers.js +4 -0
- package/package.json +7 -7
- package/src/SideMenu/SideMenu.d.ts +1 -0
- package/src/SideMenu/SideMenu.js +29 -34
- package/src/SideMenu/SideMenu.styles.d.ts +4 -5
- package/src/SideMenu/SideMenu.styles.js +26 -36
- package/src/SideMenuBody/SideMenuBody.js +2 -1
- package/src/SideMenuBody/SideMenuBody.styles.js +1 -2
- package/src/SideMenuContext.d.ts +1 -8
- package/src/SideMenuDivider/SideMenuDivider.js +4 -2
- package/src/SideMenuDivider/SideMenuDivider.styles.d.ts +1 -0
- package/src/SideMenuDivider/SideMenuDivider.styles.js +6 -3
- package/src/SideMenuDropdown/SideMenuDropdown.js +7 -7
- package/src/SideMenuDropdown/SideMenuDropdown.styles.d.ts +0 -1
- package/src/SideMenuDropdown/SideMenuDropdown.styles.js +4 -8
- package/src/SideMenuFooter/SideMenuFooter.js +6 -29
- package/src/SideMenuFooter/SideMenuFooter.styles.js +3 -4
- package/src/SideMenuHeader/SideMenuHeader.js +4 -1
- package/src/SideMenuHeader/SideMenuHeader.styles.d.ts +2 -0
- package/src/SideMenuHeader/SideMenuHeader.styles.js +12 -5
- package/src/SideMenuNotifications/BellWidget.js +13 -6
- package/src/SideMenuNotifications/BellWidgetError.js +6 -3
- package/src/SideMenuNotifications/BellWidgetView.styles.d.ts +7 -4
- package/src/SideMenuNotifications/BellWidgetView.styles.js +20 -9
- package/src/SideMenuNotifications/utils/getWrapperHeightClass.d.ts +11 -0
- package/src/SideMenuNotifications/utils/getWrapperHeightClass.js +10 -0
- 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/internal/ClickableElement.d.ts +3 -1
- package/src/internal/ClickableElement.js +35 -36
- package/src/internal/InnerSubMenu.js +4 -0
- package/src/internal/ItemContent/Caption.js +4 -4
- package/src/internal/ItemContent/Caption.styles.d.ts +2 -0
- package/src/internal/ItemContent/Caption.styles.js +14 -8
- package/src/internal/ItemContent/Icon.js +1 -0
- package/src/internal/ItemContent/Icon.styles.d.ts +1 -0
- package/src/internal/ItemContent/Icon.styles.js +13 -10
- package/src/internal/ItemContent/ItemContent.js +26 -5
- package/src/internal/ItemContent/ItemContent.styles.d.ts +0 -1
- package/src/internal/ItemContent/ItemContent.styles.js +2 -6
- package/src/internal/ItemContent/Marker.js +1 -1
- package/src/internal/NarrowAccordionDropdown.d.ts +1 -2
- package/src/internal/NarrowAccordionDropdown.js +9 -14
- package/src/internal/SideMenuLogotype.js +29 -3
- package/src/internal/SideMenuLogotype.styles.d.ts +2 -0
- package/src/internal/SideMenuLogotype.styles.js +13 -6
- package/src/internal/subMenuItems.d.ts +3 -0
- package/src/internal/subMenuItems.js +43 -0
- package/src/state/reducer.js +46 -26
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __makeTemplateObject } from "tslib";
|
|
2
2
|
import { memoizeGetStyles } from '../../lib/theming/ThemeHelpers.js';
|
|
3
|
-
import { transitionDuration } from '../SideMenu/SideMenu.js';
|
|
3
|
+
import { transitionDuration, transitionEasing } from '../SideMenu/SideMenu.js';
|
|
4
|
+
import { compactDesktopMenu } from '../SideMenu/SideMenu.styles.js';
|
|
4
5
|
export var sideMenuLogotypeIconSize = '32px';
|
|
5
6
|
export var sideMenuLogotypeGapBetweenIconAndLogo = '50px';
|
|
6
7
|
export var getStyles = memoizeGetStyles(function (_a) {
|
|
@@ -15,18 +16,24 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
15
16
|
icon: function () {
|
|
16
17
|
return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n align-self: flex-start;\n opacity: 1;\n width: auto;\n "], ["\n align-self: flex-start;\n opacity: 1;\n width: auto;\n "])));
|
|
17
18
|
},
|
|
19
|
+
defaultIconSize: function () {
|
|
20
|
+
return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n width: ", ";\n height: ", ";\n "], ["\n width: ", ";\n height: ", ";\n "])), sideMenuLogotypeIconSize, sideMenuLogotypeIconSize);
|
|
21
|
+
},
|
|
22
|
+
iconUntilExpanded: function (t) {
|
|
23
|
+
return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n ", "\n "], ["\n ", "\n "])), compactDesktopMenu(t, "width: ".concat(sideMenuLogotypeIconSize, "; height: ").concat(sideMenuLogotypeIconSize, "; opacity: 1;")));
|
|
24
|
+
},
|
|
18
25
|
iconHidden: function (t) {
|
|
19
|
-
return css(
|
|
26
|
+
return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n display: block;\n align-self: flex-start;\n width: 0;\n padding-left: ", ";\n opacity: 0;\n transition:\n opacity ", "ms ", ",\n padding-left ", "ms ", ";\n "], ["\n display: block;\n align-self: flex-start;\n width: 0;\n padding-left: ", ";\n opacity: 0;\n transition:\n opacity ", "ms ", ",\n padding-left ", "ms ", ";\n "])), t.sideMenuLogotypeHiddenIconPaddingLeft, transitionDuration, transitionEasing, transitionDuration, transitionEasing);
|
|
20
27
|
},
|
|
21
28
|
logoWrapper: function (t) {
|
|
22
|
-
return css(
|
|
29
|
+
return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n display: flex;\n padding-top: ", ";\n padding-bottom: ", ";\n padding-left: ", ";\n\n [data-logotype-component] {\n height: auto !important;\n }\n #spwDropdown {\n align-items: flex-end;\n }\n\n [data-logotype-widget] {\n align-content: end;\n align-items: end;\n }\n "], ["\n display: flex;\n padding-top: ", ";\n padding-bottom: ", ";\n padding-left: ", ";\n\n [data-logotype-component] {\n height: auto !important;\n }\n #spwDropdown {\n align-items: flex-end;\n }\n\n [data-logotype-widget] {\n align-content: end;\n align-items: end;\n }\n "])), t.sideMenuLogotypePaddingTop, t.sideMenuLogotypePaddingBottom, t.sideMenuLogotypePaddingLeft);
|
|
23
30
|
},
|
|
24
31
|
logoWrapperTabletAndMobile: function () {
|
|
25
|
-
return css(
|
|
32
|
+
return css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n padding: 0;\n gap: 2px;\n align-items: center;\n\n #spwDropdown {\n align-items: center;\n }\n\n [data-logotype-widget] {\n align-content: center;\n align-items: center;\n }\n\n #spwClicker {\n box-sizing: border-box;\n width: 44px;\n height: 44px;\n padding: 0;\n display: inline-flex;\n justify-content: center;\n align-items: center;\n }\n "], ["\n padding: 0;\n gap: 2px;\n align-items: center;\n\n #spwDropdown {\n align-items: center;\n }\n\n [data-logotype-widget] {\n align-content: center;\n align-items: center;\n }\n\n #spwClicker {\n box-sizing: border-box;\n width: 44px;\n height: 44px;\n padding: 0;\n display: inline-flex;\n justify-content: center;\n align-items: center;\n }\n "])));
|
|
26
33
|
},
|
|
27
34
|
logoWrapperHidden: function () {
|
|
28
|
-
return css(
|
|
35
|
+
return css(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n display: none;\n "], ["\n display: none;\n "])));
|
|
29
36
|
},
|
|
30
37
|
});
|
|
31
38
|
});
|
|
32
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
|
|
39
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
var itemTypes = new Set(['SideMenuItem', 'SideMenuLink', 'SideMenuSubItem', 'SideMenuSubLink']);
|
|
3
|
+
function isMenuItem(child) {
|
|
4
|
+
var type = child.type;
|
|
5
|
+
return type.__KONTUR_REACT_UI__ !== undefined && itemTypes.has(type.__KONTUR_REACT_UI__);
|
|
6
|
+
}
|
|
7
|
+
// The popup and inline submenu mount separate React trees. Seed both from the same
|
|
8
|
+
// child keys within the parent item so switching views preserves the selected item.
|
|
9
|
+
export function withSubMenuItemIds(children, parentId) {
|
|
10
|
+
if (Array.isArray(children)) {
|
|
11
|
+
return children.map(function (child, index) { return withItemId(child, parentId, index); });
|
|
12
|
+
}
|
|
13
|
+
return withItemId(children, parentId, 0);
|
|
14
|
+
}
|
|
15
|
+
function withItemId(child, parentId, index) {
|
|
16
|
+
var key = React.isValidElement(child) ? child.key : null;
|
|
17
|
+
var segment = key === null ? index : encodeURIComponent(JSON.stringify(key));
|
|
18
|
+
var path = parentId ? "".concat(parentId, "/").concat(segment) : '';
|
|
19
|
+
if (Array.isArray(child)) {
|
|
20
|
+
return withSubMenuItemIds(child, path);
|
|
21
|
+
}
|
|
22
|
+
if (!React.isValidElement(child)) {
|
|
23
|
+
return child;
|
|
24
|
+
}
|
|
25
|
+
if (isMenuItem(child)) {
|
|
26
|
+
return React.cloneElement(child, { _generatedId: path });
|
|
27
|
+
}
|
|
28
|
+
var children = child.props.children;
|
|
29
|
+
if (Array.isArray(children) || React.isValidElement(children)) {
|
|
30
|
+
return React.cloneElement(child, { children: withSubMenuItemIds(children, path) });
|
|
31
|
+
}
|
|
32
|
+
return child;
|
|
33
|
+
}
|
|
34
|
+
// A collapsed accordion mounts its popup children on demand. Their declared IDs
|
|
35
|
+
// still identify the active section while the reducer is waiting for registration.
|
|
36
|
+
export function hasSubMenuItem(children, id) {
|
|
37
|
+
return React.Children.toArray(children).some(function (child) {
|
|
38
|
+
if (!React.isValidElement(child)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return ((isMenuItem(child) && (child.props.id || child.props.href) === id) || hasSubMenuItem(child.props.children, id));
|
|
42
|
+
});
|
|
43
|
+
}
|
package/src/state/reducer.js
CHANGED
|
@@ -31,14 +31,15 @@ function getDescendantIds(state, id) {
|
|
|
31
31
|
return result;
|
|
32
32
|
}
|
|
33
33
|
function register(state, id, parentId, isSubMenuItem) {
|
|
34
|
-
var _a;
|
|
34
|
+
var e_2, _a;
|
|
35
|
+
var _b, _c;
|
|
35
36
|
if (state.parentOf.has(id) || id === ROOT || id === parentId) {
|
|
36
37
|
return state;
|
|
37
38
|
}
|
|
38
39
|
var parentOf = new Map(state.parentOf);
|
|
39
40
|
parentOf.set(id, parentId);
|
|
40
41
|
var childrenOf = new Map(state.childrenOf);
|
|
41
|
-
var parentKids = new Set((
|
|
42
|
+
var parentKids = new Set((_b = childrenOf.get(parentId)) !== null && _b !== void 0 ? _b : []);
|
|
42
43
|
parentKids.add(id);
|
|
43
44
|
childrenOf.set(parentId, parentKids);
|
|
44
45
|
var subMenuIds = isSubMenuItem ? new Set(state.subMenuIds).add(id) : state.subMenuIds;
|
|
@@ -47,18 +48,37 @@ function register(state, id, parentId, isSubMenuItem) {
|
|
|
47
48
|
if (next.pendingActiveItemId === id) {
|
|
48
49
|
return __assign(__assign({}, select(next, id, false)), { pendingActiveItemId: null });
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
if (next.activeAncestorIds.has(id)) {
|
|
52
|
+
var openNodeIds = new Set(next.openNodeIds).add(id);
|
|
53
|
+
var activeItemId = next.activeItemId;
|
|
54
|
+
if (activeItemId !== null && next.parentOf.has(activeItemId)) {
|
|
55
|
+
// Effects can register a selected child before its parents. Each ancestor
|
|
56
|
+
// that registers can extend the known path towards the top-level section.
|
|
57
|
+
var activeAncestorIds = new Set(ancestors(next, activeItemId));
|
|
58
|
+
try {
|
|
59
|
+
for (var activeAncestorIds_1 = __values(activeAncestorIds), activeAncestorIds_1_1 = activeAncestorIds_1.next(); !activeAncestorIds_1_1.done; activeAncestorIds_1_1 = activeAncestorIds_1.next()) {
|
|
60
|
+
var ancestor = activeAncestorIds_1_1.value;
|
|
61
|
+
if (next.parentOf.has(ancestor) && !next.activeAncestorIds.has(ancestor)) {
|
|
62
|
+
openNodeIds.add(ancestor);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
67
|
+
finally {
|
|
68
|
+
try {
|
|
69
|
+
if (activeAncestorIds_1_1 && !activeAncestorIds_1_1.done && (_a = activeAncestorIds_1.return)) _a.call(activeAncestorIds_1);
|
|
70
|
+
}
|
|
71
|
+
finally { if (e_2) throw e_2.error; }
|
|
72
|
+
}
|
|
73
|
+
return __assign(__assign({}, next), { activeFirstLevelParentId: (_c = firstLevelParent(next, activeItemId)) !== null && _c !== void 0 ? _c : next.activeFirstLevelParentId, activeAncestorIds: activeAncestorIds, openNodeIds: openNodeIds });
|
|
74
|
+
}
|
|
75
|
+
// The selected item can still be unmounted when its ancestors reappear.
|
|
76
|
+
return __assign(__assign({}, next), { openNodeIds: openNodeIds });
|
|
57
77
|
}
|
|
58
78
|
return next;
|
|
59
79
|
}
|
|
60
80
|
function unregister(state, id) {
|
|
61
|
-
var
|
|
81
|
+
var e_3, _a, e_4, _b, e_5, _c, e_6, _d;
|
|
62
82
|
if (!state.parentOf.has(id) || id === ROOT) {
|
|
63
83
|
return state;
|
|
64
84
|
}
|
|
@@ -74,12 +94,12 @@ function unregister(state, id) {
|
|
|
74
94
|
parentOf.delete(rid);
|
|
75
95
|
}
|
|
76
96
|
}
|
|
77
|
-
catch (
|
|
97
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
78
98
|
finally {
|
|
79
99
|
try {
|
|
80
100
|
if (idsToRemove_1_1 && !idsToRemove_1_1.done && (_a = idsToRemove_1.return)) _a.call(idsToRemove_1);
|
|
81
101
|
}
|
|
82
|
-
finally { if (
|
|
102
|
+
finally { if (e_3) throw e_3.error; }
|
|
83
103
|
}
|
|
84
104
|
var childrenOf = new Map(state.childrenOf);
|
|
85
105
|
try {
|
|
@@ -88,12 +108,12 @@ function unregister(state, id) {
|
|
|
88
108
|
childrenOf.delete(rid);
|
|
89
109
|
}
|
|
90
110
|
}
|
|
91
|
-
catch (
|
|
111
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
92
112
|
finally {
|
|
93
113
|
try {
|
|
94
114
|
if (idsToRemove_2_1 && !idsToRemove_2_1.done && (_b = idsToRemove_2.return)) _b.call(idsToRemove_2);
|
|
95
115
|
}
|
|
96
|
-
finally { if (
|
|
116
|
+
finally { if (e_4) throw e_4.error; }
|
|
97
117
|
}
|
|
98
118
|
var parentKids = childrenOf.get(parentId);
|
|
99
119
|
if (parentKids) {
|
|
@@ -112,12 +132,12 @@ function unregister(state, id) {
|
|
|
112
132
|
}
|
|
113
133
|
}
|
|
114
134
|
}
|
|
115
|
-
catch (
|
|
135
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
116
136
|
finally {
|
|
117
137
|
try {
|
|
118
138
|
if (idsToRemove_3_1 && !idsToRemove_3_1.done && (_c = idsToRemove_3.return)) _c.call(idsToRemove_3);
|
|
119
139
|
}
|
|
120
|
-
finally { if (
|
|
140
|
+
finally { if (e_5) throw e_5.error; }
|
|
121
141
|
}
|
|
122
142
|
var openNodeIds = state.openNodeIds;
|
|
123
143
|
try {
|
|
@@ -130,12 +150,12 @@ function unregister(state, id) {
|
|
|
130
150
|
}
|
|
131
151
|
}
|
|
132
152
|
}
|
|
133
|
-
catch (
|
|
153
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
134
154
|
finally {
|
|
135
155
|
try {
|
|
136
156
|
if (idsToRemove_4_1 && !idsToRemove_4_1.done && (_d = idsToRemove_4.return)) _d.call(idsToRemove_4);
|
|
137
157
|
}
|
|
138
|
-
finally { if (
|
|
158
|
+
finally { if (e_6) throw e_6.error; }
|
|
139
159
|
}
|
|
140
160
|
return __assign(__assign({}, state), { parentOf: parentOf, childrenOf: childrenOf, subMenuIds: subMenuIds, openNodeIds: openNodeIds });
|
|
141
161
|
}
|
|
@@ -162,7 +182,7 @@ function computeSeparatedShown(state, active, prevShown) {
|
|
|
162
182
|
* `isButton` only suppresses the active-item change; expansion rules are identical.
|
|
163
183
|
*/
|
|
164
184
|
function select(state, id, isButton) {
|
|
165
|
-
var
|
|
185
|
+
var e_7, _a;
|
|
166
186
|
if (!state.parentOf.has(id)) {
|
|
167
187
|
return state;
|
|
168
188
|
}
|
|
@@ -178,19 +198,19 @@ function select(state, id, isButton) {
|
|
|
178
198
|
openNodeIds.add(ancestor);
|
|
179
199
|
}
|
|
180
200
|
}
|
|
181
|
-
catch (
|
|
201
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
182
202
|
finally {
|
|
183
203
|
try {
|
|
184
204
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
185
205
|
}
|
|
186
|
-
finally { if (
|
|
206
|
+
finally { if (e_7) throw e_7.error; }
|
|
187
207
|
}
|
|
188
208
|
var nextActive = isButton ? state.activeItemId : id;
|
|
189
209
|
var next = __assign(__assign({}, state), { openNodeIds: openNodeIds, activeItemId: nextActive, activeFirstLevelParentId: nextActive !== null ? firstLevelParent(state, nextActive) : null, activeAncestorIds: nextActive !== null ? new Set(ancestors(state, nextActive)) : new Set() });
|
|
190
210
|
return __assign(__assign({}, next), { separatedMenuShown: computeSeparatedShown(next, nextActive, state.separatedMenuShown) });
|
|
191
211
|
}
|
|
192
212
|
function closeNode(state, id) {
|
|
193
|
-
var
|
|
213
|
+
var e_8, _a;
|
|
194
214
|
if (!state.openNodeIds.has(id)) {
|
|
195
215
|
return state;
|
|
196
216
|
}
|
|
@@ -202,12 +222,12 @@ function closeNode(state, id) {
|
|
|
202
222
|
openNodeIds.delete(descendant);
|
|
203
223
|
}
|
|
204
224
|
}
|
|
205
|
-
catch (
|
|
225
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
206
226
|
finally {
|
|
207
227
|
try {
|
|
208
228
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
209
229
|
}
|
|
210
|
-
finally { if (
|
|
230
|
+
finally { if (e_8) throw e_8.error; }
|
|
211
231
|
}
|
|
212
232
|
// Collapsing a top-level section in separated mode also hides the separated column,
|
|
213
233
|
// so the root stops reserving the column's double-width space.
|
|
@@ -221,11 +241,11 @@ function setActiveItem(state, id) {
|
|
|
221
241
|
return __assign(__assign({}, state), { activeItemId: null, activeFirstLevelParentId: null, activeAncestorIds: new Set(), separatedMenuShown: false, pendingActiveItemId: null });
|
|
222
242
|
}
|
|
223
243
|
if (state.activeItemId === id) {
|
|
224
|
-
return state;
|
|
244
|
+
return state.pendingActiveItemId === null ? state : __assign(__assign({}, state), { pendingActiveItemId: null });
|
|
225
245
|
}
|
|
226
246
|
// Node not registered yet (controlled prop set before mount): defer until it registers.
|
|
227
247
|
if (!state.parentOf.has(id)) {
|
|
228
|
-
return __assign(__assign({}, state), { pendingActiveItemId: id
|
|
248
|
+
return __assign(__assign({}, state), { pendingActiveItemId: id });
|
|
229
249
|
}
|
|
230
250
|
return __assign(__assign({}, select(state, id, false)), { pendingActiveItemId: null });
|
|
231
251
|
}
|