Skip to content

Commit 5a47cc6

Browse files
committed
Implement search on home header
1 parent c63f99a commit 5a47cc6

File tree

3 files changed

+122
-22
lines changed

3 files changed

+122
-22
lines changed

src/components/common/RoundButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const RoundButtonBlock = styled.button<RoundButtonBlockProps>`
6363
${props =>
6464
props.border &&
6565
css<RoundButtonBlockProps>`
66-
background: transparent;
66+
background: white;
6767
border: 1px solid ${props => buttonColorMap[props.color].background};
6868
color: ${props => buttonColorMap[props.color].background};
6969
&:hover {
@@ -98,6 +98,7 @@ const RoundButton: React.FC<RoundButtonProps> = ({
9898
color = 'teal',
9999
size = 'DEFAULT',
100100
border = false,
101+
className,
101102
...rest
102103
}) => {
103104
if (to) {

src/components/home/HomeHeader.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
22
import styled from 'styled-components';
3-
import { Logo } from '../../static/svg';
3+
import { Logo, SearchIcon2 } from '../../static/svg';
44
import RoundButton from '../common/RoundButton';
55
import HomeResponsive from './HomeResponsive';
66
import useHeader from './hooks/useHeader';
77
import HeaderUserIcon from '../base/HeaderUserIcon';
88
import useToggle from '../../lib/hooks/useToggle';
99
import HeaderUserMenu from '../base/HeaderUserMenu';
10+
import { Link } from 'react-router-dom';
11+
import { mediaQuery } from '../../lib/styles/media';
1012

1113
export type HomeHeaderProps = {};
1214

@@ -20,6 +22,19 @@ function HomeHeader(props: HomeHeaderProps) {
2022
<Logo />
2123
{user ? (
2224
<Right>
25+
<SearchButton to="/search">
26+
<SearchIcon2 />
27+
</SearchButton>
28+
<RoundButton
29+
border
30+
color="darkGray"
31+
style={{ marginRight: '1.25rem' }}
32+
to="/write"
33+
className="write-button"
34+
>
35+
새 글 작성
36+
</RoundButton>
37+
2338
<HeaderUserIcon user={user} onClick={toggleUserMenu} />
2439
<HeaderUserMenu
2540
onClose={toggleUserMenu}
@@ -30,6 +45,9 @@ function HomeHeader(props: HomeHeaderProps) {
3045
</Right>
3146
) : (
3247
<Right>
48+
<SearchButton to="/search">
49+
<SearchIcon2 />
50+
</SearchButton>
3351
<RoundButton color="darkGray" onClick={onLoginClick}>
3452
로그인
3553
</RoundButton>
@@ -44,6 +62,27 @@ const Block = styled.div`
4462
height: 4rem;
4563
`;
4664

65+
const SearchButton = styled(Link)`
66+
display: flex;
67+
align-items: center;
68+
justify-content: center;
69+
background: transparent;
70+
border: none;
71+
width: 2.5rem;
72+
height: 2.5rem;
73+
outline: none;
74+
border-radius: 50%;
75+
cursor: pointer;
76+
&:hover {
77+
background: rgba(0, 0, 0, 0.045);
78+
}
79+
svg {
80+
width: 1.125rem;
81+
height: 1.125rem;
82+
}
83+
margin-right: 0.75rem;
84+
`;
85+
4786
const Inner = styled(HomeResponsive)`
4887
height: 100%;
4988
display: flex;
@@ -55,6 +94,11 @@ const Right = styled.div`
5594
display: flex;
5695
align-items: center;
5796
position: relative;
97+
.write-button {
98+
${mediaQuery(376)} {
99+
display: none;
100+
}
101+
}
58102
`;
59103

60104
export default HomeHeader;

src/components/home/HomeTab.tsx

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
import React from 'react';
1+
import React, { useRef } from 'react';
22
import styled from 'styled-components';
33
import { NavLink, useLocation } from 'react-router-dom';
44
import palette from '../../lib/styles/palette';
5-
import { MdTrendingUp, MdAccessTime } from 'react-icons/md';
5+
import { MdTrendingUp, MdAccessTime, MdMoreVert } from 'react-icons/md';
66
import { useSpring, animated } from 'react-spring';
7+
import { mediaQuery } from '../../lib/styles/media';
8+
import useToggle from '../../lib/hooks/useToggle';
9+
import MainMobileHeadExtra from '../../components/main/MainMobileHeadExtra';
710

811
export type HomeTabProps = {};
912

1013
function HomeTab(props: HomeTabProps) {
1114
const location = useLocation();
1215

1316
const isRecent = location.pathname === '/recent';
17+
const [extra, toggle] = useToggle(false);
18+
const moreButtonRef = useRef<HTMLDivElement | null>(null);
19+
20+
const onClose = (e: React.MouseEvent<HTMLElement>) => {
21+
if (!moreButtonRef.current) return;
22+
if (
23+
e.target === moreButtonRef.current ||
24+
moreButtonRef.current.contains(e.target as Node)
25+
) {
26+
return;
27+
}
28+
toggle();
29+
};
1430

1531
const springStyle = useSpring({
1632
left: isRecent ? '50%' : '0%',
@@ -21,31 +37,61 @@ function HomeTab(props: HomeTabProps) {
2137
});
2238

2339
return (
24-
<Block>
25-
<NavLink
26-
to="/trending"
27-
activeClassName="active"
28-
isActive={(match, location) => {
29-
return ['/', '/trending'].indexOf(location.pathname) !== -1;
30-
}}
31-
>
32-
<MdTrendingUp />
33-
트렌딩
34-
</NavLink>
35-
<NavLink to="/recent" activeClassName="active">
36-
<MdAccessTime />
37-
최신
38-
</NavLink>
39-
<Indicator style={springStyle} />
40-
</Block>
40+
<Wrapper>
41+
<Block>
42+
<NavLink
43+
to="/trending"
44+
activeClassName="active"
45+
isActive={(match, location) => {
46+
return ['/', '/trending'].indexOf(location.pathname) !== -1;
47+
}}
48+
>
49+
<MdTrendingUp />
50+
트렌딩
51+
</NavLink>
52+
<NavLink to="/recent" activeClassName="active">
53+
<MdAccessTime />
54+
최신
55+
</NavLink>
56+
<Indicator style={springStyle} />
57+
</Block>
58+
<MobileMore ref={moreButtonRef}>
59+
<MdMoreVert className="more" onClick={toggle} />
60+
</MobileMore>
61+
<MainMobileHeadExtra visible={extra} onClose={onClose} />
62+
</Wrapper>
4163
);
4264
}
4365

44-
const Block = styled.div`
66+
const Wrapper = styled.div`
4567
margin-top: 1.5rem;
68+
display: flex;
69+
justify-content: space-between;
70+
align-items: center;
71+
position: relative;
72+
.more {
73+
cursor: pointer;
74+
font-size: 1.5rem;
75+
color: ${palette.gray6};
76+
}
77+
`;
78+
79+
const MobileMore = styled.div`
80+
display: none;
81+
${mediaQuery(944)} {
82+
display: flex;
83+
align-items: center;
84+
justify-content: center;
85+
}
86+
`;
87+
88+
const Block = styled.div`
4689
display: flex;
4790
position: relative;
4891
width: 14rem;
92+
${mediaQuery(944)} {
93+
width: 10rem;
94+
}
4995
a {
5096
width: 7rem;
5197
display: flex;
@@ -55,6 +101,7 @@ const Block = styled.div`
55101
text-decoration: none;
56102
color: ${palette.gray6};
57103
height: 2.875rem;
104+
58105
svg {
59106
font-size: 1.5rem;
60107
margin-right: 0.5rem;
@@ -63,6 +110,14 @@ const Block = styled.div`
63110
color: ${palette.gray8};
64111
font-weight: bold;
65112
}
113+
114+
${mediaQuery(944)} {
115+
font-size: 1rem;
116+
width: 5rem;
117+
svg {
118+
font-size: 1.25rem;
119+
}
120+
}
66121
}
67122
`;
68123

0 commit comments

Comments
 (0)