forked from aahmadyar123/CookMyFridge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSearchbar.js
96 lines (86 loc) · 2.18 KB
/
Searchbar.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React from 'react'
import{useState} from 'react'
import styled from 'styled-components'
import {AiOutlineSearch, AiOutlineClose} from 'react-icons/ai'
export const SearchContainer = styled.div`
position: relative;
width: ${(props) => (props.isSearching ? 360 : 48)}px;
height: 40px;
top: 25.06px;
background: #F2F4F8;
border-radius: ${(props) => (props.isSearching ? 0 : 200)}%;
display: flex;
justify-content: space-between;
padding-left: 5px;
translate: all 0.3s ease;
`;
export const SearchInput = styled.input`
padding-left: 48px;
border: none;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: transparent;
outline: none;
font-size: 16px;
border: 1px solid transparent;
&:focus {
border-color: rgba(0, 0, 0, 0.3)
}
`;
export const IconButton = styled.button`
position: relative;
height: 36px;
width: 36px;
top: 3px;
border: none;
z-index: 1;
cursor: pointer;
background: none;
&:hover {
color: white;
&::after {
opacity: 1;
transform: scale(1);
}
}
&::after {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
border-radius: 50%;
z-index: -1;
background: #000;
transistion: 0.2s ease;
transform: scale(0.6);
opacity: 0;
}
`;
export default function Searchbar() {
const [isActive, setIsActive] = useState(false);
// const [searchText, setSearchText] = useState("");
const toggle_search = () => {
setIsActive(!isActive);
};
// const get_input = () => {
// var input = document.getElementById("search_input").value;
// setSearchText(input);
// console.log(input);
// }
return (
<SearchContainer isSearching={isActive}>
<IconButton onClick={toggle_search}>
{isActive ? (
<AiOutlineClose size={18}/>
) : (
<AiOutlineSearch size={22}/>
)}
</IconButton>
<SearchInput id="search_input"/>
</SearchContainer>
);
}