Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SP2] blog tab navigation #228

Merged
merged 37 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7145e8a
feat : blog 탭 생성
f0rever0 Oct 18, 2023
8bbcfe5
style : change header style
f0rever0 Oct 18, 2023
94a89ee
feat : 블로그 탭 네비게이션
f0rever0 Oct 18, 2023
12efe7d
style : 전체적인 컬러 코드 변경
f0rever0 Oct 18, 2023
78c2717
feat : blog 탭 생성
f0rever0 Oct 18, 2023
80adbca
style : change header style
f0rever0 Oct 18, 2023
c10ea97
feat : 블로그 탭 네비게이션
f0rever0 Oct 18, 2023
9c116aa
style : 전체적인 컬러 코드 변경
f0rever0 Oct 18, 2023
d9ea44c
Merge branch 'feat/#218-blog-tab-navigation' of https://github.com/so…
f0rever0 Oct 19, 2023
88ae4c1
refactor : change to inline export
f0rever0 Oct 19, 2023
4c2e5f6
refactor: apply color systems
f0rever0 Oct 19, 2023
babab4f
style : header 선택한 탭에 밑줄
f0rever0 Oct 19, 2023
85aa5ef
fix : change constant color
f0rever0 Oct 19, 2023
5c178a1
fix : blog tab mobile boder style
f0rever0 Oct 20, 2023
8966d63
fix : blog tab description
f0rever0 Oct 20, 2023
7dc7385
feat : blog 탭 생성
f0rever0 Oct 18, 2023
43776ca
style : change header style
f0rever0 Oct 18, 2023
8f2e09a
feat : 블로그 탭 네비게이션
f0rever0 Oct 18, 2023
dc3d174
style : 전체적인 컬러 코드 변경
f0rever0 Oct 18, 2023
51d8a5e
feat : blog 탭 생성
f0rever0 Oct 18, 2023
190d379
refactor : change to inline export
f0rever0 Oct 19, 2023
c02989e
refactor: apply color systems
f0rever0 Oct 19, 2023
2064b1e
style : header 선택한 탭에 밑줄
f0rever0 Oct 19, 2023
51d8f9a
fix : change constant color
f0rever0 Oct 19, 2023
d0557d7
fix : blog tab mobile boder style
f0rever0 Oct 20, 2023
5c31a0d
fix : blog tab description
f0rever0 Oct 21, 2023
bb6d10a
style : change tab style
f0rever0 Oct 21, 2023
6058f69
Merge branch 'feat/#218-blog-tab-navigation' of https://github.com/so…
f0rever0 Oct 21, 2023
59cc555
fix : color 상수 코드 사용
f0rever0 Oct 21, 2023
7f2037a
style : footer color 상수로 바꾸기
f0rever0 Oct 21, 2023
74553a9
refactor : change folder name
f0rever0 Oct 21, 2023
3f1bfb4
feat : tab description 어절 단위 줄바꿈
f0rever0 Oct 21, 2023
afe94b6
chore : sopt color libaray 적용
f0rever0 Oct 22, 2023
dc96bc5
style : header 디자인 변경
f0rever0 Oct 22, 2023
5423574
feat : add blog tab title hover style
f0rever0 Oct 22, 2023
1ed8aaf
chore : blogTab 변수명 수정
f0rever0 Oct 22, 2023
173801f
Merge branch 'develop' into feat/#218-blog-tab-navigation
f0rever0 Oct 23, 2023
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
2 changes: 1 addition & 1 deletion src/components/Footer/OriginFooter/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { colors } from '@src/lib/styles/colors';
export const Root = styled.footer`
width: 100%;
min-height: 162px;
background-color: #2a2a2a;
background-color: #17171c;
Copy link
Member

Choose a reason for hiding this comment

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

요것 이제 새 컬러 상수를 사용해 주셔요..!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

요 컬러는 mds에 없어서...! 색상코드를 넣었습니다! pd에게 다시 확인하고 커밋해둘게요!


/* 태블릿 + 데스크탑 뷰 */
@media (min-width: 766px) {
Expand Down
150 changes: 10 additions & 140 deletions src/components/Header/Desktop/DesktopHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import styled from '@emotion/styled';
import Link from 'next/link';
import { css } from '@emotion/react';
import { useCallback, useEffect, useState } from 'react';
import { LOGO_IMAGE_URL } from '@src/assets/mainLogo/base64_logo';
import useHeader from '@src/hooks/useHeader';
import { GrowDown } from '@src/lib/styles/animation';
import { menuTapList } from '../menuTapList';
import { BaseMenuTap, MenuTapType, ParentMenuTap } from '../types';
import { MenuTapType, SingleMenuTap } from '../types';

function DesktopHeader() {
const { handleClickLogo, handleIsSelected } = useHeader();
const [isSubTapOpened, setIsSubTapOpened] = useState(false);

return (
<>
Expand All @@ -20,147 +18,44 @@ function DesktopHeader() {
</CenterAligner>
<MenuTitlesWrapper>
{menuTapList.map((menuTap) => (
<MenuTap
key={menuTap.title}
menuTap={menuTap}
handleIsSelected={handleIsSelected}
isSubTapOpened={isSubTapOpened}
setIsSubTapOpened={setIsSubTapOpened}
/>
<MenuTap key={menuTap.title} menuTap={menuTap} handleIsSelected={handleIsSelected} />
))}
</MenuTitlesWrapper>
</Wrapper>
{isSubTapOpened && <SubMenuWrapper />}
</>
);
}

type MenuTapProps = {
menuTap: BaseMenuTap;
menuTap: SingleMenuTap;
handleIsSelected: (path: string | string[]) => boolean;
isSubTapOpened: boolean;
setIsSubTapOpened: (isOpened: boolean) => void;
};

function MenuTap({ menuTap, handleIsSelected, isSubTapOpened, setIsSubTapOpened }: MenuTapProps) {
function MenuTap({ menuTap, handleIsSelected }: MenuTapProps) {
switch (menuTap.type) {
case MenuTapType.Anchor:
return (
<MenuTitleAnchor
href={menuTap.href}
target="_blank"
rel="noreferrer"
onClick={() => setIsSubTapOpened(false)}
onMouseEnter={() => setIsSubTapOpened(false)}
>
<MenuTitleAnchor href={menuTap.href} target="_blank" rel="noreferrer">
{menuTap.title}
</MenuTitleAnchor>
);
case MenuTapType.Router:
return (
<MenuTitle
isSelected={handleIsSelected(menuTap.href)}
onClick={() => setIsSubTapOpened(false)}
onMouseEnter={() => setIsSubTapOpened(false)}
>
<MenuTitle isSelected={handleIsSelected(menuTap.href)}>
<Link href={menuTap.href}>{menuTap.title}</Link>
</MenuTitle>
);
case MenuTapType.Parent:
return (
<ParentMenu
menuTap={menuTap}
handleIsSelected={handleIsSelected}
isSubTapOpened={isSubTapOpened}
setIsSubTapOpened={setIsSubTapOpened}
/>
);
}
}

type ParentMenuProps = {
menuTap: ParentMenuTap;
handleIsSelected: (path: string | string[]) => boolean;
isSubTapOpened: boolean;
setIsSubTapOpened: (isOpened: boolean) => void;
};

function ParentMenu({
menuTap,
handleIsSelected,
isSubTapOpened,
setIsSubTapOpened,
}: ParentMenuProps) {
const [isOpened, setIsOpened] = useState(false);

const closeSubTap = useCallback(() => {
setIsSubTapOpened(false);
setIsOpened(false);
}, [setIsSubTapOpened, setIsOpened]);

const onMouseIn = () => {
setIsSubTapOpened(true);
setIsOpened(true);
};

useEffect(() => {
if (!isSubTapOpened) {
setIsOpened(false);
}
}, [isSubTapOpened]);

useEffect(() => {
if (isSubTapOpened) {
document.addEventListener('click', closeSubTap);
}
return () => {
document.removeEventListener('click', closeSubTap);
};
}, [closeSubTap, isSubTapOpened]);

return (
<ParentMenuTitle
isSelected={handleIsSelected(menuTap.children.map((t) => t.href))}
isOpened={isOpened}
onMouseEnter={onMouseIn}
onClick={(e) => e.stopPropagation()}
>
{menuTap.title}
{isOpened && (
<SubMenu>
{menuTap.children.map((c) => {
switch (c.type) {
case MenuTapType.Anchor:
return (
<MenuTitle type="sub" key={c.title}>
<MenuTitleAnchor href={c.href} target="_blank" rel="noreferrer">
{c.title}
</MenuTitleAnchor>
</MenuTitle>
);
case MenuTapType.Router:
return (
<MenuTitle type="sub" isSelected={handleIsSelected(c.href)} key={c.title}>
<Link href={c.href}>{c.title}</Link>
</MenuTitle>
);
}
})}
</SubMenu>
)}
</ParentMenuTitle>
);
}

interface MenuTitleProps {
isSelected?: boolean;
isOpened?: boolean;
type?: 'main' | 'sub';
}

export const Wrapper = styled.div`
max-width: 1280px;
width: 90%;
max-width: 1200px;
width: 100%;
display: flex;
justify-content: space-between;
`;
Expand All @@ -175,21 +70,6 @@ export const SubMenuWrapper = styled.div`
animation: growdown 0.4s forwards;
`;

const SubMenu = styled.div`
position: absolute;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;

width: 300px;
top: 80px;
left: 25%; /* it is bad practice */
transform: translateX(-50%);

cursor: default;
`;

export const CenterAligner = styled.div`
display: flex;
align-items: center;
Expand Down Expand Up @@ -256,24 +136,14 @@ export const MenuTitle = styled.div<MenuTitleProps>`
line-height: 36px;
font-weight: ${({ isSelected }) => (isSelected ? '700' : '500')};

color: ${({ type, isSelected }) =>
type === 'sub' ? (isSelected ? '#fff' : 'rgba(255, 255, 255, 0.5)') : '#fff'};
color: ${({ isSelected }) => (isSelected ? '#fff' : 'rgba(255, 255, 255, 0.5)')};
cursor: pointer;
position: relative;
${({ isOpened }) => isOpened && menuTitleUnderline};
${({ isSelected }) => isSelected && menuTitleUnderline}

&:not(:last-child) {
padding-right: 40px;
}

&:hover {
color: #fff;
${({ type }) => type !== 'sub' && menuTitleUnderline}
}
`;

const ParentMenuTitle = styled(MenuTitle)`
position: relative;
`;

export default DesktopHeader;
10 changes: 5 additions & 5 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useIsDesktop, useIsMobile, useIsTablet } from '@src/hooks/useDevice';
import DesktopHeader from './Desktop/DesktopHeader';
import MobileHeader from './Mobile/MobileHeader';
import styles from './header.module.scss';
import * as S from './style';

export function Header() {
const isDesktop = useIsDesktop('992px');
const isTablet = useIsTablet('766px', '991.9px');
const isDesktop = useIsDesktop('940px');
const isTablet = useIsTablet('768px', '939px');
const isMobile = useIsMobile();

return (
<header className={styles.wrapper}>
<S.Wrapper>
{isDesktop && <DesktopHeader />}
{isTablet && <MobileHeader />}
{isMobile && <MobileHeader />}
</header>
</S.Wrapper>
);
}
4 changes: 2 additions & 2 deletions src/components/Header/Mobile/HeaderMenu.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const MenuWrap = styled.div`

export const Background = styled.div`
height: 100vh;
background: #181818;
background: ${colors.gray900};
opacity: 0.8;
`;

Expand Down Expand Up @@ -110,7 +110,7 @@ export const ContentsWrap = styled.div`
display: flex;
flex-direction: column;
justify-content: space-between;
background: #181818;
background: ${colors.gray900};

padding-top: 50px;
margin-bottom: 0px;
Expand Down
16 changes: 2 additions & 14 deletions src/components/Header/Mobile/HeaderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Link from 'next/link';
import { useEffect } from 'react';
import useHeader from '@src/hooks/useHeader';
import { menuTapList } from '../menuTapList';
import { BaseMenuTap, MenuState, MenuTapType } from '../types';
import { MenuState, MenuTapType, SingleMenuTap } from '../types';
import * as S from './HeaderMenu.style';

function useNoScroll(isMenuShown: MenuState) {
Expand All @@ -27,7 +27,7 @@ interface HeaderMenuProps {
}

type MenuTapProps = {
menuTap: BaseMenuTap;
menuTap: SingleMenuTap;
handleIsSelected: (path: string) => boolean;
};

Expand All @@ -47,18 +47,6 @@ function MenuTap({ menuTap, handleIsSelected }: MenuTapProps) {
<Link href={menuTap.href}>{menuTap.title}</Link>
</S.MenuTitle>
);
case MenuTapType.Parent:
return (
<>
{menuTap.children.map((childMenuTap) => (
<MenuTap
key={childMenuTap.title}
menuTap={childMenuTap}
handleIsSelected={handleIsSelected}
/>
))}
</>
);
}
}

Expand Down
26 changes: 0 additions & 26 deletions src/components/Header/header.module.scss

This file was deleted.

15 changes: 2 additions & 13 deletions src/components/Header/menuTapList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,9 @@ export const menuTapList: MenuTapList = [
href: '/project',
},
{
type: MenuTapType.Parent,
type: MenuTapType.Router,
Copy link
Member

Choose a reason for hiding this comment

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

좋네용.. 사실 이제 MenuTapType.Anchor 도 사라지긴 해서 type 이라는 친구도 없어도 되긴 혀요

다른 것이 추가될 수도 있으니 살려두어도 괜찮을 것 같습니당

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MenuTapType.Anchor 도 지울까 했는데,,, 일단 살려뒀습니다!

title: '블로그',
children: [
{
type: MenuTapType.Router,
title: '활동후기',
href: '/review',
},
{
type: MenuTapType.Router,
title: '솝티클',
href: '/sopticle',
},
],
href: '/blog',
},
{
type: MenuTapType.Router,
Expand Down
30 changes: 30 additions & 0 deletions src/components/Header/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import styled from '@emotion/styled';
import { colors } from '@src/lib/styles/colors';

export const Wrapper = styled.header`
width: 100%;
min-height: 80px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
position: fixed;
background-color: ${colors.gray900};
backdrop-filter: blur(20px);
z-index: 100;
padding: 0 20px;
top: 0;

/* 태블릿 + 데스크탑 뷰 */
@media (min-width: 768px) {
height: 48px;
}

/* 모바일 뷰 */
@media (max-width: 767px) {
height: 48px;
min-height: 48px;

justify-content: space-between;
}
`;
Loading
Loading