-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
955ad3a
commit 1b9260f
Showing
8 changed files
with
209 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 54 additions & 14 deletions
68
packages/libs/kode-ui/src/patterns/SideBarLayout/SideBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,83 @@ | ||
import { MonoMenu, MonoMenuOpen } from '@kadena/kode-icons/system'; | ||
import classNames from 'classnames'; | ||
import type { FC, PropsWithChildren, ReactElement } from 'react'; | ||
import React from 'react'; | ||
import type { PressEvent } from './../../components'; | ||
import { Button, Media, Stack } from './../../components'; | ||
import { KLogo } from './components/Logo/KLogo'; | ||
import { KadenaLogo } from './components/Logo/KadenaLogo'; | ||
import { SideBarAppContext } from './components/SideBarAppContext'; | ||
import { SideBarContext } from './components/SideBarContext'; | ||
import { SideBarNavigation } from './components/SideBarNavigation'; | ||
import { useSideBar } from './components/SideBarProvider'; | ||
import { | ||
menuBackdropClass, | ||
menuMenuIconClass, | ||
menuWrapperClass, | ||
menuWrapperMobileExpandedClass, | ||
} from './sidebar.css'; | ||
|
||
export interface ISideBarProps extends PropsWithChildren { | ||
activeUrl?: string; | ||
logo?: ReactElement; | ||
|
||
appContext?: ReactElement; | ||
navigation?: ReactElement; | ||
context?: ReactElement; | ||
logo?: ReactElement; | ||
minifiedLogo?: ReactElement; | ||
} | ||
|
||
export const SideBar: FC<ISideBarProps> = ({ | ||
children, | ||
appContext, | ||
navigation, | ||
context, | ||
logo, | ||
minifiedLogo, | ||
}) => { | ||
const { isExpanded } = useSideBar(); | ||
const { isExpanded, handleToggleExpand } = useSideBar(); | ||
|
||
const handleExpand = (e: PressEvent) => { | ||
if (handleToggleExpand) { | ||
handleToggleExpand(e); | ||
} | ||
}; | ||
|
||
const ShowLogo = () => { | ||
if (!isExpanded) { | ||
return minifiedLogo ? minifiedLogo : <KLogo height={40} />; | ||
} | ||
|
||
return logo ? logo : <KadenaLogo height={40} />; | ||
}; | ||
|
||
return ( | ||
<aside | ||
className={classNames(menuWrapperClass({ expanded: isExpanded }), { | ||
[menuWrapperMobileExpandedClass]: isExpanded, | ||
})} | ||
> | ||
{appContext && <SideBarAppContext>{appContext}</SideBarAppContext>} | ||
{navigation && <SideBarNavigation>{navigation}</SideBarNavigation>} | ||
{context && <SideBarContext>{context}</SideBarContext>} | ||
|
||
{children} | ||
</aside> | ||
<> | ||
<Stack | ||
className={menuBackdropClass({ expanded: isExpanded })} | ||
onClick={handleExpand} | ||
/> | ||
<aside | ||
className={classNames(menuWrapperClass({ expanded: isExpanded }), { | ||
[menuWrapperMobileExpandedClass]: isExpanded, | ||
})} | ||
> | ||
<Stack className={classNames(menuMenuIconClass)}> | ||
<Media lessThan="md">{ShowLogo()}</Media> | ||
<Media greaterThanOrEqual="md">{ShowLogo()}</Media> | ||
|
||
<Button | ||
variant="transparent" | ||
onPress={handleExpand} | ||
startVisual={isExpanded ? <MonoMenuOpen /> : <MonoMenu />} | ||
/> | ||
</Stack> | ||
|
||
{appContext && <SideBarAppContext>{appContext}</SideBarAppContext>} | ||
{navigation && <SideBarNavigation>{navigation}</SideBarNavigation>} | ||
{context && <SideBarContext>{context}</SideBarContext>} | ||
|
||
{children} | ||
</aside> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.