-
Notifications
You must be signed in to change notification settings - Fork 7
SearchForm, Menu, Header컴포넌트 마이그레이션, 404일때 url 주소 변경 #60
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4544eec
feat: Apply emotion to SearchForm - Issue #28
hhhyyo 318dd38
feat: Create SearchForm component - Issue #28
hhhyyo ef7dbc4
feat: Apply Storybook to SearchForm - Issue #28
hhhyyo 95e8f4e
Merge branch 'feature/migration-searchForm' into develop
hhhyyo f32e5ed
conf: Install polished - Issue #27
hhhyyo 662dbb4
feat: Apply emotion to Menu - Issue #27
hhhyyo a5e78c3
feat: Create Menu component - Issue #27
hhhyyo 62b3a73
feat: Apply Storybook to Menu - Issue #27
hhhyyo ea9e7c4
Merge branch 'feature/migration-menu' into develop
hhhyyo 6476af3
feat: Add re-export
hhhyyo 56e4c92
fix: Modify type of StyledButtonProps, StyledIconButtonProps - Issue …
hhhyyo 03a33ad
refactor: Change url when 404 - Issue #37
hhhyyo 088939b
refactor: Change to svgr - Issue #26
hhhyyo 8c53e54
fix: Modify type of StyledButtonProps, StyledIconButtonProps - Issue …
hhhyyo 665ffe0
feat: Apply emotion to Header - Issue #25
hhhyyo ceb8ca8
feat: Migrate Header component - Issue #25
hhhyyo 8c0279f
Merge branch 'feature/migration-header' into develop
hhhyyo 3e78ea7
fix: Modify typo
hhhyyo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import styled from '@emotion/styled'; | ||
| import { IconButton } from 'components'; | ||
|
|
||
| const headerHeight = 70; | ||
|
|
||
| export const StyledHeader = styled.header` | ||
| background-color: ${({ theme }) => theme.color.white}; | ||
| box-shadow: 0 4px 10px rgba(0 0 0 / 10%); | ||
| padding: 0 10px 0 20px; | ||
| position: fixed; | ||
| top: 0; | ||
| left: 0; | ||
| right: 0; | ||
| transition: top 0.2s ease-in-out; | ||
| z-index: 10; | ||
|
|
||
| &.hide { | ||
| top: ${-1 * headerHeight}px; | ||
| } | ||
| `; | ||
|
|
||
| export const StyledDiv = styled.div` | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| max-width: 1500px; | ||
| margin: 0 auto; | ||
| height: ${headerHeight}px; | ||
| `; | ||
|
|
||
| export const StyledIconButton = styled(IconButton)` | ||
| position: fixed; | ||
| right: 20px; | ||
| bottom: 20px; | ||
| cursor: pointer; | ||
| box-shadow: 1px 4px 9px rgb(0 0 0 / 30%); | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,102 @@ | ||
| import { SearchForm, Menu, Button, Logo } from 'components'; | ||
| import { useState, useEffect, useRef } from 'react'; | ||
| // import { useAuthLoading, useAuthUser } from '../../contexts/AuthContext'; | ||
| import lodash from 'lodash'; | ||
| import { createPortal } from 'react-dom'; | ||
| import { StyledHeader, StyledDiv, StyledIconButton } from './Header.styled'; | ||
|
|
||
| export const Header = (): JSX.Element => { | ||
| return <header>Header comes here</header>; | ||
| // const authLoading = useAuthLoading(); | ||
| // const authUser = useAuthUser(); | ||
| // const [showDialog, setShowDialog] = useState(false); | ||
|
|
||
| const [tempAuth, setTempAuth] = useState(false); | ||
| const [hideHeader, setHideHeader] = useState(false); | ||
| const [showScrollToTop, setShowScrollToTop] = useState(false); | ||
| const oldScrollTop = useRef(0); | ||
|
|
||
| /* | ||
| const handleOpenDialog = () => { | ||
| setShowDialog(true); | ||
| }; | ||
|
|
||
| const handleCloseDialog = () => { | ||
| setShowDialog(false); | ||
| }; | ||
| */ | ||
|
|
||
| const handleFocus = () => { | ||
| setHideHeader(false); | ||
| }; | ||
|
|
||
| const handleBlur = () => { | ||
| setHideHeader(window.pageYOffset > 70); | ||
| }; | ||
|
|
||
| const controlHeader = lodash.throttle(() => { | ||
| const currentScrollTop = window.pageYOffset; | ||
| setHideHeader(currentScrollTop > 70 && currentScrollTop > oldScrollTop.current); | ||
| oldScrollTop.current = currentScrollTop; | ||
| }, 300); | ||
|
|
||
| const controlScrollToTop = lodash.debounce(() => { | ||
| const currentScrollTop = window.pageYOffset; | ||
| setShowScrollToTop(currentScrollTop > 500); | ||
| }, 300); | ||
|
|
||
| useEffect(() => { | ||
| document.addEventListener('scroll', controlHeader); | ||
| document.addEventListener('scroll', controlScrollToTop); | ||
| return () => { | ||
| document.removeEventListener('scroll', controlHeader); | ||
| document.removeEventListener('scroll', controlScrollToTop); | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <StyledHeader onFocus={handleFocus} onBlur={handleBlur}> | ||
| <StyledDiv> | ||
| <Logo /> | ||
| <SearchForm /> | ||
| {tempAuth ? ( | ||
| <Menu /> | ||
| ) : ( | ||
| <> | ||
| <Button | ||
| type="button" | ||
| variant="transparent" | ||
| aria-haspopup="dialog" | ||
| aria-label="Open SignIn Dialog" | ||
| title="Open SignIn Dialog" | ||
| // onClick={handleOpenDialog} | ||
| color="black" | ||
| > | ||
| Sign In | ||
| </Button> | ||
| {/* <Auth isVisible={showDialog} onClose={handleClos /eDialog} /> */} | ||
| </> | ||
| )} | ||
| {showScrollToTop && | ||
| createPortal( | ||
| <StyledIconButton | ||
| ariaLabel="Go to Top" | ||
| iconType="up" | ||
| type="button" | ||
| variant="filled" | ||
| color="primaryGreen" | ||
| size="large" | ||
| circle | ||
| onClick={() => { | ||
| window.scroll({ | ||
| top: 0, | ||
| left: 0, | ||
| behavior: 'smooth', | ||
| }); | ||
| }} | ||
| />, | ||
| document.getElementById('__next')!, | ||
| )} | ||
| </StyledDiv> | ||
| </StyledHeader> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
| import { Menu } from './Menu'; | ||
|
|
||
| export default { | ||
| title: 'Menu', | ||
| component: Menu, | ||
| } as ComponentMeta<typeof Menu>; | ||
|
|
||
| const Template: ComponentStory<typeof Menu> = () => <Menu />; | ||
|
|
||
| export const Default = Template.bind({}); | ||
| Default.decorators = [ | ||
| (Story) => ( | ||
| <div style={{ width: '300px', display: 'flex', justifyContent: 'center' }}> | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { css } from '@emotion/react'; | ||
| import styled from '@emotion/styled'; | ||
| import { lighten } from 'polished'; | ||
|
|
||
| export const StyledNav = styled.nav` | ||
| position: relative; | ||
| width: fit-content; | ||
| `; | ||
|
|
||
| export const StyledUl = styled.ul` | ||
| position: absolute; | ||
| top: 60px; | ||
| right: 0; | ||
| background-color: ${({ theme }) => theme.color.menuBg}; | ||
| color: white; | ||
| padding: 5px 0; | ||
| white-space: nowrap; | ||
| z-index: 10; | ||
|
|
||
| & ::before { | ||
| content: ''; | ||
| position: absolute; | ||
| right: 20px; | ||
| top: -9px; | ||
| width: 0; | ||
| height: 0; | ||
| border-style: solid; | ||
| border-width: 0 5px 10px 5px; | ||
| border-color: transparent transparent ${({ theme }) => theme.color.menuBg} transparent; | ||
| } | ||
| `; | ||
|
|
||
| export const StyledLi = styled.li` | ||
| text-align: center; | ||
|
|
||
| & > button, | ||
| & > a { | ||
| width: 100%; | ||
| display: block; | ||
| padding: 15px 25px; | ||
| } | ||
|
|
||
| & :hover { | ||
| ${({ theme }) => { | ||
| const menuBg = theme.color.menuBg; | ||
| return css` | ||
| background-color: ${lighten(0.2, menuBg)}; | ||
| `; | ||
| }} | ||
| } | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import { StyledNav, StyledUl, StyledLi } from './Menu.styled'; | ||
| import { useRouter } from 'next/router'; | ||
| import { IconButton, Button } from 'components'; | ||
| import Link from 'next/link'; | ||
| import { logOut } from 'api/requestAuth'; | ||
|
|
||
| export const Menu = () => { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
|
|
||
| const handleClick = () => { | ||
| setIsOpen(!isOpen); | ||
| }; | ||
|
|
||
| const handleBlur = (e: React.FocusEvent<HTMLElement, Element>) => { | ||
| if (!e.currentTarget.contains(e.relatedTarget)) { | ||
| setIsOpen(false); | ||
| } | ||
| }; | ||
|
|
||
| const router = useRouter(); | ||
|
|
||
| /* | ||
| TODO: 스토리북에서 next.js 설정 후 주석 해제 | ||
| useEffect(() => { | ||
| const handleRouteChange = () => { | ||
| setIsOpen(false); | ||
| }; | ||
|
|
||
| router.events.on('routeChangeStart', handleRouteChange); | ||
|
|
||
| return () => { | ||
| router.events.off('routeChangeStart', handleRouteChange); | ||
| }; | ||
| }, []); | ||
| */ | ||
|
|
||
| return ( | ||
| <StyledNav onBlur={handleBlur}> | ||
| <IconButton | ||
| type="button" | ||
| ariaLabel="User Menu" | ||
| aria-haspopup="true" | ||
| aria-expanded={isOpen} | ||
| color="black" | ||
| size="large" | ||
| variant="transparent" | ||
| iconType="user" | ||
| onClick={handleClick} | ||
| /> | ||
| {isOpen && ( | ||
| <StyledUl> | ||
| <StyledLi> | ||
| <Link href="/my-recipes">My Recipes</Link> | ||
| </StyledLi> | ||
| <StyledLi> | ||
| <Button type="button" variant="transparent" color="white" onClick={logOut}> | ||
| Sign Out | ||
| </Button> | ||
| </StyledLi> | ||
| </StyledUl> | ||
| )} | ||
| </StyledNav> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
| import { SearchForm } from './SearchForm'; | ||
|
|
||
| export default { | ||
| title: 'SearchForm', | ||
| component: SearchForm, | ||
| } as ComponentMeta<typeof SearchForm>; | ||
|
|
||
| const Template: ComponentStory<typeof SearchForm> = () => <SearchForm />; | ||
|
|
||
| export const Default = Template.bind({}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import styled from '@emotion/styled'; | ||
| import { media } from 'utils'; | ||
| import { IconButton } from 'components'; | ||
|
|
||
| export const StyledForm = styled.form` | ||
| position: relative; | ||
| width: fit-content; | ||
| `; | ||
|
|
||
| export const StyledInput = styled.input` | ||
| width: 40vw; | ||
| background: ${({ theme }) => theme.color.searchGray}; | ||
| border: none; | ||
| border-radius: 30px; | ||
| padding: 10px 38px 10px 18px; | ||
| line-height: 1; | ||
|
|
||
| ${media.mobile} { | ||
| width: 50vw; | ||
| } | ||
| `; | ||
|
|
||
| export const StyledIconButton = styled(IconButton)` | ||
| position: absolute; | ||
| right: 10px; | ||
| top: 50%; | ||
| transform: translateY(-50%); | ||
| `; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
커스텀 훅으로 만들어서 사용하면 깔끔할것 같습니다~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 알겠습니다~