From 7013ae5d2830999d0f05d1e7cd5466c992fecd57 Mon Sep 17 00:00:00 2001 From: Steven Straatemans Date: Wed, 30 Oct 2024 09:56:45 +0100 Subject: [PATCH] fix closing the sidebar --- .../SideBarLayout/SideBarLayout.stories.tsx | 29 +++++++++++++++-- .../patterns/SideBarLayout/SideBarLayout.tsx | 25 +++++++++++++-- .../components/SideBarHeader.tsx | 23 +++++++------- .../SideBarLayout/components/SideBarItem.tsx | 31 ++++++------------- .../components/SideBarProvider.tsx | 9 ++++++ .../components/SideBarTreeItem.tsx | 11 ++++++- 6 files changed, 88 insertions(+), 40 deletions(-) diff --git a/packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.stories.tsx b/packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.stories.tsx index fc00af9ae6..31ab1d55ac 100644 --- a/packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.stories.tsx +++ b/packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.stories.tsx @@ -11,6 +11,8 @@ import { MonoWorkspaces, } from '@kadena/kode-icons/system'; import { Breadcrumbs, BreadcrumbsItem, Button } from './../../components'; +import { KadenaLogo } from './components/Logo/KadenaLogo'; +import { KLogo } from './components/Logo/KLogo'; import { SideBarFooter } from './components/SideBarFooter'; import { SideBarFooterItem } from './components/SideBarFooterItem'; import { SideBarItem } from './components/SideBarItem'; @@ -37,7 +39,8 @@ const meta: Meta = { }, docs: { description: { - component: 'A component can show the steps through a process', + component: + 'A component that will set the layout for your app. All with header, footer and sidebar. The layout is setup that you can choose your own routing system. whether its Next or reactRouter. \nThe actual routes are set in your app', }, }, }, @@ -59,6 +62,17 @@ const InnerLayout = () => { return ( + + + } + minifiedLogo={ + + + + } + activeUrl="https://mastersoftheuniverse.com" topBanner={
topbanner
} breadcrumbs={ }> @@ -165,7 +179,18 @@ export const Primary: IStory = { }; const InnerLayoutFull = () => { - return content; + return ( + + + + } + variant="full" + > + content + + ); }; export const Full: IStory = { diff --git a/packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.tsx b/packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.tsx index c63eab8bbb..b984613dbf 100644 --- a/packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.tsx +++ b/packages/libs/kode-ui/src/patterns/SideBarLayout/SideBarLayout.tsx @@ -1,6 +1,6 @@ import classNames from 'classnames'; import type { FC, PropsWithChildren, ReactElement } from 'react'; -import React from 'react'; +import React, { useEffect } from 'react'; import { MediaContextProvider, Stack } from './../../components'; import { SideBarHeader } from './components/SideBarHeader'; @@ -13,20 +13,34 @@ import { export interface ISideBarLayout extends PropsWithChildren { topBanner?: ReactElement; + logo?: ReactElement; + minifiedLogo?: ReactElement; breadcrumbs?: ReactElement; sidebar?: ReactElement; footer?: ReactElement; variant?: 'default' | 'full'; + activeUrl?: string; } export const SideBarLayout: FC = ({ children, topBanner, + logo, + minifiedLogo, breadcrumbs, sidebar, footer, variant = 'default', + activeUrl, }) => { - const { isExpanded } = useSideBar(); + const { isExpanded, setActiveUrl } = useSideBar(); + + // set the active URL in your app. + //we dont know what route system is being used so the active URL will be given as a prop to the component + //and then saved in the layout + useEffect(() => { + setActiveUrl(activeUrl); + }, [activeUrl]); + return ( = ({ [layoutExpandedWrapperClass]: isExpanded, })} > - + {sidebar}
{children}
{footer} diff --git a/packages/libs/kode-ui/src/patterns/SideBarLayout/components/SideBarHeader.tsx b/packages/libs/kode-ui/src/patterns/SideBarLayout/components/SideBarHeader.tsx index 42198b2ce6..6be7ddeee0 100644 --- a/packages/libs/kode-ui/src/patterns/SideBarLayout/components/SideBarHeader.tsx +++ b/packages/libs/kode-ui/src/patterns/SideBarLayout/components/SideBarHeader.tsx @@ -18,12 +18,14 @@ import { useSideBar } from './SideBarProvider'; interface IProps extends PropsWithChildren { logo?: ReactElement; + minifiedLogo?: ReactElement; breadcrumbs?: ReactElement; hasSidebar?: boolean; } export const SideBarHeader: FC = ({ logo, + minifiedLogo, breadcrumbs, hasSidebar = true, }) => { @@ -34,14 +36,13 @@ export const SideBarHeader: FC = ({ } }; - const ShowLogo = - !isExpanded && hasSidebar ? ( - - ) : logo ? ( - logo - ) : ( - - ); + const ShowLogo = () => { + if (!isExpanded && hasSidebar) { + return minifiedLogo ? minifiedLogo : ; + } + + return logo ? logo : ; + }; return (
@@ -54,10 +55,8 @@ export const SideBarHeader: FC = ({ > <> - - {hasSidebar ? : } - - {ShowLogo} + {ShowLogo()} + {ShowLogo()} {hasSidebar && ( diff --git a/packages/libs/kode-ui/src/patterns/SideBarLayout/components/SideBarItem.tsx b/packages/libs/kode-ui/src/patterns/SideBarLayout/components/SideBarItem.tsx index 0499b3849f..65cb10d396 100644 --- a/packages/libs/kode-ui/src/patterns/SideBarLayout/components/SideBarItem.tsx +++ b/packages/libs/kode-ui/src/patterns/SideBarLayout/components/SideBarItem.tsx @@ -16,7 +16,6 @@ export interface ISideBarItemProps extends PropsWithChildren { } export const SideBarItem: FC = ({ visual, - isAppContext = false, label, onPress, children, @@ -28,6 +27,12 @@ export const SideBarItem: FC = ({ handleSetExpanded(isMediumDevice ? true : false); }, [isMediumDevice]); + const handlePress = (e: PressEvent) => { + if (!isMediumDevice) handleSetExpanded(false); + + onPress(e); + }; + return (
  • {children ? ( @@ -45,7 +50,7 @@ export const SideBarItem: FC = ({
  • ); - - // return ( - //