Skip to content

Commit

Permalink
feat: expanding menu bar
Browse files Browse the repository at this point in the history
  • Loading branch information
celinechoiii committed Oct 27, 2024
1 parent 48c7c71 commit 327bbc4
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 1 deletion.
77 changes: 77 additions & 0 deletions components/ExpandingMenu/ExpandingMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { useState } from 'react';
import Availability from '@/public/images/availabilities.svg';
import Events from '@/public/images/upcoming-events.svg';
import Settings from '@/public/images/settings.svg';
import { MenuContainer, ToggleButton, MenuItem, MenuLabel, MenuIconWrapper, Icon } from './styles';

const ExpandingMenu: React.FC = () => {
const [expanded, setExpanded] = useState(false);
const [activeItem, setActiveItem] = useState<string | null>(null);

const toggleMenu = () => setExpanded(!expanded);

// TODO: add navigation by passing in path prop
const handleClick = (item: string) => {
setActiveItem(item);
};

return (
<MenuContainer $expanded={expanded}>
<ToggleButton onClick={toggleMenu}>
<MenuIconWrapper $expanded={expanded}>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M3 18H21V16H3V18ZM3 13H21V11H3V13ZM3 6V8H21V6H3Z" fill="currentColor" />
</svg>
</MenuIconWrapper>
</ToggleButton>
{expanded && (
<>
<MenuItem
$expanded={expanded}
onClick={() => handleClick('availabilities')}
>
<Icon src={Availability} alt="Availabilities icon" />
<MenuLabel
$expanded={expanded}
$active={activeItem === 'availabilities'}
>
Availabilities
</MenuLabel>
</MenuItem>
<MenuItem
$expanded={expanded}
onClick={() => handleClick('events')}
>
<Icon src={Events} alt="Events icon" />
<MenuLabel
$expanded={expanded}
$active={activeItem === 'events'}
>
Upcoming Events
</MenuLabel>
</MenuItem>
<MenuItem
$expanded={expanded}
onClick={() => handleClick('settings')}
>
<Icon src={Settings} alt="Settings icon" />
<MenuLabel
$expanded={expanded}
$active={activeItem === 'settings'}
>
Profile & Settings
</MenuLabel>
</MenuItem>
</>
)}
</MenuContainer>
);
};

export default ExpandingMenu;
65 changes: 65 additions & 0 deletions components/ExpandingMenu/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import styled from 'styled-components';
import COLORS from '@/styles/colors';
import Image from 'next/image';
import { Sans } from '@/styles/fonts';
import { P } from '@/styles/text';

export const MenuContainer = styled.div<{ $expanded: boolean }>`
height: 100vh;
background-color: ${({ $expanded }) => ($expanded ? COLORS.pomegranate : 'transparent')};
display: flex;
flex-direction: column;
padding-left: 1.25rem;
gap: 1.5rem;
transition: width 0.3s ease, background-color 0.3s ease;
position: fixed;
width: ${({ $expanded }) => ($expanded ? '20%' : '0')};
@media (max-width: 768px) {
width: ${({ $expanded }) => ($expanded ? '75%' : '0')};
}
`;

export const ToggleButton = styled.button`
background-color: transparent;
border: none;
cursor: pointer;
display: flex;
padding: 1rem 0;
`;

export const MenuItem = styled.button<{ $expanded: boolean }>`
width: 100%;
background-color: transparent;
border-style: solid;
border-color: transparent;
color: ${COLORS.gray3};
display: flex;
align-items: center;
justify-content: ${({ $expanded }) => ($expanded ? 'flex-start' : 'center')};
cursor: pointer;
`;

export const MenuIconWrapper = styled.div<{ $expanded: boolean }>`
width: 20px;
height: 20px;
& svg path {
fill: ${({ $expanded }) => ($expanded ? COLORS.gray3 : COLORS.pomegranate)};
}
`;

export const Icon = styled(Image)`
width: 20px;
height: 20px;
margin-right: 0.625rem;
`;

export const MenuLabel = styled(P)<{ $expanded: boolean; $active: boolean }>`
${Sans.style}
color: ${COLORS.gray3};
display: ${({ $expanded }) => ($expanded ? 'flex' : 'none')};
font-weight: ${({ $active }) => ($active ? '600' : '400')};
transition: font-weight 0.03s ease-in-out;
`;
3 changes: 3 additions & 0 deletions public/images/availabilities.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/images/menu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/images/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/images/upcoming-events.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions styles/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const COLORS = {
gray10: '#6D6D6D',
gray11: '#515151',
gray12: '#202020',

pomegranate: '#342A2F'
};

export default COLORS;
2 changes: 1 addition & 1 deletion styles/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const H6 = styled.h6<TextProps>`
export const P = styled.p<TextProps>`
${TextStyles}
font-size: 1rem;
font-weight: 400;
// font-weight: 400;
`;

export const SMALL = styled.p<TextProps>`
Expand Down

0 comments on commit 327bbc4

Please sign in to comment.