Input.js
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { useState } from 'react';
import styled from 'styled-components';
import { useHistory } from 'react-router-dom';
import SearchBox from './SearchBox';
import { inputColorMap } from '../../lib/styles/palette';
const InputBlock = styled.div`
input {
padding: ${props => props.size};
padding-right: ${props => props.width};
color: ${props => inputColorMap[props.color].color};
box-shadow: 2px 3px 28px 1px rgba(0, 0, 0, 0.1);
border: 3px solid ${props => inputColorMap[props.color].borderColor};
font-size: ${props => props.size};
&::placeholder {
color: ${props => inputColorMap[props.color].placeholder};
text-transform: uppercase;
}
float: left;
}
float: ${props => props.float || ''};
`;
const SearchIconWrap = styled.div``;
const Input = ({
color,
size,
float,
width,
placeholder = '내용을 입력해 주세요.',
display,
}) => {
const [query, setQuery] = useState('');
const history = useHistory();
return (
<InputBlock
color={color}
size={size}
float={float}
width={width}
placeholder={placeholder}
display={display}
>
<input
placeholder={placeholder}
type="text"
value={query}
onChange={e => setQuery(e.target.value)}
onKeyPress={e => {
if (e.key === 'Enter') {
if (query === '') {
alert('검색어를 입력 해 주세요.');
return;
}
const params = new URLSearchParams({ query });
history.push(`?${params.toString()}`);
}
}}
/>
<SearchIconWrap
onClick={() => {
const params = new URLSearchParams({ query });
history.push(`?${params.toString()}`);
}}
>
<SearchBox color="blue" size="50px" display={display} />
</SearchIconWrap>
</InputBlock>
);
};
export default Input;