From 2fb38e836c529acd86dade00a3ad39aab9b1247e Mon Sep 17 00:00:00 2001 From: Michele Masciave Date: Thu, 17 Oct 2024 21:19:14 +0200 Subject: [PATCH] init --- .../Context/PanelSideBarContext.tsx | 3 ++ .../Context/PanelSideBarContextProps.ts | 5 +++ .../PanelSideBar/Definitions/PanelItem.ts | 5 +++ .../PanelSideBar/PanelSideBarItem.tsx | 45 ++++++++++--------- .../PanelSideBar/PanelSideBarToggle.tsx | 3 +- .../PanelSideBar/PanelSidebar.tsx | 2 + .../PanelSideBarLayoutContent.tsx | 5 ++- styles/Layout/_PanelSideBarLayout.scss | 13 ++++-- styles/Layout/variables.scss | 1 + 9 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContext.tsx b/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContext.tsx index 2370782..14a0aa7 100644 --- a/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContext.tsx +++ b/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContext.tsx @@ -87,6 +87,8 @@ export const PanelSideBarProvider = ( ); }; + const activePanelShowIconsOnCollapse = menuItems.find((x) => x.id === activePanelId)?.showIconsOnCollapse ?? false; + return ( ( closeMenuItems, hiddenMenuItemIds, setHiddenMenuItemsIds, + activePanelShowIconsOnCollapse, }} > {children} diff --git a/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContextProps.ts b/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContextProps.ts index 16ea4c1..0421829 100644 --- a/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContextProps.ts +++ b/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContextProps.ts @@ -87,4 +87,9 @@ export interface PanelSideBarContextProps void; + + /** + * Whether the sidebar maintains the active panel item icons visible on collapsing. + */ + activePanelShowIconsOnCollapse?: boolean; } diff --git a/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Definitions/PanelItem.ts b/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Definitions/PanelItem.ts index fc49c30..3948216 100644 --- a/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Definitions/PanelItem.ts +++ b/src/lib/Layout/PanelSideBarLayout/PanelSideBar/Definitions/PanelItem.ts @@ -44,4 +44,9 @@ export type PanelItem { children: PanelItem; @@ -13,14 +14,25 @@ export interface PanelSideBarItemProps isParentHidden?: boolean; } +const PanelSidebarItemNavLink = ({ icon, title, collapsedWithIcons }: { icon?: IconProp, title: ReactNode, collapsedWithIcons?: boolean }) => { + const iconClassName = collapsedWithIcons ? "ms-1 me-3 p-1" : "me-2"; + return ( + + {icon && } + {collapsedWithIcons && icon ? "" : title} + + ); +} + // eslint-disable-next-line complexity const PanelSideBarItem = (props: PanelSideBarItemProps) => { const { depth = 0, children: item, isParentHidden = false } = props; - const { LinkRenderer, toggledMenuItemIds, toggleMenuItem, hiddenMenuItemIds } = usePanelSideBarContext(); - const hasitem = !!item.children?.length; - const isActive = (hasitem && item.children && hasActiveChildren(item.children)) || item.active; + const { LinkRenderer, toggledMenuItemIds, toggleMenuItem, hiddenMenuItemIds, activePanelShowIconsOnCollapse, isSidebarOpen } = usePanelSideBarContext(); + const hasItems = !!item.children?.length; + const isActive = (hasItems && item.children && hasActiveChildren(item.children)) || item.active; const isOpen = toggledMenuItemIds?.includes(item.id); const scrollToActiveItemRef = useRef(null); + const collapsedWithIcons = activePanelShowIconsOnCollapse && !isSidebarOpen; useEffect(() => { if (scrollToActiveItemRef.current && isActive) { @@ -33,28 +45,25 @@ const PanelSideBarItem = (props: PanelS - {hasitem && ( + {hasItems && ( {item.children?.map((childItem) => ( { const { toggled, ...buttonProps } = props; - const { theme } = usePanelSideBarContext(); + const { theme, activePanelShowIconsOnCollapse } = usePanelSideBarContext(); return (