@skbkontur/side-menu 3.0.6 → 3.1.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/useMemoIcon.d.ts +6 -1
- package/hooks/useMemoIcon.js +3 -2
- package/package.json +2 -2
- package/src/internal/ClickableElement.js +21 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.1.0](https://git.skbkontur.ru/ui/ui-parking/compare/@skbkontur/side-menu@3.0.6...@skbkontur/side-menu@3.1.0) (2024-12-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **SideMenu:** collapsible menu items ([13f7caa](https://git.skbkontur.ru/ui/ui-parking/commits/13f7caa1979361150bceb372fbdbe427f3da273d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [3.0.6](https://git.skbkontur.ru/ui/ui-parking/compare/@skbkontur/side-menu@3.0.5...@skbkontur/side-menu@3.0.6) (2024-11-25)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @skbkontur/side-menu
|
package/hooks/useMemoIcon.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
interface IconParams {
|
|
3
|
+
isOpened: boolean;
|
|
4
|
+
onClick: () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const useMemoIcon: (children: React.ReactNode, { isOpened, onClick }: IconParams) => JSX.Element | undefined;
|
|
3
7
|
export declare const useMemoBorderIcon: (isCollapsed?: boolean | undefined) => JSX.Element;
|
|
8
|
+
export {};
|
package/hooks/useMemoIcon.js
CHANGED
|
@@ -2,11 +2,12 @@ import React, { useMemo } from 'react';
|
|
|
2
2
|
import { ArrowCDownIcon16Regular } from '@skbkontur/icons/icons/ArrowCDownIcon/ArrowCDownIcon16Regular';
|
|
3
3
|
import { ArrowCRightIcon16Regular } from '@skbkontur/icons/icons/ArrowCRightIcon/ArrowCRightIcon16Regular';
|
|
4
4
|
import { ArrowCLeftIcon16Regular } from '@skbkontur/icons/icons/ArrowCLeftIcon/ArrowCLeftIcon16Regular';
|
|
5
|
-
export var useMemoIcon = function (children,
|
|
5
|
+
export var useMemoIcon = function (children, _a) {
|
|
6
|
+
var isOpened = _a.isOpened, onClick = _a.onClick;
|
|
6
7
|
return useMemo(function () {
|
|
7
8
|
if (children) {
|
|
8
9
|
if (isOpened) {
|
|
9
|
-
return React.createElement(ArrowCDownIcon16Regular,
|
|
10
|
+
return React.createElement(ArrowCDownIcon16Regular, { onClick: onClick });
|
|
10
11
|
}
|
|
11
12
|
else {
|
|
12
13
|
return React.createElement(ArrowCRightIcon16Regular, null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skbkontur/side-menu",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@skbkontur/react-ui": "5.0.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@skbkontur/icons": "^1.14.
|
|
25
|
+
"@skbkontur/icons": "^1.14.2",
|
|
26
26
|
"@skbkontur/react-ui-addons": "^5.1.0",
|
|
27
27
|
"tslib": "^1"
|
|
28
28
|
}
|
|
@@ -73,7 +73,7 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
var handleClick = function (e) {
|
|
76
|
-
var _a, _b, _c;
|
|
76
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
77
77
|
if (disabled) {
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
@@ -81,11 +81,17 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
81
81
|
if (_isBackButton || _isDropdown) {
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
|
-
(_a = context.navigation) === null || _a === void 0 ? void 0 : _a.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
var item = (_b = (_a = context.navigation) === null || _a === void 0 ? void 0 : _a.navigationTree) === null || _b === void 0 ? void 0 : _b.find(currentId);
|
|
85
|
+
if (isOpened && !((_c = item === null || item === void 0 ? void 0 : item.value) === null || _c === void 0 ? void 0 : _c.isSubMenu)) {
|
|
86
|
+
(_d = item === null || item === void 0 ? void 0 : item.value) === null || _d === void 0 ? void 0 : _d.setIsOpened(false);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
(_e = context.navigation) === null || _e === void 0 ? void 0 : _e.switchActiveMenuItem(currentId, isButton);
|
|
90
|
+
var lastElementInTheHierarchy = !_isDropdown && !_isBackButton && !((_g = (_f = context.navigation) === null || _f === void 0 ? void 0 : _f.activeMenuItemTreeNode) === null || _g === void 0 ? void 0 : _g.hasChildren);
|
|
91
|
+
toggleIsShown(lastElementInTheHierarchy);
|
|
92
|
+
setIsMinimized(lastElementInTheHierarchy);
|
|
93
|
+
setMouseIsOutside(lastElementInTheHierarchy);
|
|
94
|
+
}
|
|
89
95
|
};
|
|
90
96
|
var handleFocus = function (e) {
|
|
91
97
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
|
|
@@ -103,6 +109,14 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
103
109
|
var isHighlighted = isActive ||
|
|
104
110
|
(isFirstLevelParentOfActiveMenuItem && !context.isOpened && context.isCollapsable) ||
|
|
105
111
|
(isFirstLevelParentOfActiveMenuItem && context.isSeparatedMenu);
|
|
112
|
+
var handleCollapse = function (e) {
|
|
113
|
+
var _a, _b, _c, _d;
|
|
114
|
+
if (disabled) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
e.stopPropagation();
|
|
118
|
+
(_d = (_c = (_b = (_a = context.navigation) === null || _a === void 0 ? void 0 : _a.navigationTree) === null || _b === void 0 ? void 0 : _b.find(currentId)) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.setIsOpened(false);
|
|
119
|
+
};
|
|
106
120
|
var newProps = __assign({ className: cx((_b = {},
|
|
107
121
|
_b[jsStyles.root(theme)] = true,
|
|
108
122
|
_b[jsStyles.rootButton(theme)] = isButton,
|
|
@@ -113,7 +127,7 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
113
127
|
_b[jsStyles.activeRootSubItemInSeparatedSubMenu(theme)] = isActive && context.isSeparatedMenu && _isSubMenu,
|
|
114
128
|
_b), className), onClick: handleClick, onFocus: handleFocus, onBlur: handleBlur, children: (React.createElement(ItemContent, { _isSubMenu: _isSubMenu,
|
|
115
129
|
// @ts-expect-error: SideMenuItem should have icon
|
|
116
|
-
icon: _isSubMenu && !_isBackButton ? useMemoIcon(children, isOpened) : icon, isNestedSubMenu: isNestedSubMenu, caption: caption, subCaption: subCaption, marker: marker, _isBackButton: _isBackButton, _isDropdown: _isDropdown, _isAvatar: _isAvatar, disabled: disabled })), ref: ref, href: href }, rest);
|
|
130
|
+
icon: _isSubMenu && !_isBackButton ? useMemoIcon(children, { isOpened: isOpened, onClick: handleCollapse }) : icon, isNestedSubMenu: isNestedSubMenu, caption: caption, subCaption: subCaption, marker: marker, _isBackButton: _isBackButton, _isDropdown: _isDropdown, _isAvatar: _isAvatar, disabled: disabled })), ref: ref, href: href }, rest);
|
|
117
131
|
return (React.createElement(Component, __assign({ "data-tid": SideMenuDataTids.clickableElement }, (_c = {}, _c[navigationAttribute] = currentId, _c)),
|
|
118
132
|
React.cloneElement(React.createElement(Tag, { state: isActive ? 'active' : undefined }), children
|
|
119
133
|
? __assign(__assign({}, newProps), { 'aria-expanded': children ? isOpened : undefined, 'aria-controls': children ? currentId : undefined }) : __assign({}, newProps)),
|