Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const MainContainer = styled.div<{ isVisible: boolean }>`
`

const NavItemContainer = styled.div`
height: ${NAV_BAR_HEIGHT};
height: auto;
display: flex;
align-items: flex-start;
margin-left: 3rem;
margin-top: 1.5rem;

a + a {
margin-left: 2rem;
Expand All @@ -35,6 +37,7 @@ function NavBar() {
const router = useRouter()
const pageFilePath = router.pathname
const pageName = pageFilePath.slice(1)

const [prevScrollPos, setPrevScrollPos] = useState(0)
const [isVisible, setVisible] = useState(true)

Expand All @@ -58,6 +61,7 @@ function NavBar() {
key={index}
text={item}
isActive={item.toLowerCase() === pageName || (item === 'Home' && pageName === '')}
isDropdown={item.toLowerCase() === 'about us'}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok acceptable for now

href={item === 'Home' ? '/' : `/${item.toLowerCase()}`}
/>
))}
Expand Down
89 changes: 85 additions & 4 deletions components/NavItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Link from 'next/link'
import { useState } from 'react'
import styled, { css, FontType, useTheme } from 'styled-components'
import { fontTypeCss } from '@/styles/sample-rhdevs-website/index.styled'

import { dropdownTitles } from '@/texts/common/dropdownTitles'

const activeCss = css`
color: ${(props) => props.theme.palette.primary};
//css solution for styled underline
Expand All @@ -22,13 +25,28 @@ const inactiveCss = css`
font-size: 130%;
}
`
const DropdownDiv = styled.div`
display: flex;
flex-direction: column;
height: auto;
width: 90px;
background-position: 50% calc(50% + 12px);
background-color: black;
justify-content: center;
align-items: center;
`

const StyledNavItem = styled(Link)<{ isActive?: boolean; fontType: FontType }>`
height: 100%;
const StyledNavItem = styled(Link)<{
isActive?: boolean
fontType: FontType
}>`
height: auto;
width: fit-content;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-left: 2rem;
cursor: pointer;

// overwrite default link styles
Expand All @@ -38,29 +56,92 @@ const StyledNavItem = styled(Link)<{ isActive?: boolean; fontType: FontType }>`
${fontTypeCss}
transition: font-size 0.3s;
text-transform: capitalize;
line-height: 1;
//line-height: 1;

${(props) => (props.isActive ? activeCss : inactiveCss)}

@media (max-width: 650px) {
font-size: 12px;
}
`
const ColumnNavItemContainer = styled(StyledNavItem)`
margin-left: 0;

a + a {
margin-top: 1rem;
margin-left: 0;
}
`

type NavItemProps = {
text: string
href?: string
isActive?: boolean
isDropdown?: boolean
isInColumn?: boolean
}

const defaultProps = {
href: '',
isActive: false,
isDropdown: false,
isInColumn: false,
}

export default function NavItem({ text, href, isActive }: NavItemProps) {
export default function NavItem({ text, href, isActive, isDropdown, isInColumn }: NavItemProps) {
const theme = useTheme()
const [dropdown, setDropdown] = useState(false)
const { h3 } = { ...theme.typography.fontSize }
const onMouseEnter = () => {
if (window.innerWidth < 960) {
setDropdown(false)
} else {
setDropdown(true)
}
}

const onMouseLeave = () => {
if (window.innerWidth < 960) {
setDropdown(false)
} else {
setDropdown(false)
}
}
Comment on lines +103 to +109

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both is the same??????????


if (isDropdown) {
return (
<StyledNavItem
href={href ?? ''}
isActive={isActive}
fontType={h3}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
<div>{text}</div>

{dropdown && (
<DropdownDiv>
{dropdownTitles.map((item, index) => (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice attempt to abstract the dropdown titles! should work for now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but think what if we want to have multiple tabs on the navbar to have different dropdown menus? and how you store information such as which URL will each dropdown option direct to

<NavItem
key={index}
text={item}
isDropdown={item.toLowerCase() === 'about us'}
href={item === 'Home' ? '/' : `/${item.toLowerCase()}`}
isInColumn={isInColumn}
/>
Comment on lines +125 to +131

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm you should create a new component for dropdown item instead of just reusing the navbar NavItem component!

))}
</DropdownDiv>
)}
</StyledNavItem>
)
}
if (isInColumn) {
return (
<ColumnNavItemContainer href={href ?? ''} isActive={isActive} fontType={h3}>
{text}
</ColumnNavItemContainer>
)
}
Comment on lines +111 to +144

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of putting rerturns within if else statement what you could do is:

  1. Abstract the components that you want to render on certain conditions only (i.e. the dropdown)
  2. Have only ONE return statement
  3. In the return statement, do something like isDropdown && <Dropdown />. This will then only render the dropdown when the argument isDropdown is set to true

return (
<StyledNavItem href={href ?? ''} isActive={isActive} fontType={h3}>
{text}
Expand Down
Loading