@skbkontur/side-menu 3.3.3 → 3.3.5-19a67.0
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 +11 -0
- package/hooks/useAnimateOnMount.js +8 -9
- package/hooks/useMemoIcon.js +9 -10
- package/index.js +1 -1
- package/internal/themes/SideMenuTheme.js +200 -278
- package/lib/theming/ThemeHelpers.js +23 -38
- package/lib/utils/memo.js +3 -3
- package/lib/utils/scripts.js +4 -4
- package/package.json +3 -3
- package/src/Navigation.js +73 -118
- package/src/SideMenu/SideMenu.js +175 -181
- package/src/SideMenu/SideMenu.styles.js +140 -71
- package/src/SideMenuAvatar/SideMenuAvatar.d.ts +1 -1
- package/src/SideMenuAvatar/SideMenuAvatar.js +9 -10
- package/src/SideMenuBody/SideMenuBody.js +16 -18
- package/src/SideMenuBody/SideMenuBody.styles.js +13 -9
- package/src/SideMenuContext.d.ts +1 -1
- package/src/SideMenuContext.js +1 -1
- package/src/SideMenuDivider/SideMenuDivider.js +9 -11
- package/src/SideMenuDivider/SideMenuDivider.styles.js +10 -7
- package/src/SideMenuDropdown/SideMenuDropdown.d.ts +1 -1
- package/src/SideMenuDropdown/SideMenuDropdown.js +29 -33
- package/src/SideMenuDropdown/SideMenuDropdown.styles.js +21 -14
- package/src/SideMenuFooter/SideMenuFooter.js +19 -21
- package/src/SideMenuFooter/SideMenuFooter.styles.js +21 -11
- package/src/SideMenuHeader/SideMenuHeader.js +24 -28
- package/src/SideMenuHeader/SideMenuHeader.styles.js +30 -15
- package/src/SideMenuItem/SideMenuItem.js +5 -6
- package/src/SideMenuLink/SideMenuLink.js +7 -9
- package/src/SideMenuLink/SideMenuLink.styles.js +7 -6
- package/src/SideMenuNotifications/BellWidget.js +50 -71
- package/src/SideMenuNotifications/BellWidgetError.js +12 -13
- package/src/SideMenuNotifications/BellWidgetView.styles.js +43 -18
- package/src/SideMenuNotifications/SideMenuNotifications.js +22 -23
- package/src/SideMenuNotifications/utils/getNotificationsErrorMessages.js +11 -11
- package/src/SideMenuOrganisations/SideMenuOrganisations.js +5 -6
- package/src/SideMenuSubItem/SideMenuSubItem.js +5 -6
- package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.js +14 -16
- package/src/SideMenuSubItemHeader/SideMenuSubItemHeader.styles.js +14 -9
- package/src/SideMenuSubLink/SideMenuSubLink.js +5 -5
- package/src/Tree.js +34 -110
- package/src/internal/BackButton.js +13 -16
- package/src/internal/Backdrop.js +13 -11
- package/src/internal/Backdrop.styles.js +12 -7
- package/src/internal/Burger.js +11 -11
- package/src/internal/Burger.styles.js +10 -8
- package/src/internal/ClickableElement.js +90 -82
- package/src/internal/ClickableElement.styles.js +44 -20
- package/src/internal/InnerSubMenu.js +12 -14
- package/src/internal/ItemContent/Caption.js +43 -47
- package/src/internal/ItemContent/Caption.styles.js +78 -33
- package/src/internal/ItemContent/Icon.js +24 -26
- package/src/internal/ItemContent/Icon.styles.js +45 -19
- package/src/internal/ItemContent/ItemContent.js +37 -40
- package/src/internal/ItemContent/ItemContent.styles.js +61 -27
- package/src/internal/ItemContent/Marker.js +19 -21
- package/src/internal/ItemContent/Marker.styles.js +55 -21
- package/src/internal/NestedMenu.js +17 -19
- package/src/internal/NestedMenu.styles.js +7 -7
- package/src/internal/RightBorder.js +21 -22
- package/src/internal/RightBorder.styles.js +22 -9
- package/src/internal/SeparatedSubMenu.js +43 -48
- package/src/internal/SeparatedSubMenu.styles.js +53 -27
- package/src/internal/SideMenuLogotype.js +43 -47
- package/src/internal/SideMenuLogotype.styles.js +44 -20
- package/src/internal/SubMenu.js +10 -12
|
@@ -1,148 +1,156 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClickableElement = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const keyListener_1 = require("@skbkontur/react-ui/lib/events/keyListener");
|
|
7
|
+
const Emotion_1 = require("@skbkontur/react-ui/lib/theming/Emotion");
|
|
8
|
+
const ThemeContext_1 = require("@skbkontur/react-ui/lib/theming/ThemeContext");
|
|
9
|
+
const ThemeHelpers_1 = require("../../lib/theming/ThemeHelpers");
|
|
10
|
+
const SideMenuContext_1 = require("../SideMenuContext");
|
|
11
|
+
const useMemoIcon_1 = require("../../hooks/useMemoIcon");
|
|
12
|
+
const SideMenuDataTids_1 = require("../../SideMenuDataTids");
|
|
13
|
+
const Navigation_1 = require("../Navigation");
|
|
14
|
+
const scripts_1 = require("../../lib/utils/scripts");
|
|
15
|
+
const ClickableElement_styles_1 = require("./ClickableElement.styles");
|
|
16
|
+
const SubMenu_1 = require("./SubMenu");
|
|
17
|
+
const ItemContent_1 = require("./ItemContent/ItemContent");
|
|
18
18
|
/**
|
|
19
19
|
* Элемент списка (пункт меню либо ссылка)
|
|
20
20
|
*
|
|
21
21
|
* @visibleName ClickableElement
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var _k = tslib_1.__read((0, react_1.useState)(id || href || ''), 2), currentId = _k[0], setCurrentId = _k[1];
|
|
35
|
-
(0, react_1.useEffect)(function () {
|
|
36
|
-
var _a;
|
|
23
|
+
const ClickableElement = (0, react_1.forwardRef)(({ onClick, icon, marker, caption, subCaption, id, _isSubMenu, children, element: Tag, onKeyDown, onFocus, onBlur, className, _isDropdown, _isBackButton, _isAvatar, isButton, href, disabled, ...rest }, ref) => {
|
|
24
|
+
const context = (0, react_1.useContext)(SideMenuContext_1.SideMenuContext);
|
|
25
|
+
const theme = (0, ThemeHelpers_1.getSideMenuTheme)((0, react_1.useContext)(ThemeContext_1.ThemeContext));
|
|
26
|
+
const [isActive, setIsActive] = (0, react_1.useState)(false);
|
|
27
|
+
const [isFirstLevelParentOfActiveMenuItem, setIsFirstLevelParentOfActiveMenuItem] = (0, react_1.useState)(false);
|
|
28
|
+
const [isOpened, setIsOpened] = (0, react_1.useState)(false);
|
|
29
|
+
const [isNestedSubMenu, setIsNestedSubMenu] = (0, react_1.useState)(false);
|
|
30
|
+
const [hasSubIcons, setHasSubIcons] = (0, react_1.useState)(false);
|
|
31
|
+
const [isFocusedByTab, setIsFocusedByTab] = (0, react_1.useState)(false);
|
|
32
|
+
const [currentId, setCurrentId] = (0, react_1.useState)(id || href || '');
|
|
33
|
+
(0, react_1.useEffect)(() => {
|
|
37
34
|
if (!currentId) {
|
|
38
|
-
|
|
35
|
+
const generatedId = (0, scripts_1.generateId)();
|
|
39
36
|
setCurrentId(generatedId);
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
setIsActive
|
|
43
|
-
setIsOpened
|
|
38
|
+
context.navigation?.addValue(currentId, {
|
|
39
|
+
setIsActive,
|
|
40
|
+
setIsOpened,
|
|
44
41
|
isSubMenu: _isSubMenu,
|
|
45
|
-
setIsNestedSubMenu
|
|
46
|
-
setHasSubIcons
|
|
47
|
-
setIsFirstLevelParentOfActiveMenuItem
|
|
42
|
+
setIsNestedSubMenu,
|
|
43
|
+
setHasSubIcons,
|
|
44
|
+
setIsFirstLevelParentOfActiveMenuItem,
|
|
48
45
|
});
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
(_a = context.navigation) === null || _a === void 0 ? void 0 : _a.updateNavigationTree();
|
|
46
|
+
return () => {
|
|
47
|
+
context.navigation?.updateNavigationTree();
|
|
52
48
|
};
|
|
53
49
|
});
|
|
54
|
-
|
|
55
|
-
var _a;
|
|
50
|
+
const toggleIsShown = (lastElementInTheHierarchy) => {
|
|
56
51
|
if ((context.isMobile || context.isTablet) && lastElementInTheHierarchy) {
|
|
57
|
-
|
|
52
|
+
context.toggleIsOpened?.();
|
|
58
53
|
}
|
|
59
54
|
};
|
|
60
|
-
|
|
61
|
-
var _a, _b;
|
|
55
|
+
const setIsMinimized = (lastElementInTheHierarchy) => {
|
|
62
56
|
if (context.isMobile || context.isTablet || (context.isDesktop && !context.isCollapsable)) {
|
|
63
57
|
return;
|
|
64
58
|
}
|
|
65
|
-
|
|
59
|
+
const topLevelItemInSeparatedSideMenu = context.isSeparatedMenu && !_isSubMenu && children;
|
|
66
60
|
if (context.isCollapsable && (lastElementInTheHierarchy || topLevelItemInSeparatedSideMenu)) {
|
|
67
|
-
|
|
61
|
+
context.setIsMinimized?.(true);
|
|
68
62
|
}
|
|
69
63
|
if (!_isSubMenu) {
|
|
70
|
-
|
|
64
|
+
context.setIsMinimized?.(false);
|
|
71
65
|
}
|
|
72
66
|
};
|
|
73
|
-
|
|
74
|
-
var _a;
|
|
67
|
+
const setMouseIsOutside = (lastElementInTheHierarchy) => {
|
|
75
68
|
if (lastElementInTheHierarchy) {
|
|
76
|
-
|
|
69
|
+
context.setIsMouseOutside?.(true);
|
|
77
70
|
}
|
|
78
71
|
};
|
|
79
|
-
|
|
80
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
72
|
+
const handleClick = (e) => {
|
|
81
73
|
if (disabled) {
|
|
82
74
|
return;
|
|
83
75
|
}
|
|
84
|
-
onClick
|
|
76
|
+
onClick?.(e);
|
|
85
77
|
if (_isBackButton || _isDropdown) {
|
|
86
78
|
return;
|
|
87
79
|
}
|
|
88
|
-
|
|
89
|
-
if (isButton && !
|
|
80
|
+
const item = context.navigation?.navigationTree?.find(currentId);
|
|
81
|
+
if (isButton && !item?.hasChildren) {
|
|
90
82
|
return;
|
|
91
83
|
}
|
|
92
|
-
if (isOpened && !
|
|
93
|
-
|
|
84
|
+
if (isOpened && !item?.value?.isSubMenu && !context.isSeparatedMenu) {
|
|
85
|
+
item?.value?.setIsOpened(false);
|
|
94
86
|
}
|
|
95
87
|
else {
|
|
96
|
-
|
|
97
|
-
|
|
88
|
+
context.navigation?.switchActiveMenuItem(currentId, isButton);
|
|
89
|
+
const lastElementInTheHierarchy = !_isDropdown && !_isBackButton && !context.navigation?.activeMenuItemTreeNode?.hasChildren;
|
|
98
90
|
toggleIsShown(lastElementInTheHierarchy);
|
|
99
91
|
setIsMinimized(lastElementInTheHierarchy);
|
|
100
92
|
setMouseIsOutside(lastElementInTheHierarchy);
|
|
101
93
|
}
|
|
102
94
|
};
|
|
103
|
-
|
|
104
|
-
onFocus
|
|
105
|
-
requestAnimationFrame(
|
|
95
|
+
const handleFocus = (e) => {
|
|
96
|
+
onFocus?.(e);
|
|
97
|
+
requestAnimationFrame(() => {
|
|
106
98
|
if (keyListener_1.keyListener.isTabPressed) {
|
|
107
99
|
setIsFocusedByTab(true);
|
|
108
100
|
}
|
|
109
101
|
});
|
|
110
102
|
};
|
|
111
|
-
|
|
112
|
-
onBlur
|
|
103
|
+
const handleBlur = (e) => {
|
|
104
|
+
onBlur?.(e);
|
|
113
105
|
setIsFocusedByTab(false);
|
|
114
106
|
};
|
|
115
|
-
|
|
116
|
-
|
|
107
|
+
const Component = _isSubMenu || _isDropdown ? 'div' : 'li';
|
|
108
|
+
const isHighlighted = isActive ||
|
|
117
109
|
(isFirstLevelParentOfActiveMenuItem && !context.isOpened && context.isCollapsable) ||
|
|
118
110
|
(isFirstLevelParentOfActiveMenuItem && context.isSeparatedMenu);
|
|
119
|
-
|
|
120
|
-
var _a, _b, _c, _d;
|
|
111
|
+
const handleCollapse = (e) => {
|
|
121
112
|
if (disabled) {
|
|
122
113
|
return;
|
|
123
114
|
}
|
|
124
115
|
e.stopPropagation();
|
|
125
|
-
|
|
116
|
+
context.navigation?.navigationTree?.find(currentId)?.value?.setIsOpened(false);
|
|
126
117
|
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
118
|
+
const newProps = {
|
|
119
|
+
className: (0, Emotion_1.cx)({
|
|
120
|
+
[ClickableElement_styles_1.jsStyles.root(theme)]: true,
|
|
121
|
+
[ClickableElement_styles_1.jsStyles.rootButton(theme)]: isButton,
|
|
122
|
+
[ClickableElement_styles_1.jsStyles.rootSubItemInSeparatedSubMenu(theme)]: context.isSeparatedMenu && _isSubMenu,
|
|
123
|
+
[ClickableElement_styles_1.jsStyles.focusedRoot(theme)]: isFocusedByTab,
|
|
124
|
+
[ClickableElement_styles_1.jsStyles.disabledRoot(theme)]: disabled,
|
|
125
|
+
[ClickableElement_styles_1.jsStyles.activeRoot(theme)]: isHighlighted,
|
|
126
|
+
[ClickableElement_styles_1.jsStyles.activeRootSubItemInSeparatedSubMenu(theme)]: isActive && context.isSeparatedMenu && _isSubMenu,
|
|
127
|
+
}, className),
|
|
128
|
+
onClick: handleClick,
|
|
129
|
+
onFocus: handleFocus,
|
|
130
|
+
onBlur: handleBlur,
|
|
131
|
+
children: (react_1.default.createElement(ItemContent_1.ItemContent, { _isSubMenu: _isSubMenu,
|
|
136
132
|
// @ts-expect-error: SideMenuItem should have icon
|
|
137
|
-
icon: _isSubMenu && !_isBackButton ? (0, useMemoIcon_1.useMemoIcon)(children, { isOpened
|
|
138
|
-
|
|
133
|
+
icon: _isSubMenu && !_isBackButton ? (0, useMemoIcon_1.useMemoIcon)(children, { isOpened, onClick: handleCollapse }) : icon, isNestedSubMenu: isNestedSubMenu, caption: caption, subCaption: subCaption, marker: marker, _isBackButton: _isBackButton, _isDropdown: _isDropdown, _isAvatar: _isAvatar, disabled: disabled })),
|
|
134
|
+
ref,
|
|
135
|
+
href,
|
|
136
|
+
...rest,
|
|
137
|
+
};
|
|
138
|
+
return (react_1.default.createElement(Component, { "data-tid": SideMenuDataTids_1.SideMenuDataTids.clickableElement, [Navigation_1.navigationAttribute]: currentId },
|
|
139
139
|
react_1.default.cloneElement(react_1.default.createElement(Tag, { state: isActive ? 'active' : undefined }), children
|
|
140
|
-
?
|
|
140
|
+
? {
|
|
141
|
+
...newProps,
|
|
142
|
+
'aria-expanded': children ? isOpened : undefined,
|
|
143
|
+
'aria-controls': children ? currentId : undefined,
|
|
144
|
+
}
|
|
145
|
+
: { ...newProps }),
|
|
141
146
|
react_1.default.createElement(SubMenu_1.SubMenu, { caption: caption, isSubMenu: _isSubMenu, isSeparatedMenu: context.isSeparatedMenu, htmlId: currentId, isOpened: isOpened },
|
|
142
|
-
react_1.default.createElement(SideMenuContext_1.SideMenuContext.Provider, { value:
|
|
147
|
+
react_1.default.createElement(SideMenuContext_1.SideMenuContext.Provider, { value: {
|
|
148
|
+
hasSubIcons,
|
|
149
|
+
...context,
|
|
150
|
+
} }, children))));
|
|
143
151
|
});
|
|
144
152
|
ClickableElement.displayName = 'ClickableElement';
|
|
145
|
-
|
|
153
|
+
const ClickableElementWithStaticFields = Object.assign(ClickableElement, {
|
|
146
154
|
__KONTUR_REACT_UI__: 'ClickableElement',
|
|
147
155
|
});
|
|
148
156
|
exports.ClickableElement = ClickableElementWithStaticFields;
|
|
@@ -1,32 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jsStyles = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const Emotion_1 = require("@skbkontur/react-ui/lib/theming/Emotion");
|
|
5
|
+
const Mixins_1 = require("@skbkontur/react-ui/lib/styles/Mixins");
|
|
6
|
+
const ThemeHelpers_1 = require("../../lib/theming/ThemeHelpers");
|
|
7
|
+
const styles = {
|
|
8
|
+
root(t) {
|
|
9
|
+
return (0, Emotion_1.css) `
|
|
10
|
+
user-select: text;
|
|
11
|
+
${(0, Mixins_1.resetButton)()};
|
|
12
|
+
width: 100%;
|
|
13
|
+
border-radius: ${t.sideMenuItemBorderRadius};
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
&:hover {
|
|
16
|
+
background: ${t.sideMenuItemHoverBg};
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
11
19
|
},
|
|
12
|
-
rootButton
|
|
13
|
-
return (0, Emotion_1.css)
|
|
20
|
+
rootButton(t) {
|
|
21
|
+
return (0, Emotion_1.css) `
|
|
22
|
+
&:active {
|
|
23
|
+
background: ${t.sideMenuItemActiveBg};
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
14
26
|
},
|
|
15
|
-
rootSubItemInSeparatedSubMenu
|
|
16
|
-
return (0, Emotion_1.css)
|
|
27
|
+
rootSubItemInSeparatedSubMenu(t) {
|
|
28
|
+
return (0, Emotion_1.css) `
|
|
29
|
+
&:hover {
|
|
30
|
+
background: ${t.sideMenuSubItemWithSeparatedSubMenuHoverBg};
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
17
33
|
},
|
|
18
|
-
focusedRoot
|
|
19
|
-
return (0, Emotion_1.css)
|
|
34
|
+
focusedRoot(t) {
|
|
35
|
+
return (0, Emotion_1.css) `
|
|
36
|
+
box-shadow: ${t.sideMenuFocusedItemBoxShadow};
|
|
37
|
+
`;
|
|
20
38
|
},
|
|
21
|
-
disabledRoot
|
|
22
|
-
return (0, Emotion_1.css)
|
|
39
|
+
disabledRoot(t) {
|
|
40
|
+
return (0, Emotion_1.css) `
|
|
41
|
+
color: ${t.sideMenuItemDisabledColor};
|
|
42
|
+
pointer-events: none;
|
|
43
|
+
`;
|
|
23
44
|
},
|
|
24
|
-
activeRoot
|
|
25
|
-
return (0, Emotion_1.css)
|
|
45
|
+
activeRoot(t) {
|
|
46
|
+
return (0, Emotion_1.css) `
|
|
47
|
+
background: ${t.sideMenuItemActiveBg} !important;
|
|
48
|
+
`;
|
|
26
49
|
},
|
|
27
|
-
activeRootSubItemInSeparatedSubMenu
|
|
28
|
-
return (0, Emotion_1.css)
|
|
50
|
+
activeRootSubItemInSeparatedSubMenu(t) {
|
|
51
|
+
return (0, Emotion_1.css) `
|
|
52
|
+
background: ${t.sideMenuSubItemWithSeparatedSubMenuActiveBg} !important;
|
|
53
|
+
`;
|
|
29
54
|
},
|
|
30
55
|
};
|
|
31
56
|
exports.jsStyles = (0, ThemeHelpers_1.memoizeStyle)(styles);
|
|
32
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InnerSubMenu = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const Emotion_1 = require("@skbkontur/react-ui/lib/theming/Emotion");
|
|
7
|
+
const SideMenu_styles_1 = require("../SideMenu/SideMenu.styles");
|
|
8
|
+
const SideMenuContext_1 = require("../SideMenuContext");
|
|
9
9
|
/**
|
|
10
10
|
* Подменю, раскрывающееся внутри основного меню
|
|
11
11
|
*
|
|
12
12
|
* @visibleName InnerSubMenu
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
_b[SideMenu_styles_1.jsStylesForSideMenu.hidden()] = !isOpened || !context.isOpened,
|
|
21
|
-
_b)) }, children));
|
|
14
|
+
const InnerSubMenu = (0, react_1.forwardRef)(({ children, htmlId, isOpened }, ref) => {
|
|
15
|
+
const context = (0, react_1.useContext)(SideMenuContext_1.SideMenuContext);
|
|
16
|
+
return (react_1.default.createElement("ul", { ref: ref, id: htmlId, className: (0, Emotion_1.cx)({
|
|
17
|
+
[SideMenu_styles_1.jsStylesForSideMenu.list()]: true,
|
|
18
|
+
[SideMenu_styles_1.jsStylesForSideMenu.hidden()]: !isOpened || !context.isOpened,
|
|
19
|
+
}) }, children));
|
|
22
20
|
});
|
|
23
21
|
InnerSubMenu.displayName = 'InnerSubMenu';
|
|
24
|
-
|
|
22
|
+
const InnerSubMenuWithStaticFields = Object.assign(InnerSubMenu, { __KONTUR_REACT_UI__: 'InnerSubMenu' });
|
|
25
23
|
exports.InnerSubMenu = InnerSubMenuWithStaticFields;
|
|
@@ -1,44 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Caption = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Emotion_1 = require("@skbkontur/react-ui/lib/theming/Emotion");
|
|
6
|
+
const ThemeContext_1 = require("@skbkontur/react-ui/lib/theming/ThemeContext");
|
|
7
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
8
|
+
const SideMenuContext_1 = require("../../SideMenuContext");
|
|
9
|
+
const ThemeHelpers_1 = require("../../../lib/theming/ThemeHelpers");
|
|
10
|
+
const Caption_styles_1 = require("./Caption.styles");
|
|
11
|
+
const getTruncatedUserName = (caption, visibleWidth, fullWidth) => {
|
|
12
|
+
const [firstName, lastName] = caption.split(' ');
|
|
13
13
|
if (visibleWidth < fullWidth && lastName) {
|
|
14
|
-
return
|
|
14
|
+
return `${firstName} ${lastName[0]}.`;
|
|
15
15
|
}
|
|
16
16
|
return caption;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
const getCaptionTail = (caption, visibleWidth, fullWidth) => {
|
|
19
19
|
if (visibleWidth < fullWidth) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const symbolsCount = caption.length;
|
|
21
|
+
const symbolLength = fullWidth / symbolsCount;
|
|
22
|
+
const halfVisibleSymbols = visibleWidth / symbolLength / 2;
|
|
23
23
|
return caption.slice(symbolsCount - halfVisibleSymbols);
|
|
24
24
|
}
|
|
25
25
|
return '';
|
|
26
26
|
};
|
|
27
|
-
exports.Caption = (0, react_1.forwardRef)(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var isCaptionPlainText = typeof caption === 'string';
|
|
35
|
-
(0, react_1.useEffect)(function () {
|
|
27
|
+
exports.Caption = (0, react_1.forwardRef)(({ _isSubMenu, isNestedSubMenu, hasIcon, caption, subCaption, isMultiline, _isBackButton, _isDropdown, _isAvatar }, ref) => {
|
|
28
|
+
const theme = (0, ThemeHelpers_1.getSideMenuTheme)((0, react_1.useContext)(ThemeContext_1.ThemeContext));
|
|
29
|
+
const { isBeingTransitioned, isSeparatedMenu, size, isTouchScreen, hasSubIcons } = (0, react_1.useContext)(SideMenuContext_1.SideMenuContext);
|
|
30
|
+
const captionRef = (0, react_1.useRef)(null);
|
|
31
|
+
const [tail, setTail] = (0, react_1.useState)('');
|
|
32
|
+
const isCaptionPlainText = typeof caption === 'string';
|
|
33
|
+
(0, react_1.useEffect)(() => {
|
|
36
34
|
if (!_isDropdown || !captionRef.current || !caption || !isCaptionPlainText) {
|
|
37
35
|
return;
|
|
38
36
|
}
|
|
39
37
|
captionRef.current.innerText = caption;
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const fullWidth = captionRef.current.scrollWidth;
|
|
39
|
+
const visibleWidth = captionRef.current.offsetWidth;
|
|
42
40
|
if (_isAvatar) {
|
|
43
41
|
captionRef.current.innerText = getTruncatedUserName(caption, visibleWidth, fullWidth);
|
|
44
42
|
}
|
|
@@ -46,32 +44,30 @@ exports.Caption = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
46
44
|
setTail(getCaptionTail(caption, visibleWidth, fullWidth));
|
|
47
45
|
}
|
|
48
46
|
}, [isBeingTransitioned, caption]);
|
|
49
|
-
|
|
50
|
-
if (userName === void 0) { userName = ''; }
|
|
51
|
-
if (_isAvatar === void 0) { _isAvatar = false; }
|
|
47
|
+
const isAvatarCaptionSingleWord = (userName = '', _isAvatar = false) => {
|
|
52
48
|
return _isAvatar && userName.split(' ').length === 1;
|
|
53
49
|
};
|
|
54
|
-
|
|
55
|
-
return (react_1.default.createElement("div", { className: (0, Emotion_1.cx)(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
react_1.default.createElement(Component, { className: (0, Emotion_1.cx)(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
const Component = isCaptionPlainText ? 'p' : 'div';
|
|
51
|
+
return (react_1.default.createElement("div", { className: (0, Emotion_1.cx)({
|
|
52
|
+
[Caption_styles_1.jsStyles.root()]: true,
|
|
53
|
+
[Caption_styles_1.jsStyles.rootMultiline()]: isMultiline && !_isSubMenu,
|
|
54
|
+
}), ref: ref },
|
|
55
|
+
react_1.default.createElement(Component, { className: (0, Emotion_1.cx)({
|
|
56
|
+
[Caption_styles_1.jsStyles.caption(theme)]: true,
|
|
57
|
+
[Caption_styles_1.jsStyles.captionDropdown()]: _isDropdown,
|
|
58
|
+
[Caption_styles_1.jsStyles.captionTruncated()]: isCaptionPlainText &&
|
|
63
59
|
_isDropdown &&
|
|
64
60
|
(!_isAvatar || isAvatarCaptionSingleWord(caption, _isAvatar)),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
[Caption_styles_1.jsStyles.captionSubItem(theme)]: _isSubMenu,
|
|
62
|
+
[Caption_styles_1.jsStyles.captionSubItemSeparatedMenuTopLevel()]: isSeparatedMenu && !isNestedSubMenu && _isSubMenu && !hasIcon,
|
|
63
|
+
[Caption_styles_1.jsStyles.captionNestedItemSeparatedMenu()]: isSeparatedMenu && isNestedSubMenu && !hasIcon,
|
|
64
|
+
[Caption_styles_1.jsStyles.captionWithoutItemIcon()]: !hasIcon && !isSeparatedMenu,
|
|
65
|
+
[Caption_styles_1.jsStyles.captionSubItemWithoutColumnIcons()]: _isSubMenu && isSeparatedMenu && !hasSubIcons,
|
|
66
|
+
[Caption_styles_1.jsStyles.captionLarge(theme)]: size === 'large',
|
|
67
|
+
[Caption_styles_1.jsStyles.captionForTouchScreens(theme)]: isTouchScreen,
|
|
68
|
+
[Caption_styles_1.jsStyles.captionSubItemForTouchScreens(theme)]: isTouchScreen && _isSubMenu,
|
|
69
|
+
[Caption_styles_1.jsStyles.captionInBackButton(theme)]: _isBackButton,
|
|
70
|
+
}), ref: captionRef, "data-tail": tail }, caption),
|
|
75
71
|
subCaption));
|
|
76
72
|
});
|
|
77
73
|
exports.Caption.displayName = 'Caption';
|
|
@@ -1,54 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jsStyles = exports.sideMenuCaptionMarginRight = exports.sideMenuMultilineCaptionPaddingTop = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var ThemeHelpers_1 = require("../../../lib/theming/ThemeHelpers");
|
|
4
|
+
const Emotion_1 = require("@skbkontur/react-ui/lib/theming/Emotion");
|
|
5
|
+
const ThemeHelpers_1 = require("../../../lib/theming/ThemeHelpers");
|
|
7
6
|
exports.sideMenuMultilineCaptionPaddingTop = '4px';
|
|
8
7
|
exports.sideMenuCaptionMarginRight = '8px';
|
|
9
|
-
|
|
10
|
-
root
|
|
11
|
-
return (0, Emotion_1.css)
|
|
8
|
+
const styles = {
|
|
9
|
+
root() {
|
|
10
|
+
return (0, Emotion_1.css) `
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
flex: 1;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
`;
|
|
12
16
|
},
|
|
13
|
-
rootMultiline
|
|
14
|
-
return (0, Emotion_1.css)
|
|
17
|
+
rootMultiline() {
|
|
18
|
+
return (0, Emotion_1.css) `
|
|
19
|
+
padding-top: ${exports.sideMenuMultilineCaptionPaddingTop};
|
|
20
|
+
align-self: flex-start;
|
|
21
|
+
`;
|
|
15
22
|
},
|
|
16
|
-
caption
|
|
17
|
-
return (0, Emotion_1.css)
|
|
23
|
+
caption(t) {
|
|
24
|
+
return (0, Emotion_1.css) `
|
|
25
|
+
font-size: ${t.sideMenuCaptionFontSize};
|
|
26
|
+
line-height: ${t.sideMenuCaptionLineHeight};
|
|
27
|
+
margin: 0 ${exports.sideMenuCaptionMarginRight} 0 0;
|
|
28
|
+
overflow-wrap: anywhere;
|
|
29
|
+
`;
|
|
18
30
|
},
|
|
19
|
-
captionForTouchScreens
|
|
20
|
-
return (0, Emotion_1.css)
|
|
31
|
+
captionForTouchScreens(t) {
|
|
32
|
+
return (0, Emotion_1.css) `
|
|
33
|
+
font-size: ${t.sideMenuCaptionFontSizeForTouchScreens};
|
|
34
|
+
line-height: ${t.sideMenuCaptionLineHeightForTouchScreens};
|
|
35
|
+
`;
|
|
21
36
|
},
|
|
22
|
-
captionSubItem
|
|
23
|
-
return (0, Emotion_1.css)
|
|
37
|
+
captionSubItem(t) {
|
|
38
|
+
return (0, Emotion_1.css) `
|
|
39
|
+
margin-left: ${t.sideMenuCaptionSubItemMarginLeft};
|
|
40
|
+
`;
|
|
24
41
|
},
|
|
25
|
-
captionSubItemForTouchScreens
|
|
26
|
-
return (0, Emotion_1.css)
|
|
42
|
+
captionSubItemForTouchScreens(t) {
|
|
43
|
+
return (0, Emotion_1.css) `
|
|
44
|
+
font-size: ${t.sideMenuCaptionSubItemFontSizeForTouchScreens};
|
|
45
|
+
line-height: ${t.sideMenuCaptionSubItemLineHeightForTouchScreens};
|
|
46
|
+
`;
|
|
27
47
|
},
|
|
28
|
-
captionSubItemSeparatedMenuTopLevel
|
|
29
|
-
return (0, Emotion_1.css)
|
|
48
|
+
captionSubItemSeparatedMenuTopLevel() {
|
|
49
|
+
return (0, Emotion_1.css) `
|
|
50
|
+
margin: 0 8px;
|
|
51
|
+
`;
|
|
30
52
|
},
|
|
31
|
-
captionNestedItemSeparatedMenu
|
|
32
|
-
return (0, Emotion_1.css)
|
|
53
|
+
captionNestedItemSeparatedMenu() {
|
|
54
|
+
return (0, Emotion_1.css) `
|
|
55
|
+
margin-left: 25px;
|
|
56
|
+
`;
|
|
33
57
|
},
|
|
34
|
-
captionWithoutItemIcon
|
|
35
|
-
return (0, Emotion_1.css)
|
|
58
|
+
captionWithoutItemIcon() {
|
|
59
|
+
return (0, Emotion_1.css) `
|
|
60
|
+
margin-left: 40px;
|
|
61
|
+
`;
|
|
36
62
|
},
|
|
37
|
-
captionSubItemWithoutColumnIcons
|
|
38
|
-
return (0, Emotion_1.css)
|
|
63
|
+
captionSubItemWithoutColumnIcons() {
|
|
64
|
+
return (0, Emotion_1.css) `
|
|
65
|
+
margin-left: 8px;
|
|
66
|
+
`;
|
|
39
67
|
},
|
|
40
|
-
captionLarge
|
|
41
|
-
return (0, Emotion_1.css)
|
|
68
|
+
captionLarge(t) {
|
|
69
|
+
return (0, Emotion_1.css) `
|
|
70
|
+
font-size: ${t.sideMenuCaptionLargeFontSize} !important;
|
|
71
|
+
line-height: ${t.sideMenuCaptionLargeLineHeight} !important;
|
|
72
|
+
`;
|
|
42
73
|
},
|
|
43
|
-
captionInBackButton
|
|
44
|
-
return (0, Emotion_1.css)
|
|
74
|
+
captionInBackButton(t) {
|
|
75
|
+
return (0, Emotion_1.css) `
|
|
76
|
+
font-weight: ${t.sideMenuBackButtonCaptionFontWeight};
|
|
77
|
+
font-size: ${t.sideMenuBackButtonCaptionFontSize};
|
|
78
|
+
line-height: ${t.sideMenuBackButtonCaptionLineHeight};
|
|
79
|
+
padding-top: ${t.sideMenuBackButtonCaptionPaddingY};
|
|
80
|
+
padding-bottom: ${t.sideMenuBackButtonCaptionPaddingY};
|
|
81
|
+
`;
|
|
45
82
|
},
|
|
46
|
-
captionDropdown
|
|
47
|
-
return (0, Emotion_1.css)
|
|
83
|
+
captionDropdown() {
|
|
84
|
+
return (0, Emotion_1.css) `
|
|
85
|
+
white-space: nowrap;
|
|
86
|
+
overflow: hidden;
|
|
87
|
+
`;
|
|
48
88
|
},
|
|
49
|
-
captionTruncated
|
|
50
|
-
return (0, Emotion_1.css)
|
|
89
|
+
captionTruncated() {
|
|
90
|
+
return (0, Emotion_1.css) `
|
|
91
|
+
text-overflow: ellipsis;
|
|
92
|
+
&::before {
|
|
93
|
+
float: right;
|
|
94
|
+
content: attr(data-tail);
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
51
97
|
},
|
|
52
98
|
};
|
|
53
99
|
exports.jsStyles = (0, ThemeHelpers_1.memoizeStyle)(styles);
|
|
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;
|