@skbkontur/side-menu 4.0.9 → 4.0.10-ddcb0.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/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/SideMenuTheme.d.ts +4 -0
- package/internal/themes/SideMenuTheme.js +4 -0
- package/lib/utils/scripts.d.ts +1 -0
- package/lib/utils/scripts.js +9 -0
- package/package.json +2 -1
- package/src/SideMenu/SideMenu.d.ts +7 -4
- package/src/SideMenu/SideMenu.js +148 -178
- package/src/SideMenu/SideMenu.styles.js +2 -2
- package/src/SideMenuAvatar/SideMenuAvatar.js +11 -2
- package/src/SideMenuContext.d.ts +16 -9
- package/src/SideMenuContext.js +6 -1
- package/src/SideMenuDropdown/SideMenuDropdown.js +11 -18
- package/src/SideMenuDropdown/SideMenuDropdown.styles.js +3 -3
- package/src/SideMenuFooter/SideMenuFooter.js +15 -3
- package/src/SideMenuFooter/SideMenuFooter.styles.d.ts +4 -0
- package/src/SideMenuFooter/SideMenuFooter.styles.js +16 -4
- package/src/SideMenuHeader/SideMenuHeader.js +4 -3
- package/src/SideMenuSubItem/SideMenuSubItem.d.ts +1 -1
- 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 +8 -1
- package/src/internal/ClickableElement.js +125 -67
- package/src/internal/ClickableElement.styles.d.ts +1 -0
- package/src/internal/ClickableElement.styles.js +6 -3
- package/src/internal/CollapseToggle.d.ts +1 -0
- package/src/internal/CollapseToggle.js +27 -0
- package/src/internal/{RightBorder.styles.d.ts → CollapseToggle.styles.d.ts} +0 -1
- package/src/internal/CollapseToggle.styles.js +12 -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 +13 -0
- package/src/internal/NarrowAccordionDropdown.js +34 -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 +10 -8
- 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/unstable.d.ts +1 -0
- package/unstable.js +1 -0
- package/src/Navigation.d.ts +0 -53
- package/src/Navigation.js +0 -194
- 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
|
@@ -3,20 +3,27 @@ import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment
|
|
|
3
3
|
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
4
4
|
import React, { forwardRef, useContext, useEffect, useState } from 'react';
|
|
5
5
|
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
6
|
+
import { flattenChildren } from '../../lib/utils/scripts.js';
|
|
6
7
|
import { SideMenuDataTids } from '../../SideMenuDataTids.js';
|
|
8
|
+
import { CollapseToggle } from '../internal/CollapseToggle.js';
|
|
7
9
|
import { getStyles as getSideMenuStyles } from '../SideMenu/SideMenu.styles.js';
|
|
8
10
|
import { SideMenuContext } from '../SideMenuContext.js';
|
|
9
11
|
import { getStyles } from './SideMenuFooter.styles.js';
|
|
10
12
|
var SideMenuFooterInner = forwardRef(function (_a, ref) {
|
|
11
|
-
var _b;
|
|
13
|
+
var _b, _c;
|
|
12
14
|
var className = _a.className, children = _a.children, rest = __rest(_a, ["className", "children"]);
|
|
13
15
|
var context = useContext(SideMenuContext);
|
|
14
16
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
15
17
|
var cx = useEmotion().cx;
|
|
16
18
|
var styles = useStyles(getStyles);
|
|
17
19
|
var sideMenuStyles = useStyles(getSideMenuStyles);
|
|
18
|
-
var
|
|
20
|
+
var _d = __read(useState(false), 2), isFixed = _d[0], setIsFixed = _d[1];
|
|
19
21
|
var isTabletOrMobile = context.isTablet || context.isMobile;
|
|
22
|
+
var showCollapseToggle = (context.isDesktop || context.isNarrowDesktop) && !context.disableCollapsing;
|
|
23
|
+
var showTrailingItem = showCollapseToggle && context.isOpened;
|
|
24
|
+
var footerItems = flattenChildren(children);
|
|
25
|
+
var trailingItem = showTrailingItem ? footerItems[footerItems.length - 1] : null;
|
|
26
|
+
var leadingItems = trailingItem ? footerItems.slice(0, -1) : footerItems;
|
|
20
27
|
useEffect(function () {
|
|
21
28
|
setIsFixed(!!context.hasScrollBar && !(context.scrollState === 'bottom'));
|
|
22
29
|
}, [context.hasScrollBar, context.scrollState]);
|
|
@@ -25,7 +32,12 @@ var SideMenuFooterInner = forwardRef(function (_a, ref) {
|
|
|
25
32
|
_b[styles.rootFixed(theme)] = isFixed,
|
|
26
33
|
_b[styles.rootTransitionedTabletAndMobile()] = context.isBeingTransitioned && isTabletOrMobile,
|
|
27
34
|
_b), className), ref: ref }, rest),
|
|
28
|
-
React.createElement("ul", { className: sideMenuStyles.list() },
|
|
35
|
+
leadingItems.length > 0 && React.createElement("ul", { className: cx(sideMenuStyles.list(), styles.list()) }, leadingItems),
|
|
36
|
+
(trailingItem || showCollapseToggle) && (React.createElement("div", { className: cx(styles.trailingRow(), (_c = {},
|
|
37
|
+
_c[styles.trailingRowCorner()] = !trailingItem,
|
|
38
|
+
_c)) },
|
|
39
|
+
trailingItem && (React.createElement("ul", { className: cx(sideMenuStyles.list(), styles.list(), styles.trailingItem(theme)) }, trailingItem)),
|
|
40
|
+
showCollapseToggle && React.createElement(CollapseToggle, null)))));
|
|
29
41
|
}
|
|
30
42
|
return null;
|
|
31
43
|
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { SideMenuTheme } from '../../lib/theming/ThemeTypes.js';
|
|
2
2
|
export declare const getStyles: import("../../lib/theming/ThemeHelpers.js").StylesGetter<{
|
|
3
3
|
root(t: SideMenuTheme): string;
|
|
4
|
+
list(): string;
|
|
5
|
+
trailingRow(): string;
|
|
6
|
+
trailingRowCorner(): string;
|
|
7
|
+
trailingItem(t: SideMenuTheme): string;
|
|
4
8
|
rootFixed(t: SideMenuTheme): string;
|
|
5
9
|
rootTransitionedTabletAndMobile(): string;
|
|
6
10
|
}>;
|
|
@@ -4,14 +4,26 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
4
4
|
var css = _a.css;
|
|
5
5
|
return ({
|
|
6
6
|
root: function (t) {
|
|
7
|
-
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n flex-grow: 0;\n position: sticky;\n bottom: 0;\n padding-bottom: ", ";\n padding-top: ", ";\n margin: 0 ", ";\n background-color: inherit;\n "], ["\n flex-grow: 0;\n position: sticky;\n bottom: 0;\n padding-bottom: ", ";\n padding-top: ", ";\n margin: 0 ", ";\n background-color: inherit;\n "])), t.sideMenuFooterPaddingBottom, t.sideMenuFooterPaddingTop, t.sideMenuMarginX);
|
|
7
|
+
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n flex-grow: 0;\n position: sticky;\n bottom: 0;\n padding-bottom: ", ";\n padding-top: ", ";\n margin: 0 ", ";\n background-color: inherit;\n "], ["\n display: flex;\n flex-direction: column;\n flex-grow: 0;\n position: sticky;\n bottom: 0;\n padding-bottom: ", ";\n padding-top: ", ";\n margin: 0 ", ";\n background-color: inherit;\n "])), t.sideMenuFooterPaddingBottom, t.sideMenuFooterPaddingTop, t.sideMenuMarginX);
|
|
8
|
+
},
|
|
9
|
+
list: function () {
|
|
10
|
+
return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n min-width: 0;\n "], ["\n display: flex;\n flex-direction: column;\n min-width: 0;\n "])));
|
|
11
|
+
},
|
|
12
|
+
trailingRow: function () {
|
|
13
|
+
return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n min-width: 0;\n "], ["\n display: flex;\n align-items: center;\n min-width: 0;\n "])));
|
|
14
|
+
},
|
|
15
|
+
trailingRowCorner: function () {
|
|
16
|
+
return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n justify-content: flex-end;\n "], ["\n justify-content: flex-end;\n "])));
|
|
17
|
+
},
|
|
18
|
+
trailingItem: function (t) {
|
|
19
|
+
return css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n flex: 1 1 auto;\n min-width: 0;\n --side-menu-footer-trailing-reserved-width: ", ";\n "], ["\n flex: 1 1 auto;\n min-width: 0;\n --side-menu-footer-trailing-reserved-width: ", ";\n "])), t.sideMenuCollapseToggleSize);
|
|
8
20
|
},
|
|
9
21
|
rootFixed: function (t) {
|
|
10
|
-
return css(
|
|
22
|
+
return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n box-shadow: 0 -1px 0 ", ";\n "], ["\n box-shadow: 0 -1px 0 ", ";\n "])), t.sideMenuFooterDividerColor);
|
|
11
23
|
},
|
|
12
24
|
rootTransitionedTabletAndMobile: function () {
|
|
13
|
-
return css(
|
|
25
|
+
return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n position: static;\n "], ["\n position: static;\n "])));
|
|
14
26
|
},
|
|
15
27
|
});
|
|
16
28
|
});
|
|
17
|
-
var templateObject_1, templateObject_2, templateObject_3;
|
|
29
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
|
|
@@ -7,15 +7,16 @@ import React, { forwardRef, useContext, useEffect, useRef } from 'react';
|
|
|
7
7
|
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
8
8
|
import { SideMenuLogotype } from '../internal/SideMenuLogotype.js';
|
|
9
9
|
import { SideMenuContext } from '../SideMenuContext.js';
|
|
10
|
+
import { separatedShown } from '../state/selectors.js';
|
|
10
11
|
import { getStyles } from './SideMenuHeader.styles.js';
|
|
11
12
|
var SideMenuHeaderInner = forwardRef(function (_a, ref) {
|
|
12
13
|
var _b;
|
|
13
|
-
var _c;
|
|
14
|
-
var className = _a.className, productLogo = _a.productLogo, konturLogo = _a.konturLogo, iconUrl = _a.iconUrl, style = _a.style, _d = _a.withWidget, withWidget = _d === void 0 ? true : _d, dataTid = _a["data-tid"], rest = __rest(_a, ["className", "productLogo", "konturLogo", "iconUrl", "style", "withWidget", 'data-tid']);
|
|
14
|
+
var className = _a.className, productLogo = _a.productLogo, konturLogo = _a.konturLogo, iconUrl = _a.iconUrl, style = _a.style, _c = _a.withWidget, withWidget = _c === void 0 ? true : _c, dataTid = _a["data-tid"], rest = __rest(_a, ["className", "productLogo", "konturLogo", "iconUrl", "style", "withWidget", 'data-tid']);
|
|
15
15
|
var context = useContext(SideMenuContext);
|
|
16
16
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
17
17
|
var headerWrapperRef = useRef(null);
|
|
18
18
|
var isTabletOrMobile = context.isTablet || context.isMobile;
|
|
19
|
+
var isSeparatedMenuShown = separatedShown(context.state);
|
|
19
20
|
useEffect(function () {
|
|
20
21
|
var _a;
|
|
21
22
|
if (headerWrapperRef.current) {
|
|
@@ -28,7 +29,7 @@ var SideMenuHeaderInner = forwardRef(function (_a, ref) {
|
|
|
28
29
|
_b[styles.fixedRoot(theme)] = context.isOpened && !!context.hasScrollBar && !(context.scrollState === 'top'),
|
|
29
30
|
_b[styles.rootTabletAndMobile(theme)] = isTabletOrMobile,
|
|
30
31
|
_b[styles.rootCollapsedTabletAndMobile()] = isTabletOrMobile && !context.isOpened,
|
|
31
|
-
_b[styles.rootWithSeparatedMenuShownMobile(theme)] = context.isOpened && context.isMobile &&
|
|
32
|
+
_b[styles.rootWithSeparatedMenuShownMobile(theme)] = context.isOpened && context.isMobile && isSeparatedMenuShown,
|
|
32
33
|
_b), className), ref: mergeRefs(headerWrapperRef, ref), style: style, "data-tid": dataTid },
|
|
33
34
|
React.createElement(SideMenuLogotype, __assign({ productLogo: productLogo, konturLogo: konturLogo, iconUrl: iconUrl, withWidget: withWidget }, rest))));
|
|
34
35
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { SideMenuItemProps } from '../SideMenuItem/SideMenuItem.js';
|
|
3
|
-
export interface SideMenuSubItemProps extends Omit<SideMenuItemProps, 'icon'>, Partial<Pick<SideMenuItemProps, 'icon'>> {
|
|
3
|
+
export interface SideMenuSubItemProps extends Omit<SideMenuItemProps, 'icon' | 'hint'>, Partial<Pick<SideMenuItemProps, 'icon'>> {
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* Элемент списка второго уровня
|
|
@@ -13,6 +13,7 @@ var SideMenuSubItemHeaderInner = forwardRef(function (_a, ref) {
|
|
|
13
13
|
var cx = useEmotion().cx;
|
|
14
14
|
var styles = useStyles(getStyles);
|
|
15
15
|
return (React.createElement("p", __assign({ className: cx(styles.root(theme), (_b = {},
|
|
16
|
+
_b[styles.rootInDropdown()] = !context.isOpened && !context.isSeparatedMenu,
|
|
16
17
|
_b[styles.rootInSeparatedSubMenu()] = context.isSeparatedMenu,
|
|
17
18
|
_b), className), ref: ref }, rest), children));
|
|
18
19
|
});
|
|
@@ -6,9 +6,12 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
6
6
|
root: function (t) {
|
|
7
7
|
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font-size: ", ";\n color: ", ";\n padding: ", ";\n margin: 0;\n "], ["\n font-size: ", ";\n color: ", ";\n padding: ", ";\n margin: 0;\n "])), t.sideMenuSubItemHeaderFontSize, t.sideMenuSubItemHeaderColor, t.sideMenuSubItemHeaderPadding);
|
|
8
8
|
},
|
|
9
|
+
rootInDropdown: function () {
|
|
10
|
+
return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n padding: 12px 8px 4px 8px;\n "], ["\n padding: 12px 8px 4px 8px;\n "])));
|
|
11
|
+
},
|
|
9
12
|
rootInSeparatedSubMenu: function () {
|
|
10
|
-
return css(
|
|
13
|
+
return css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n padding-left: 8px;\n "], ["\n padding-left: 8px;\n "])));
|
|
11
14
|
},
|
|
12
15
|
});
|
|
13
16
|
});
|
|
14
|
-
var templateObject_1, templateObject_2;
|
|
17
|
+
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { SideMenuLinkProps } from '../SideMenuLink/SideMenuLink.js';
|
|
3
|
-
export interface SideMenuSubLinkProps<T = string> extends Omit<SideMenuLinkProps<T>, 'icon'>, Partial<Pick<SideMenuLinkProps, 'icon'>> {
|
|
3
|
+
export interface SideMenuSubLinkProps<T = string> extends Omit<SideMenuLinkProps<T>, 'icon' | 'hint'>, Partial<Pick<SideMenuLinkProps, 'icon'>> {
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* Ссылка в подменю для `SideMenu`
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { CommonClickableElementProps } from './ClickableElement.js';
|
|
3
|
-
export
|
|
4
|
-
href?: string;
|
|
5
|
-
}
|
|
3
|
+
export type BackButtonProps = Pick<CommonClickableElementProps, 'caption' | 'id'>;
|
|
6
4
|
declare const BackButtonWithStaticFields: React.ForwardRefExoticComponent<BackButtonProps & React.RefAttributes<HTMLButtonElement>> & {
|
|
7
5
|
__KONTUR_REACT_UI__: string;
|
|
8
6
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IconArrowALeftRegular20 } from '@skbkontur/icons/IconArrowALeftRegular20';
|
|
2
2
|
import React, { forwardRef, useContext } from 'react';
|
|
3
3
|
import { SideMenuDataTids } from '../../SideMenuDataTids.js';
|
|
4
|
-
import { navigationAttributeBackButton } from '../
|
|
4
|
+
import { navigationAttributeBackButton } from '../navigationAttributes.js';
|
|
5
5
|
import { SideMenuContext } from '../SideMenuContext.js';
|
|
6
6
|
import { SideMenuItem } from '../SideMenuItem/SideMenuItem.js';
|
|
7
7
|
/**
|
|
@@ -14,8 +14,9 @@ var BackButton = forwardRef(function (_a, ref) {
|
|
|
14
14
|
var caption = _a.caption, id = _a.id;
|
|
15
15
|
var context = useContext(SideMenuContext);
|
|
16
16
|
var handleClick = function () {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
if (id !== undefined) {
|
|
18
|
+
context.dispatch({ type: 'SELECT', id: id, isButton: false });
|
|
19
|
+
}
|
|
19
20
|
};
|
|
20
21
|
return (React.createElement(SideMenuItem, (_b = { ref: ref, "data-tid": SideMenuDataTids.backButton, icon: React.createElement(IconArrowALeftRegular20, null), caption: caption, onClick: handleClick, _isSubMenu: true, _isBackButton: true }, _b[navigationAttributeBackButton] = '', _b)));
|
|
21
22
|
});
|
|
@@ -19,6 +19,13 @@ export interface CommonClickableElementProps extends CommonProps {
|
|
|
19
19
|
disabled?: boolean;
|
|
20
20
|
/** Отключает перенос строки у заголовка элемента, вместо этого он будет обрезаться многоточием. */
|
|
21
21
|
noWrap?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Текст всплывающей подсказки (`Hint`) над элементом. Показывается только в свёрнутом
|
|
24
|
+
* меню (наведение мыши); в развёрнутом — подавляется, т.к. подпись и так видна.
|
|
25
|
+
* Для доступности в свёрнутом состоянии передавайте также `aria-label` — `hint` носит
|
|
26
|
+
* визуальный характер и не подставляется в `aria-label` автоматически.
|
|
27
|
+
*/
|
|
28
|
+
hint?: ReactNode;
|
|
22
29
|
/** @ignore */
|
|
23
30
|
_isSubMenu?: boolean;
|
|
24
31
|
/** @ignore */
|
|
@@ -37,7 +44,7 @@ export interface ClickableElementProps extends CommonClickableElementProps {
|
|
|
37
44
|
onFocus?: React.EventHandler<React.FocusEvent>;
|
|
38
45
|
onBlur?: React.EventHandler<React.FocusEvent>;
|
|
39
46
|
}
|
|
40
|
-
declare const ClickableElementWithStaticFields: React.ForwardRefExoticComponent<ClickableElementProps & React.RefAttributes<
|
|
47
|
+
declare const ClickableElementWithStaticFields: React.ForwardRefExoticComponent<ClickableElementProps & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>> & {
|
|
41
48
|
__KONTUR_REACT_UI__: string;
|
|
42
49
|
};
|
|
43
50
|
export { ClickableElementWithStaticFields as ClickableElement };
|
|
@@ -1,17 +1,31 @@
|
|
|
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, 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
|
+
if (hint === null || hint === undefined) {
|
|
22
|
+
return children;
|
|
23
|
+
}
|
|
24
|
+
if (isOpened) {
|
|
25
|
+
return (React.createElement(Hint, { text: hint, pos: 'right', manual: true, opened: false }, children));
|
|
26
|
+
}
|
|
27
|
+
return (React.createElement(Hint, { text: hint, pos: 'right' }, children));
|
|
28
|
+
};
|
|
15
29
|
/**
|
|
16
30
|
* Элемент списка (пункт меню либо ссылка)
|
|
17
31
|
*
|
|
@@ -20,90 +34,106 @@ import { SubMenu } from './SubMenu.js';
|
|
|
20
34
|
var ClickableElement = forwardRef(function (_a, ref) {
|
|
21
35
|
var _b, _c, _d;
|
|
22
36
|
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"]);
|
|
37
|
+
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, hint = _a.hint, rest = __rest(_a, ["onClick", "icon", "marker", "caption", "subCaption", "id", "_isSubMenu", "children", "element", "onKeyDown", "onFocus", "onBlur", "className", "_isDropdown", "_isBackButton", "_isAvatar", "isButton", "href", "disabled", "noWrap", "hint"]);
|
|
24
38
|
var context = useContext(SideMenuContext);
|
|
25
39
|
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
26
40
|
var styles = useStyles(getStyles);
|
|
27
41
|
var cx = useEmotion().cx;
|
|
28
42
|
var keyListener = useKeyListener();
|
|
29
|
-
var _f = __read(useState(false), 2),
|
|
30
|
-
var _g = __read(useState(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
if (
|
|
39
|
-
var
|
|
40
|
-
|
|
43
|
+
var _f = __read(useState(false), 2), isFocusedByTab = _f[0], setIsFocusedByTab = _f[1];
|
|
44
|
+
var _g = __read(useState(function () {
|
|
45
|
+
if (id) {
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
if (href) {
|
|
49
|
+
return href;
|
|
50
|
+
}
|
|
51
|
+
var counter = context.childIdCounterRef;
|
|
52
|
+
if (counter) {
|
|
53
|
+
var index = counter.current;
|
|
54
|
+
counter.current += 1;
|
|
55
|
+
return "".concat(context.parentItemId, "__").concat(index);
|
|
41
56
|
}
|
|
42
|
-
(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
return generateId();
|
|
58
|
+
}), 1), currentId = _g[0];
|
|
59
|
+
var focusRafRef = useRef(null);
|
|
60
|
+
var childIdCounterRef = useRef(0);
|
|
61
|
+
useEffect(function () {
|
|
62
|
+
return function () {
|
|
63
|
+
if (focusRafRef.current !== null) {
|
|
64
|
+
cancelAnimationFrame(focusRafRef.current);
|
|
65
|
+
focusRafRef.current = null;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}, []);
|
|
69
|
+
var _h = useNodeState(currentId), isActive = _h.isActive, isExpanded = _h.isExpanded, isNestedSubMenu = _h.isNestedSubMenu, hasSeparatedSubMenu = _h.hasSeparatedSubMenu;
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
context.dispatch({
|
|
72
|
+
type: 'REGISTER',
|
|
73
|
+
id: currentId,
|
|
74
|
+
parentId: context.parentItemId,
|
|
75
|
+
isSubMenu: !!_isSubMenu,
|
|
49
76
|
});
|
|
50
77
|
return function () {
|
|
51
|
-
|
|
52
|
-
(_a = context.navigation) === null || _a === void 0 ? void 0 : _a.updateNavigationTree();
|
|
78
|
+
context.dispatch({ type: 'UNREGISTER', id: currentId });
|
|
53
79
|
};
|
|
54
|
-
});
|
|
80
|
+
}, [currentId, context.parentItemId, _isSubMenu, context.dispatch]);
|
|
81
|
+
var Component = _isSubMenu || _isDropdown ? 'div' : 'li';
|
|
82
|
+
var isDesktopCollapsedMode = (context.isDesktop || context.isNarrowDesktop) && !context.isOpened;
|
|
83
|
+
var isActiveSection = context.state.activeFirstLevelParentId === currentId;
|
|
84
|
+
var isHighlighted = isActive || (isActiveSection && (context.isSeparatedMenu || isDesktopCollapsedMode));
|
|
85
|
+
var isCollapsedTopLevelSection = isDesktopCollapsedMode && !_isSubMenu && !_isDropdown && !_isBackButton && !_isAvatar;
|
|
86
|
+
var isCollapsedAccordionSection = isCollapsedTopLevelSection && !!children && !context.isSeparatedMenu;
|
|
55
87
|
var toggleIsShown = function (lastElementInTheHierarchy) {
|
|
56
88
|
var _a;
|
|
57
89
|
if ((context.isMobile || context.isTablet) && lastElementInTheHierarchy) {
|
|
58
90
|
(_a = context.toggleIsOpened) === null || _a === void 0 ? void 0 : _a.call(context);
|
|
59
91
|
}
|
|
60
92
|
};
|
|
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
93
|
var handleClick = function (e) {
|
|
81
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
82
94
|
if (disabled) {
|
|
83
95
|
return;
|
|
84
96
|
}
|
|
97
|
+
if (isCollapsedAccordionSection) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
85
100
|
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
101
|
+
if (e.defaultPrevented) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
86
104
|
if (_isBackButton || _isDropdown) {
|
|
87
105
|
return;
|
|
88
106
|
}
|
|
89
|
-
var
|
|
90
|
-
|
|
107
|
+
var hasKids = context.state ? hasChildren(context.state, currentId) : false;
|
|
108
|
+
// A leaf inside a NarrowAccordionDropdown should dismiss the popup.
|
|
109
|
+
if (!hasKids && context.closeParentDropdown) {
|
|
110
|
+
context.closeParentDropdown();
|
|
111
|
+
}
|
|
112
|
+
if (isButton && !hasKids) {
|
|
91
113
|
return;
|
|
92
114
|
}
|
|
93
|
-
|
|
94
|
-
|
|
115
|
+
// An expanded item collapses on click (toggle), except in separated mode:
|
|
116
|
+
// - a top-level item on desktop keeps its column open on a repeated click
|
|
117
|
+
// (collapsing it would hide the whole column), and
|
|
118
|
+
// - touch (mobile/tablet) has its own BackButton toggle driven by SELECT.
|
|
119
|
+
var isTouchViewport = !!(context.isMobile || context.isTablet);
|
|
120
|
+
var isProtectedSeparatedTopLevel = context.isSeparatedMenu && !_isSubMenu && hasKids && !isTouchViewport;
|
|
121
|
+
if (isExpanded && !isProtectedSeparatedTopLevel && !(context.isSeparatedMenu && isTouchViewport)) {
|
|
122
|
+
context.dispatch({ type: 'CLOSE_NODE', id: currentId });
|
|
95
123
|
}
|
|
96
124
|
else {
|
|
97
|
-
|
|
98
|
-
var lastElementInTheHierarchy = !_isDropdown && !_isBackButton && !
|
|
125
|
+
context.dispatch({ type: 'SELECT', id: currentId, isButton: !!isButton });
|
|
126
|
+
var lastElementInTheHierarchy = !_isDropdown && !_isBackButton && !hasKids;
|
|
99
127
|
toggleIsShown(lastElementInTheHierarchy);
|
|
100
|
-
setIsCollapsed(lastElementInTheHierarchy);
|
|
101
|
-
setMouseIsOutside(lastElementInTheHierarchy);
|
|
102
128
|
}
|
|
103
129
|
};
|
|
104
130
|
var handleFocus = function (e) {
|
|
105
131
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
|
|
106
|
-
|
|
132
|
+
if (focusRafRef.current !== null) {
|
|
133
|
+
cancelAnimationFrame(focusRafRef.current);
|
|
134
|
+
}
|
|
135
|
+
focusRafRef.current = requestAnimationFrame(function () {
|
|
136
|
+
focusRafRef.current = null;
|
|
107
137
|
if (keyListener.isTabPressed) {
|
|
108
138
|
setIsFocusedByTab(true);
|
|
109
139
|
}
|
|
@@ -113,17 +143,20 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
113
143
|
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
114
144
|
setIsFocusedByTab(false);
|
|
115
145
|
};
|
|
116
|
-
var Component = _isSubMenu || _isDropdown ? 'div' : 'li';
|
|
117
|
-
var isHighlighted = isActive ||
|
|
118
|
-
(isFirstLevelParentOfActiveMenuItem && !context.isOpened && context.isCollapsable) ||
|
|
119
|
-
(isFirstLevelParentOfActiveMenuItem && context.isSeparatedMenu);
|
|
120
146
|
var handleCollapse = function (e) {
|
|
121
|
-
var _a, _b, _c, _d;
|
|
122
147
|
if (disabled) {
|
|
123
148
|
return;
|
|
124
149
|
}
|
|
125
150
|
e.stopPropagation();
|
|
126
|
-
|
|
151
|
+
context.dispatch({ type: 'CLOSE_NODE', id: currentId });
|
|
152
|
+
};
|
|
153
|
+
var subMenuIcon = useMemoIcon(children, { isOpened: isExpanded, onClick: handleCollapse });
|
|
154
|
+
var isNativeAnchor = Tag === 'a';
|
|
155
|
+
var handleKeyDown = function (e) {
|
|
156
|
+
if (isNativeAnchor && disabled && e.key === 'Enter') {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
}
|
|
159
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
127
160
|
};
|
|
128
161
|
var newProps = __assign({ className: cx(styles.root(theme), (_b = {},
|
|
129
162
|
_b[styles.rootButton(theme)] = isButton,
|
|
@@ -133,19 +166,44 @@ var ClickableElement = forwardRef(function (_a, ref) {
|
|
|
133
166
|
_b), (_c = {},
|
|
134
167
|
_c[styles.rootSubItemInSeparatedSubMenu(theme)] = context.isSeparatedMenu && _isSubMenu,
|
|
135
168
|
_c[styles.rootSubItemInSeparatedSubMenuActive(theme)] = isActive && context.isSeparatedMenu && _isSubMenu,
|
|
136
|
-
_c)
|
|
169
|
+
_c[styles.rootSubItemInDropdownActive(theme)] = isActive && !context.isSeparatedMenu && _isSubMenu && isDesktopCollapsedMode,
|
|
170
|
+
_c), className), onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur, children: (React.createElement(ItemContent, { _isSubMenu: _isSubMenu,
|
|
137
171
|
// @ts-expect-error: SideMenuItem should have icon
|
|
138
|
-
icon: _isSubMenu && !_isBackButton ?
|
|
172
|
+
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
173
|
// Подсчет смещения вправо для текущего уровня вложенности
|
|
174
|
+
// NOTE: Probably it can be calculated using Navigation Tree
|
|
140
175
|
var currentItemNestingLevel = (_e = context.currentItemNestingLevel) !== null && _e !== void 0 ? _e : 0;
|
|
141
176
|
var nestingLevelPadding = {
|
|
142
|
-
paddingLeft: (currentItemNestingLevel - 1) * parseInt(theme.sideMenuItemNestedPaddingLeft),
|
|
177
|
+
paddingLeft: Math.max(0, currentItemNestingLevel - 1) * parseInt(theme.sideMenuItemNestedPaddingLeft),
|
|
143
178
|
};
|
|
179
|
+
// NOTE: In the collapsed-accordion path (`isCollapsedAccordionSection`) this element is
|
|
180
|
+
// wrapped by `NarrowAccordionDropdown` → `DropdownMenu` → `PopupMenu`. `PopupMenu` adds
|
|
181
|
+
// its own correct `aria-expanded`/`aria-controls` to the outer caption wrapper, but
|
|
182
|
+
// this inner focusable element still keeps the `aria-expanded` set below. Because
|
|
183
|
+
// `handleClick` bails out early in accordion mode, the reducer never marks the section
|
|
184
|
+
// as opened, so the inner element always reports `aria-expanded="false"` while the
|
|
185
|
+
// popup is actually open. Screen readers announce the focused element's state, so
|
|
186
|
+
// the user can hear "collapsed" for an open section.
|
|
187
|
+
//
|
|
188
|
+
// The proper fix is to either sync the dropdown's opened state into this element, or
|
|
189
|
+
// to omit `aria-expanded` here in accordion mode and make the outer caption wrapper
|
|
190
|
+
// the accessible control (focusable + correct `aria-expanded`).
|
|
191
|
+
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 } : {}))));
|
|
192
|
+
var clickableElementWithHint = (React.createElement(ClickableElementWithHint, { hint: hint, isOpened: context.isOpened }, clickableElement));
|
|
193
|
+
// Reset the child id counter on every render so children at this nesting level get stable,
|
|
194
|
+
// position-based generated ids across unmount → re-mount transitions (e.g. narrow
|
|
195
|
+
// accordion dropdown closing → inline submenu opening).
|
|
196
|
+
childIdCounterRef.current = 0;
|
|
197
|
+
var subMenuContextValue = useMemo(function () { return (__assign(__assign({ hasSeparatedSubMenu: hasSeparatedSubMenu }, context), { parentItemId: currentId, currentItemNestingLevel: currentItemNestingLevel + 1, childIdCounterRef: childIdCounterRef })); }, [hasSeparatedSubMenu, context, currentId, currentItemNestingLevel]);
|
|
198
|
+
// При клике на айтем без детей закрывать дропдаун
|
|
199
|
+
// айтем должен оставаться активным и при разворачивании меню корректно показываться в списке подменю
|
|
200
|
+
// При клике на активный элемент с детьми, он должен закрыться
|
|
144
201
|
return (React.createElement(Component, (_d = { "data-tid": SideMenuDataTids.clickableElement }, _d[navigationAttribute] = currentId, _d),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
React.createElement(
|
|
202
|
+
isCollapsedAccordionSection && (React.createElement(NarrowAccordionDropdown, { caption: clickableElementWithHint, htmlId: currentId, childIdCounterRef: childIdCounterRef }, children)),
|
|
203
|
+
!isCollapsedAccordionSection && (React.createElement(React.Fragment, null,
|
|
204
|
+
clickableElementWithHint,
|
|
205
|
+
React.createElement(SubMenu, { caption: caption, isSubMenu: _isSubMenu, isSeparatedMenu: context.isSeparatedMenu, htmlId: currentId, isOpened: isExpanded },
|
|
206
|
+
React.createElement(SideMenuContext.Provider, { value: subMenuContextValue }, children))))));
|
|
149
207
|
});
|
|
150
208
|
ClickableElement.displayName = 'ClickableElement';
|
|
151
209
|
var ClickableElementWithStaticFields = Object.assign(ClickableElement, {
|
|
@@ -6,5 +6,6 @@ export declare const getStyles: import("../../lib/theming/ThemeHelpers.js").Styl
|
|
|
6
6
|
rootFocus(t: SideMenuTheme): string;
|
|
7
7
|
rootDisabled(t: SideMenuTheme): string;
|
|
8
8
|
rootActive(t: SideMenuTheme): string;
|
|
9
|
+
rootSubItemInDropdownActive(t: SideMenuTheme): string;
|
|
9
10
|
rootSubItemInSeparatedSubMenuActive(t: SideMenuTheme): string;
|
|
10
11
|
}>;
|
|
@@ -8,7 +8,7 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
8
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);
|
|
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);
|
|
@@ -22,9 +22,12 @@ export var getStyles = memoizeGetStyles(function (_a) {
|
|
|
22
22
|
rootActive: function (t) {
|
|
23
23
|
return css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n background: ", " !important;\n "], ["\n background: ", " !important;\n "])), t.sideMenuItemBgActive);
|
|
24
24
|
},
|
|
25
|
+
rootSubItemInDropdownActive: function (t) {
|
|
26
|
+
return css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n background: ", " !important;\n "], ["\n background: ", " !important;\n "])), t.sideMenuItemBgHover);
|
|
27
|
+
},
|
|
25
28
|
rootSubItemInSeparatedSubMenuActive: function (t) {
|
|
26
|
-
return css(
|
|
29
|
+
return css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n background: ", " !important;\n "], ["\n background: ", " !important;\n "])), t.sideMenuSubItemWithSeparatedSubMenuBgActive);
|
|
27
30
|
},
|
|
28
31
|
});
|
|
29
32
|
});
|
|
30
|
-
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
|
|
33
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CollapseToggle: () => JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Hint } from '@skbkontur/react-ui/components/Hint/Hint';
|
|
2
|
+
import { useEmotion, useStyles } from '@skbkontur/react-ui/lib/renderEnvironment';
|
|
3
|
+
import { ThemeContext } from '@skbkontur/react-ui/lib/theming/ThemeContext';
|
|
4
|
+
import React, { useContext } from 'react';
|
|
5
|
+
import { getSideMenuTheme } from '../../lib/theming/ThemeHelpers.js';
|
|
6
|
+
import { SideMenuDataTids } from '../../SideMenuDataTids.js';
|
|
7
|
+
import { SideMenuContext } from '../SideMenuContext.js';
|
|
8
|
+
import { getStyles } from './CollapseToggle.styles.js';
|
|
9
|
+
var SideMenuCollapseIcon = function () {
|
|
10
|
+
return (React.createElement("svg", { width: "24", height: "24", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
|
|
11
|
+
React.createElement("path", { d: "M7.29951 3.00195L7.29951 17.002M3.69951 17.002H16.2995C17.7907 17.002 18.9995 15.6588 18.9995 14.002V6.00195C18.9995 4.3451 17.7907 3.00195 16.2995 3.00195H3.69951C2.20834 3.00195 0.999512 4.3451 0.999512 6.00195V14.002C0.999512 15.6588 2.20834 17.002 3.69951 17.002Z", stroke: "currentColor", strokeWidth: "1.5" })));
|
|
12
|
+
};
|
|
13
|
+
export var CollapseToggle = function () {
|
|
14
|
+
var context = useContext(SideMenuContext);
|
|
15
|
+
var theme = getSideMenuTheme(useContext(ThemeContext));
|
|
16
|
+
var styles = useStyles(getStyles);
|
|
17
|
+
var cx = useEmotion().cx;
|
|
18
|
+
var isOpened = !!context.isOpened;
|
|
19
|
+
var hintText = isOpened ? 'Свернуть меню' : 'Развернуть меню';
|
|
20
|
+
var handleClick = function () {
|
|
21
|
+
var _a;
|
|
22
|
+
(_a = context.setMenuOpened) === null || _a === void 0 ? void 0 : _a.call(context, !isOpened);
|
|
23
|
+
};
|
|
24
|
+
return (React.createElement(Hint, { text: hintText, pos: 'right' },
|
|
25
|
+
React.createElement("button", { type: 'button', className: cx(styles.root(theme)), "aria-label": hintText, "aria-expanded": isOpened, "data-tid": SideMenuDataTids.collapseToggle, onClick: handleClick },
|
|
26
|
+
React.createElement(SideMenuCollapseIcon, null))));
|
|
27
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __makeTemplateObject } from "tslib";
|
|
2
|
+
import { resetButton } from '@skbkontur/react-ui/lib/styles/Mixins';
|
|
3
|
+
import { memoizeGetStyles } from '../../lib/theming/ThemeHelpers.js';
|
|
4
|
+
export var getStyles = memoizeGetStyles(function (_a) {
|
|
5
|
+
var css = _a.css;
|
|
6
|
+
return ({
|
|
7
|
+
root: function (t) {
|
|
8
|
+
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\n &:hover {\n color: ", ";\n }\n\n &:focus-visible {\n box-shadow: ", ";\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\n &:hover {\n color: ", ";\n }\n\n &:focus-visible {\n box-shadow: ", ";\n }\n "])), resetButton(), t.sideMenuCollapseToggleSize, t.sideMenuCollapseToggleSize, t.sideMenuItemBorderRadius, t.sideMenuRightBorderIconColor, t.sideMenuRightBorderIconColorHover, t.sideMenuItemBoxShadowFocus);
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
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 {};
|