Skip to content

Commit

Permalink
Merge pull request #37 from gabrielduete/feat/create-navbar
Browse files Browse the repository at this point in the history
feat: create navbar
  • Loading branch information
gabrielduete authored Mar 18, 2024
2 parents d823b64 + e876f65 commit 41766c7
Show file tree
Hide file tree
Showing 18 changed files with 316 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},

"editor.formatOnSave": true,
Expand Down
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const nextJest = require('next/jest')
const path = require('path')

const createJestConfig = nextJest({
dir: './',
Expand All @@ -9,8 +10,11 @@ const customJestConfig = {
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
moduleDirectories: ['node_modules', '<rootDir>/'],
testEnvironment: 'jest-environment-jsdom',
moduleNameMapper: {
'^~/src/enums/medias$': path.resolve(__dirname, './src/enums/medias'),
},
}

module.exports = createJestConfig(customJestConfig)
module.exports = createJestConfig({ ...customJestConfig })

/** o/ font: https://fek.io/blog/add-jest-testing-framework-to-an-existing-next-js-app */
7 changes: 6 additions & 1 deletion pages/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ const Home: NextPage = () => {
return () => clearInterval(timer)
}, [])

const redirectToAbout = () => {
SoundClickButton()
window.open('/about', '_self', 'noreferrer')
}

return (
<>
<Sound playStatus='PLAYING' {...settingsSound} />
<S.Wrapper>
<S.Content>
<S.Title ref={glitch.ref}>sandevistan</S.Title>
<S.Link onClick={() => SoundClickButton()}>
<S.Link onClick={redirectToAbout}>
explore <ArrowRightAltIcon />
</S.Link>
</S.Content>
Expand Down
1 change: 0 additions & 1 deletion src/components/Footer/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const Footer = styled.footer`
max-height: auto;
min-height: 50px;
background-color: var(--green);
position: fixed;
left: 0;
bottom: 0;
Expand Down
20 changes: 12 additions & 8 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useRouter } from 'next/router'

import MobileNavBar from '../NavBar/Mobile'
import { items } from './Header.data'
import * as S from './styles'

Expand All @@ -8,15 +9,18 @@ const Header = () => {

return (
<S.Header>
{items.map(({ name, href }) => {
const isPath = router?.pathname === href
<S.WrapperLinks>
{items.map(({ name, href }) => {
const isPath = router?.pathname === href

return (
<S.Link href={href} key={name} isPath={isPath}>
{name}
</S.Link>
)
})}
return (
<S.Link href={href} key={name} isPath={isPath}>
{name}
</S.Link>
)
})}
</S.WrapperLinks>
<MobileNavBar />
</S.Header>
)
}
Expand Down
11 changes: 9 additions & 2 deletions src/components/Header/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ export const Header = styled.header`
display: flex;
align-items: center;
flex-wrap: wrap;
gap: var(--spacing-basic);
justify-content: space-between;
width: 100%;
height: 60px;
background-color: var(--green);
padding-left: var(--spacing-basic);
padding: 0 var(--spacing-basic);
position: fixed;
top: 0;
left: 0;
`

export const WrapperLinks = styled.div`
display: flex;
align-items: center;
flex-wrap: wrap;
gap: var(--spacing-basic);
`

export const Link = styled.a<{ isPath: boolean }>`
color: ${({ isPath }) =>
isPath ? 'color: var(--white)' : 'var(--green-white)'};
Expand Down
5 changes: 5 additions & 0 deletions src/components/NavBar/Desktop/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('<MobileNavBar />', () => {
it.todo('render texts correctly')

it.todo('toggles the NavBar when BackIcon is clicked')
})
39 changes: 39 additions & 0 deletions src/components/NavBar/Desktop/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useState } from 'react'

import { SoundClickButton } from '../../../utils/Sounds/index'
import Equalizer from '../../Equalizer'
import { navBarMock } from '../Navbar.mock'
import * as S from './styles'

const DesktopNavBar = () => {
const [isOpen, setIsOpen] = useState(true)

const closeNavBar = () => {
SoundClickButton()
setIsOpen(!isOpen)
}

return (
<>
<S.Wrapper showNavBar={isOpen}>
<S.NavBar>
{navBarMock.map(({ name }, idx) => (
<S.Item key={idx}>
<S.Link>{name}</S.Link>
</S.Item>
))}
</S.NavBar>
<S.RollbackContainer>
<Equalizer />
<S.BackIcon onClick={closeNavBar} />
<div />
</S.RollbackContainer>
</S.Wrapper>
<S.WrapperColapsed showNavBar={!isOpen}>
<S.GoIcon onClick={closeNavBar} />
</S.WrapperColapsed>
</>
)
}

export default DesktopNavBar
113 changes: 113 additions & 0 deletions src/components/NavBar/Desktop/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import ArrowBackIcon from '@mui/icons-material/ArrowBack'
import ArrowForwardIcon from '@mui/icons-material/ArrowForward'
import { SvgIconProps } from '@mui/material'
import React from 'react'
import styled from 'styled-components'
import medias from '~/src/enums/medias'

const createIconStyles = (Icon: React.ComponentType<SvgIconProps>) => styled(
Icon
)`
width: 35px;
height: 35px;
cursor: pointer;
transition: 0.3s;
color: var(--green-white);
&:hover {
color: var(--white);
}
`

export const Wrapper = styled.nav<{ showNavBar: boolean }>`
display: flex;
flex-direction: column;
height: calc(100vh - 120px);
margin-top: 70px;
overflow-y: auto;
display: ${({ showNavBar }) => !showNavBar && 'none'};
@media (max-width: ${medias.maxTablet}) {
display: none;
}
`

export const WrapperColapsed = styled.nav<{ showNavBar: boolean }>`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
overflow-y: auto;
padding: calc(var(--spacing-basic-small) - 2px);
background-color: var(--green);
border: 1px solid var(--green-white);
display: ${({ showNavBar }) => !showNavBar && 'none'};
@media (max-width: ${medias.maxTablet}) {
display: none;
}
`

export const NavBar = styled.div`
width: 280px;
display: flex;
flex-direction: column;
gap: var(--spacing-basic-small);
overflow-y: auto;
::-webkit-scrollbar {
width: 2px;
}
::-webkit-scrollbar-button {
background-color: var(--black);
}
::-webkit-scrollbar-track-piece {
background-color: var(--black);
}
::-webkit-scrollbar-thumb {
background-color: var(--white);
}
`

export const Item = styled.div`
display: flex;
align-items: center;
width: 100%;
transition: 0.3s;
padding: var(--spacing-basic-small) 0;
cursor: pointer;
&:hover {
background: var(--green);
a {
color: var(--white);
}
}
`

export const Link = styled.a`
font-size: var(--font-small);
padding-left: var(--spacing-basic);
`

export const RollbackContainer = styled.div`
max-width: 280px;
height: 60px;
color: var(--green-white);
background-color: var(--green);
border: 1px solid var(--green-white);
display: flex;
align-items: center;
justify-content: space-around;
padding: 0 10px;
`

export const BackIcon = createIconStyles(ArrowBackIcon)

export const GoIcon = createIconStyles(ArrowForwardIcon)
5 changes: 5 additions & 0 deletions src/components/NavBar/Mobile/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('<MobileNavBar />', () => {
it.todo('render texts correctly')

it.todo('toggles the NavBar when BackIcon is clicked')
})
24 changes: 24 additions & 0 deletions src/components/NavBar/Mobile/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useState } from 'react'

import { navBarMock } from '../Navbar.mock'
import * as S from './styles'

const MobileNavBar = () => {
const [isOpen, setIsOpen] = useState(false)

return (
<S.Container>
<S.IconOpen onClick={() => setIsOpen(true)} />
<S.WrapperContent isOpen={isOpen}>
<S.IconClose onClick={() => setIsOpen(false)} />
<S.WrapperLinks>
{navBarMock.map(({ name }, idx) => {
return <S.Link key={idx}>{name}</S.Link>
})}
</S.WrapperLinks>
</S.WrapperContent>
</S.Container>
)
}

export default MobileNavBar
57 changes: 57 additions & 0 deletions src/components/NavBar/Mobile/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import CloseIcon from '@mui/icons-material/Close'
import MenuIcon from '@mui/icons-material/Menu'
import { SvgIconProps } from '@mui/material'
import React from 'react'
import styled from 'styled-components'
import medias from '~/src/enums/medias'

type addStyleIcon = {
Icon: React.ComponentType<SvgIconProps>
alignSelfEnd?: boolean
}

const addStyledIcon = ({ Icon, alignSelfEnd }: addStyleIcon) => styled(Icon)`
align-self: ${alignSelfEnd && 'flex-end'};
color: var(--green-white);
cursor: pointer;
transition: 0.1s;
&:active {
color: var(--white);
}
`

export const Container = styled.nav`
@media (min-width: ${medias.maxTablet}) {
display: none;
}
`

export const IconOpen = addStyledIcon({ Icon: MenuIcon })

export const IconClose = addStyledIcon({ Icon: CloseIcon, alignSelfEnd: true })

export const WrapperContent = styled.div<{ isOpen: boolean }>`
width: 100%;
height: 90vh;
background-color: var(--green-dark);
position: absolute;
top: 0;
left: 0;
display: ${({ isOpen }) => (isOpen ? 'flex' : 'none')};
flex-direction: column;
align-items: center;
overflow-y: scroll;
`

export const WrapperLinks = styled.div`
display: flex;
flex-direction: column;
gap: var(--spacing-basic);
`

export const Link = styled.a`
font-size: var(--font-medium);
padding-left: var(--spacing-basic);
cursor: pointer;
`
17 changes: 17 additions & 0 deletions src/components/NavBar/Navbar.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const navBarMock = [
{
name: 'Go',
},
{
name: 'React',
},
{
name: 'Nextjs',
},
{
name: 'Vue',
},
{
name: 'React',
},
]
5 changes: 0 additions & 5 deletions src/components/NavBar/index.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/enums/medias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
minMobile: '360px',
maxMobile: '768px',
maxTablet: '992px',
} as const
Loading

0 comments on commit 41766c7

Please sign in to comment.