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

[SP3] 헤더 디자인 변경 #336

Merged
merged 8 commits into from
Dec 22, 2023
Merged
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
70 changes: 25 additions & 45 deletions src/components/Header/Desktop/DesktopHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import styled from '@emotion/styled';
import { colors } from '@sopt-makers/colors';
import Link from 'next/link';
import { css } from '@emotion/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 { MenuTapType, SingleMenuTap } from '../types';
import { MenuTapType } from '../types';

function DesktopHeader() {
const { handleClickLogo, handleIsSelected } = useHeader();
Expand All @@ -18,43 +19,31 @@ function DesktopHeader() {
</CenterAligner>
<MenuTitlesWrapper>
{menuTapList.map((menuTap) => (
<MenuTap key={menuTap.title} menuTap={menuTap} handleIsSelected={handleIsSelected} />
<MenuTitle
menuColor={menuTap.type}
key={menuTap.title}
href={menuTap.href}
isSelected={handleIsSelected(menuTap.href)}
>
{menuTap.title}
</MenuTitle>
))}
</MenuTitlesWrapper>
</Wrapper>
</>
);
}

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

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

interface MenuTitleProps {
isSelected?: boolean;
isOpened?: boolean;
menuColor: MenuTapType;
}

export const Wrapper = styled.div`
max-width: 1200px;
padding: auto 20px;
height: 100%;
width: 100%;
display: flex;
justify-content: space-between;
Expand Down Expand Up @@ -91,32 +80,12 @@ export const Logo = styled.button`
`;

export const MenuTitlesWrapper = styled.div`
height: 100%;

display: flex;
align-items: center;
`;

export const MenuTitleAnchor = styled(Link)`
font-size: 18px;
height: 100%;
line-height: 36px;
font-weight: 500;
display: block;
color: inherit;
text-decoration: none;
color: white;
background-color: #504ebf;
padding: 6px 32px;
border-radius: 30px;
&:hover {
background-color: #413fac;
}
`;

export const MenuTitle = styled(Link)<MenuTitleProps>`
font-size: 18px;
height: 100%;
line-height: 36px;
font-weight: ${({ isSelected }) => (isSelected ? '700' : '500')};

Expand All @@ -133,9 +102,20 @@ export const MenuTitle = styled(Link)<MenuTitleProps>`
top: 3.5rem; /* this is bad practice */
left: 0;
width: 100%;
border-bottom: 2px solid ${colors.white};
border-bottom: ${({ menuColor }) =>
menuColor !== 'SPECIAL' ? `2px solid ${colors.white}` : 'none'};
}
}

${({ menuColor }) =>
menuColor === 'SPECIAL' &&
css`
margin-left: 20px;
border-radius: 5.869px;
border: 1.027px solid #4786ff;
background: rgba(71, 134, 255, 0.28);
color: #267dff;
`}
`;

export default DesktopHeader;
19 changes: 18 additions & 1 deletion src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react';
import { useIsDesktop, useIsMobile, useIsTablet } from '@src/hooks/useDevice';
import DesktopHeader from './Desktop/DesktopHeader';
import MobileHeader from './Mobile/MobileHeader';
Expand All @@ -8,8 +9,24 @@ export function Header() {
const isTablet = useIsTablet('768px', '939px');
const isMobile = useIsMobile();

const [isTransparent, setIsTransparent] = useState<boolean>(false);

useEffect(() => {
const handleScroll = () => {
const scrollPosition = window.scrollY;

scrollPosition <= 0 ? setIsTransparent(false) : setIsTransparent(true);
};

window.addEventListener('scroll', handleScroll);

return () => {
window.removeEventListener('scroll', handleScroll);
};
});

return (
<S.Wrapper>
<S.Wrapper isTransparent={isTransparent}>
{isDesktop && <DesktopHeader />}
{isTablet && <MobileHeader />}
{isMobile && <MobileHeader />}
Expand Down
24 changes: 18 additions & 6 deletions src/components/Header/Mobile/HeaderMenu.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { colors } from '@sopt-makers/colors';
import Link from 'next/link';
import { css } from '@emotion/react';
import { FadeIn, FadeInDown, FadeOut, FadeOutUp } from '@src/lib/styles/animation';
import { MenuTapType } from '../types';

type MenuType = 'idle' | 'open' | 'close';

Expand All @@ -12,6 +13,7 @@ interface CloseButtonProps extends RootProps {

interface MenuTitleProps {
isSelected?: boolean;
menuColor: MenuTapType;
}

interface RootProps {
Expand All @@ -29,8 +31,8 @@ export const Root = styled.div<RootProps>`
width: 100%;
height: 100vh;

${(props) => {
switch (props.isMenuShown) {
${({ isMenuShown }) => {
switch (isMenuShown) {
case 'open':
return css`
${FadeInDown()}
Expand Down Expand Up @@ -79,8 +81,8 @@ export const CloseButton = styled.button<CloseButtonProps>`
width: 28px;
height: 28px;

${(props) => {
switch (props.isMenuShown) {
${({ isMenuShown }) => {
switch (isMenuShown) {
case 'open':
return css`
${FadeIn}
Expand Down Expand Up @@ -141,11 +143,21 @@ export const MenuTitle = styled.div<MenuTitleProps>`

color: ${({ isSelected }) => (isSelected ? '#fff' : 'rgba(255, 255, 255, 0.5)')};
cursor: pointer;
width: fit-content;

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

${({ menuColor }) =>
menuColor === 'SPECIAL' &&
css`
padding: 0 20px;
border-radius: 5.869px;
border: 1.027px solid #4786ff;
background: rgba(71, 134, 255, 0.28);
color: #267dff;
`}
`;

export const Rules = styled(Link)`
Expand Down
34 changes: 8 additions & 26 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 { MenuState, MenuTapType, SingleMenuTap } from '../types';
import { MenuState } from '../types';
import * as S from './HeaderMenu.style';

function useNoScroll(isMenuShown: MenuState) {
Expand All @@ -26,30 +26,6 @@ interface HeaderMenuProps {
handleHeaderToggleButton: () => void;
}

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

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

function HeaderMenu({ isMenuShown, handleHeaderToggleButton }: HeaderMenuProps) {
useNoScroll(isMenuShown);

Expand All @@ -61,7 +37,13 @@ function HeaderMenu({ isMenuShown, handleHeaderToggleButton }: HeaderMenuProps)
<S.ContentsWrap>
<S.MenuTitlesWrap>
{menuTapList.map((menuTap) => (
<MenuTap key={menuTap.title} menuTap={menuTap} handleIsSelected={handleIsSelected} />
<S.MenuTitle
menuColor={menuTap.type}
key={menuTap.title}
isSelected={handleIsSelected(menuTap.href)}
>
<Link href={menuTap.href}>{menuTap.title}</Link>
</S.MenuTitle>
))}
<S.Background onClick={() => handleHeaderToggleButton()} />
</S.MenuTitlesWrap>
Expand Down
10 changes: 7 additions & 3 deletions src/components/Header/Mobile/MobileHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from '@emotion/styled';
import { colors } from '@sopt-makers/colors';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { useState } from 'react';
Expand All @@ -19,7 +20,7 @@ function MobileHeader() {

return (
<>
<StyledHeader>
<StyledHeader isMenuShown={isMenuShown === 'open'}>
<Logo onClick={() => router.push('/')} />
<ToggleButton onClick={handleHeaderToggleButton}>
<Image src={isMenuShown === 'open' ? xButton.src : menuBar} alt="메뉴 토글 버튼" fill />
Expand All @@ -32,13 +33,16 @@ function MobileHeader() {
);
}

export const StyledHeader = styled.div`
export const StyledHeader = styled.div<{ isMenuShown: boolean }>`
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
z-index: 10;
background-color: transparent;
background-color: ${({ isMenuShown }) => (isMenuShown ? colors.gray950 : 'initial')};
padding: 0 20px;
height: 100%;
transition: background-color 0.6s;
`;

export const Logo = styled.button`
Expand Down
16 changes: 8 additions & 8 deletions src/components/Header/menuTapList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ import { MenuTapList, MenuTapType } from './types';

export const menuTapList: MenuTapList = [
{
type: MenuTapType.Router,
title: 'ABOUT',
type: MenuTapType.DEFAULT,
title: '소개',
href: '/about',
},
{
type: MenuTapType.Router,
type: MenuTapType.DEFAULT,
title: '프로젝트',
href: '/project',
},
{
type: MenuTapType.Router,
title: '블로그',
type: MenuTapType.DEFAULT,
title: '활동 후기',
href: '/blog',
},
{
type: MenuTapType.Router,
type: MenuTapType.DEFAULT,
title: '후원',
href: '/sponsor',
},
{
type: MenuTapType.Router,
title: '리크루팅',
type: MenuTapType.SPECIAL,
title: '지원하기',
href: '/recruit',
},
];
23 changes: 16 additions & 7 deletions src/components/Header/style.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
import styled from '@emotion/styled';
import { colors } from '@sopt-makers/colors';
import { css } from '@emotion/react';

export const Wrapper = styled.header`
export const Wrapper = styled.header<{ isTransparent: boolean }>`
width: 100%;
min-height: 80px;
margin: 0 auto;

display: flex;
justify-content: center;
align-items: center;
position: fixed;
/* background-color: ${colors.gray950}; */
/* backdrop-filter: blur(20px); */
z-index: 100;
padding: 0 20px;
top: 0;

${({ isTransparent }) =>
isTransparent &&
css`
background-color: rgba(0, 0, 0, 0.2);
backdrop-filter: blur(30px);
color: white;
`}

padding: 0 20px;

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

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

justify-content: space-between;
}
Expand Down
Loading
Loading