Skip to content

Commit

Permalink
refactor: sidebar interaction by onclick (#751)
Browse files Browse the repository at this point in the history
# Fixes Issue:
- Issue: #748 
- Change Side Menu Behavior to Open on Click Instead of on Hover

<br>

# Changes made:
- Refactored code to interact with sidebar using `onClick` instead
`onHover`

<br>

# Files changed:
- **menu.tsx** (frontend/webapp/components/side.menu/menu/menu.tsx)
- **menu.styled.tsx**
(frontend/webapp/components/side.menu/menu/menu.styled.tsx)

<br>

- [x] Tested the code

---------

Co-authored-by: Alon Braymok <138359965+alonkeyval@users.noreply.github.com>
  • Loading branch information
HeetVekariya and alonkeyval authored Nov 12, 2023
1 parent 5d0584e commit 817c599
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
9 changes: 4 additions & 5 deletions frontend/webapp/components/side.menu/menu/menu.styled.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import styled from 'styled-components';

export const MenuContainer = styled.div`
width: 70px;
export const MenuContainer = styled.div<{ $isExpanded?: boolean; }>`
transition: width 0.1s;
height: 100%;
border-right: 1px solid rgba(255, 255, 255, 0.04);
background: ${({ theme }) => theme.colors.dark_blue};
&:hover {
width: 234px;
}
width: ${({$isExpanded}) => $isExpanded ? 234 : 70}px;
`;

export const LogoWrapper = styled.div`
cursor: pointer;
padding: 24px 16px;
height: 48px;
position: relative;
Expand Down
17 changes: 8 additions & 9 deletions frontend/webapp/components/side.menu/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function Menu() {
const [currentMenuItem, setCurrentMenuItem] = useState<MenuItem>(
MENU_ITEMS[0]
);
const [isHovered, setIsHovered] = useState(false);
const [isExpanded, setIsExpanded] = useState(false);
const router = useRouter();

useEffect(onLoad, []);
Expand All @@ -54,15 +54,17 @@ export function Menu() {
onClick={() => handleMenuItemClick(item)}
focused={currentMenuItem?.id === item.id}
item={item}
expand={isHovered}
expand={isExpanded}
/>
));
}

function renderMenuLogo() {
return (
<LogoWrapper>
{isHovered ? (
<LogoWrapper
onClick={() => setIsExpanded(!isExpanded)}
>
{isExpanded ? (
<KeyvalText size={32} weight={700}>
{OVERVIEW.ODIGOS}
</KeyvalText>
Expand All @@ -76,16 +78,13 @@ export function Menu() {
function renderContactUsButton() {
return (
<ContactUsWrapper>
<ContactUsButton expand={isHovered} />
<ContactUsButton expand={isExpanded} />
</ContactUsWrapper>
);
}

return (
<MenuContainer
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
>
<MenuContainer $isExpanded={isExpanded} >
{renderMenuLogo()}
<MenuItemsWrapper>{renderMenuItemsList()}</MenuItemsWrapper>
{renderContactUsButton()}
Expand Down

0 comments on commit 817c599

Please sign in to comment.