generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'layer5io:master' into master
- Loading branch information
Showing
10 changed files
with
287 additions
and
141 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import NavigationNavbar from './navigationNavbar'; | ||
|
||
export { NavigationNavbar }; |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import ExpandLessIcon from '@mui/icons-material/ExpandLess'; | ||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
import React, { MouseEvent, useState } from 'react'; | ||
import { Collapse, Divider, ListItemText, MenuItem } from '../../base'; | ||
import { IconWrapper, MenuItemList, MenuItemSubList, MenuListStyle, SubIconWrapper } from './style'; | ||
|
||
type NavigationItem = { | ||
id: string; | ||
title: string; | ||
icon: React.ReactNode; | ||
permission?: boolean; | ||
onClick: () => void; | ||
subItems?: NavigationItem[]; | ||
addDivider?: boolean; | ||
}; | ||
|
||
type NavigationNavbarProps = { | ||
navigationItems: NavigationItem[]; | ||
}; | ||
|
||
const NavigationNavbar: React.FC<NavigationNavbarProps> = ({ navigationItems }) => { | ||
const [openSectionId, setOpenSectionId] = useState<string | null>(null); | ||
|
||
const toggleSectionOpen = (sectionId: string, event: MouseEvent<SVGSVGElement>) => { | ||
event.stopPropagation(); | ||
setOpenSectionId((currentOpenSectionId) => | ||
currentOpenSectionId === sectionId ? null : sectionId | ||
); | ||
}; | ||
|
||
const NavigationNavbarItems = () => { | ||
return navigationItems.map((item) => { | ||
const isOpen = openSectionId === item.id; | ||
const permission = item.permission ?? true; | ||
const addDivider = item.addDivider ?? false; | ||
|
||
return ( | ||
<React.Fragment key={item.id}> | ||
<MenuItem disabled={!permission} onClick={item.onClick}> | ||
<MenuItemList> | ||
<IconWrapper>{item.icon}</IconWrapper> | ||
<ListItemText primary={item.title} /> | ||
</MenuItemList> | ||
{item.subItems && ( | ||
<ListItemText> | ||
{isOpen ? ( | ||
<ExpandLessIcon onClick={(e) => toggleSectionOpen(item.id, e)} /> | ||
) : ( | ||
<ExpandMoreIcon onClick={(e) => toggleSectionOpen(item.id, e)} /> | ||
)} | ||
</ListItemText> | ||
)} | ||
</MenuItem> | ||
|
||
{item.subItems && ( | ||
<Collapse in={isOpen} timeout="auto" unmountOnExit variant="submenu"> | ||
{item.subItems.map((subItem) => ( | ||
<MenuItem key={subItem.id} disabled={!subItem.permission} onClick={subItem.onClick}> | ||
<MenuItemSubList> | ||
<SubIconWrapper>{subItem.icon}</SubIconWrapper> | ||
<ListItemText primary={subItem.title} /> | ||
</MenuItemSubList> | ||
</MenuItem> | ||
))} | ||
</Collapse> | ||
)} | ||
|
||
{addDivider && <Divider />} | ||
</React.Fragment> | ||
); | ||
}); | ||
}; | ||
|
||
return <MenuListStyle dense>{NavigationNavbarItems()}</MenuListStyle>; | ||
}; | ||
|
||
export default NavigationNavbar; |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { styled } from '@mui/material/styles'; | ||
import { ListItem, MenuList } from '../../base'; | ||
|
||
export const ListItemStyle = styled('div')(({ theme }) => ({ | ||
marginLeft: '.5rem', | ||
color: theme.palette.background.secondary | ||
})); | ||
|
||
export const MenuListStyle = styled(MenuList)({ | ||
minHeight: '31rem', | ||
width: '13rem', | ||
overflowY: 'auto', | ||
scrollbarWidth: 'none', | ||
'&::-webkit-scrollbar': { | ||
width: '0em' | ||
} | ||
}); | ||
|
||
export const MenuItemList = styled(ListItem)(() => ({ | ||
pointerEvents: 'auto', | ||
margin: '0.5rem 0rem 0.5rem 0.5rem', | ||
fontSize: '0.1rem', | ||
padding: '0' | ||
})); | ||
|
||
export const MenuItemSubList = styled(ListItem)(() => ({ | ||
pointerEvents: 'auto', | ||
margin: '0rem 0rem 0rem 0.5rem', | ||
fontSize: '0.1rem' | ||
})); | ||
|
||
export const IconWrapper = styled('div')({ | ||
marginRight: '0.75rem' | ||
}); | ||
|
||
export const SubIconWrapper = styled('div')({ | ||
marginRight: '0.5rem' | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { DEFAULT_FILL_NONE, DEFAULT_HEIGHT, DEFAULT_WIDTH } from '../../constants/constants'; | ||
import { IconProps } from '../types'; | ||
|
||
export const AddIcon = ({ | ||
width = DEFAULT_WIDTH, | ||
height = DEFAULT_HEIGHT, | ||
fill = DEFAULT_FILL_NONE, | ||
...props | ||
}: IconProps): JSX.Element => { | ||
return ( | ||
<svg | ||
width={width} | ||
height={height} | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
data-testid="add-icon-svg" | ||
{...props} | ||
> | ||
<path fill={fill} d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"></path> | ||
</svg> | ||
); | ||
}; | ||
|
||
export default AddIcon; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as MenuIcon } from './MenuIcon'; |
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