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

[feature/#1/header] - 헤더 컴포넌트 구현 #18

Merged
merged 13 commits into from
Feb 15, 2024
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
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"axios": "^1.6.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.0.1",
"react-router-dom": "^6.22.0",
"styled-components": "^6.1.8",
"zustand": "^4.5.0"
Expand Down
9 changes: 9 additions & 0 deletions src/assets/svgs/sidepeek_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { IoSearch } from "react-icons/io5"

import {
Box,
Center,
Flex,
Icon,
Input,
InputGroup,
InputRightElement,
Spacer,
} from "@chakra-ui/react"

import HeaderLogo from "./components/HeaderLogo"
import Menu from "./components/Menu"

const Header = () => {
Copy link
Contributor

@whdgur5717 whdgur5717 Feb 14, 2024

Choose a reason for hiding this comment

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

저는 뭔가 Header의 의미 상 들어가는 컴포넌트들을 (대부분 차크라에서 제공하는 컴포넌트를 사용했어도) 하나의 커스텀 컴포넌트로 만들어도 좋을 것 같습니다
예를 들어

<Link
          as={ReactRouterLink}
          to="/">
          <Image
            src={SidePeekLogoSVG}
            alt="side peek logo"
          />
        </Link>

이런걸 Logo 컴포넌트로 만든다던지.. 해서 Header에서는 최대한 깔끔한? return문을 유지하면 나중에 요소 추가하기도 쉽지 않을까..싶습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오... 맞는 말씀이에요
의미상으로 중요한 UI들이 딱히 특별한 로직이 없더라도
가독성 차원에서 컴포넌트로 구분해 놓으면
다른 분들이 읽을 때 훨씬 수월하겠네요!
너무 좋은 조언 감사합니다~! 👍👍

return (
<Center
w="100%"
position="fixed"
bg="white"
boxShadow="md">
<Flex
flex="1"
h="headerHeight"
maxW="1280px"
align="center"
gap="1.6rem"
px="1.6rem">
{/* 로고 */}
<Box>
<HeaderLogo />
</Box>
{/* 검색창 */}
<Box
pl="1.5rem"
alignSelf="end"
pb="2rem">
<InputGroup>
<InputRightElement>
<Icon
as={IoSearch}
w="2rem"
h="2rem"
/>
</InputRightElement>
<Input
size="lg"
variant="flushed"
placeholder="검색어를 입력하세요"
/>
</InputGroup>
</Box>
Comment on lines +36 to +54
Copy link
Contributor

@whdgur5717 whdgur5717 Feb 14, 2024

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.

아 이건 일단 나중에 검색창 컴포넌트로 대체하려고 대충 만든거긴한데
헤더의 검색창이 뭔가 디자인이 살짝 다르다보니까
종혁님 말씀대로 따로 컴포넌트로 빼도 될 것 같네요!
일단은 검색창 나오는데로 수정하겠습니다~

<Spacer />
{/* 메뉴 */}
<Box>
<Menu />
</Box>
</Flex>
</Center>
)
}

export default Header
20 changes: 20 additions & 0 deletions src/components/Header/components/HeaderLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Link as ReactRouterLink } from "react-router-dom"

import { Image, Link } from "@chakra-ui/react"

import SidePeekLogoSVG from "@assets/svgs/sidepeek_logo.svg"

const HeaderLogo = () => {
return (
<Link
as={ReactRouterLink}
to="/">
<Image
src={SidePeekLogoSVG}
alt="side peek logo"
/>
</Link>
)
}

export default HeaderLogo
51 changes: 51 additions & 0 deletions src/components/Header/components/Menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { FaRegBell } from "react-icons/fa"

import { Avatar, HStack, Icon, IconButton } from "@chakra-ui/react"

import NotificationPopover from "./NotificationPopover"
import ProfilePopover from "./ProfilePopover"

const Menu = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

P3 :
Chakra UI에 Menu라는 컴포넌트가 존재해서(select랑 기능 비슷) 자세히는 안 봤지만 나중에 import할 때 조금 꼬일 수 있을 것 같습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chakra UI에 이미 있는거군요;;
근데 이 Menu는 헤더에서만 쓰이는 거기도 하고
혹시 Chakra Menu하고 같이 써야되면 Menu as ChakraMenu로 이름 바꿔서 사용해도 되니까
일단 이대로 머지하겠습니다!

return (
<HStack spacing="1.6rem">
<NotificationPopover
NotificationIconButton={
<IconButton
aria-label="notification popover"
icon={
<Icon
as={FaRegBell}
w="3rem"
h="3rem"
/>
}
bg={"transparent"}
_before={{
content: "''",
position: "absolute",
top: "5%",
right: "10%",
width: "1rem",
height: "1rem",
bg: "red",
borderRadius: "full",
}}
/>
}
/>
<ProfilePopover
ProfileButton={
<Avatar
as="button"
size="md"
aria-label="profile popover"
transition="all 0.2s"
_hover={{ filter: "brightness(90%)" }}
/>
}
/>
</HStack>
)
}

export default Menu
38 changes: 38 additions & 0 deletions src/components/Header/components/NotificationPopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ReactNode } from "react"

import {
Divider,
Heading,
Popover,
PopoverArrow,
PopoverBody,
PopoverCloseButton,
PopoverContent,
PopoverHeader,
PopoverTrigger,
} from "@chakra-ui/react"

interface NotificationPopoverProps {
NotificationIconButton: ReactNode
}

const NotificationPopover = ({
NotificationIconButton,
}: NotificationPopoverProps) => {
return (
<Popover>
<PopoverTrigger>{NotificationIconButton}</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverCloseButton />
<PopoverHeader>
<Heading size="md">알림</Heading>
</PopoverHeader>
<Divider />
<PopoverBody>이쪽에 알림 목록을 넣을 예정입니다</PopoverBody>
</PopoverContent>
</Popover>
)
}

export default NotificationPopover
36 changes: 36 additions & 0 deletions src/components/Header/components/ProfilePopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ReactNode } from "react"

import {
Divider,
Heading,
Popover,
PopoverArrow,
PopoverBody,
PopoverCloseButton,
PopoverContent,
PopoverHeader,
PopoverTrigger,
} from "@chakra-ui/react"

interface ProfilePopoverProps {
ProfileButton: ReactNode
}

const ProfilePopover = ({ ProfileButton }: ProfilePopoverProps) => {
return (
<Popover>
<PopoverTrigger>{ProfileButton}</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverCloseButton />
<PopoverHeader>
<Heading size="md">프로필</Heading>
</PopoverHeader>
<Divider />
<PopoverBody>이쪽에 프로필 팝오버 목록을 넣을 예정입니다</PopoverBody>
</PopoverContent>
</Popover>
)
}

export default ProfilePopover
3 changes: 2 additions & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Outlet, createBrowserRouter } from "react-router-dom"
import App from "@/App"

import TestPage from "@/pages/TestPage/TestPage"

import ErrorPage from "@pages/ErrorPage/ErrorPage"
import HomePage from "@pages/HomePage/HomePage"
import LoginPage from "@pages/LoginPage/LoginPage"
Expand Down
3 changes: 3 additions & 0 deletions src/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const themeConfig = {
toast: 90,
tooltip: 100,
},
sizes: {
headerHeight: "9.5rem",
},
semanticTokens: {},
}

Expand Down