Skip to content

Commit 62ed268

Browse files
committed
[#46] 페이지 헤더에 들어가는 검색 기능 구현
1 parent 97e87eb commit 62ed268

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

src/components/page-header/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
display: flex;
55
justify-content: center;
66
width: 100%;
7-
height: 80px;
7+
height: 60px;
88

99

1010
.page-header {

src/components/post-search/index.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
import { Autocomplete } from '@mui/material';
2-
import React, { useCallback, useState } from 'react';
1+
import React from 'react';
32
import { navigate } from 'gatsby';
4-
import { TextField } from '@material-ui/core';
5-
import { SearchOutlined } from '@material-ui/icons';
6-
import { Box } from '@mui/system';
3+
import { Autocomplete, TextField } from '@mui/material';
4+
import SearchIcon from '@mui/icons-material/SearchOutlined';
75
import './style.scss';
86

97
function PostSearch({ posts }) {
10-
const [searchState, setSearchState] = useState({
11-
query: '',
12-
results: posts,
13-
});
14-
158
return (
169
<Autocomplete
1710
freeSolo
1811
disableClearable
19-
options={searchState.results}
12+
options={posts}
2013
onInputChange={(event, value, reason) => {
2114
if (reason === 'reset' && value) {
22-
const item = searchState.results.find((item) => item.title === value);
15+
const item = posts.find((item) => item.title === value);
2316
if (!item) return;
2417
navigate(item.slug);
2518
}
@@ -31,10 +24,10 @@ function PostSearch({ posts }) {
3124
}
3225
getOptionLabel={(option) => option.title}
3326
renderInput={(params) => (
34-
<Box sx={{ display: 'flex', alignItems: 'flex-end', width: 120 }}>
35-
<SearchOutlined sx={{ color: 'action.active', marginRight: 5, mr: 1, my: 0.5 }} />
36-
<TextField className="search-input" {...params} size="medium" />
37-
</Box>
27+
<div className="search-input-wrapper">
28+
<SearchIcon className="search-icon" />
29+
<TextField className="search-input" variant="standard" {...params} size="medium" />
30+
</div>
3831
)}
3932
/>
4033
);
Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
@use '../../styles/variables'as *;
2+
@use '../../styles/mixins'as *;
3+
4+
5+
.search-input-wrapper {
6+
display: none;
7+
align-items: flex-end;
8+
width: 180px;
9+
margin-bottom: 6px;
10+
11+
@include md {
12+
display: flex;
13+
}
14+
}
15+
16+
.search-icon {
17+
margin-right: 2px;
18+
font-size: 22px;
19+
color: var(--primary-text-color);
20+
}
221

322
.search-input {
423
width: 100%;
524
height: 100%;
6-
font-family: $font-family;
7-
color: var(--primary-text-color) !important;
25+
margin-left: 5px;
26+
padding-left: 2px;
827
vertical-align: center;
9-
transition: width 300ms ease;
28+
29+
.MuiInputBase-input {
30+
font-family: $font-family;
31+
font-size: 15px;
32+
color: var(--primary-text-color) !important;
33+
}
34+
35+
.MuiInput-underline:before {
36+
border-bottom-color: var(--primary-text-color);
37+
border-bottom-width: 1px;
38+
}
39+
40+
.MuiInput-underline:after {
41+
border-bottom-color: var(--primary-text-color);
42+
}
1043
}

0 commit comments

Comments
 (0)