Total Complexity | 1 |
Complexity/F | 0 |
Lines of Code | 44 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import React from "react"; |
||
2 | import { useEffect } from "react"; |
||
3 | import { AiOutlineSearch } from "react-icons/ai"; |
||
4 | |||
5 | const Search = ({ handleSearch, searchPhrase, setSearchPhrase }) => { |
||
6 | useEffect(() => { |
||
7 | const keyDownHandler = (event) => { |
||
8 | if (event.key === "Enter") { |
||
9 | event.preventDefault(); |
||
10 | handleSearch(); |
||
11 | } |
||
12 | }; |
||
13 | |||
14 | document.addEventListener("keydown", keyDownHandler); |
||
15 | |||
16 | return () => { |
||
17 | document.removeEventListener("keydown", keyDownHandler); |
||
18 | }; |
||
19 | }, []); |
||
20 | |||
21 | return ( |
||
22 | <div className="flex row content-center"> |
||
23 | <div className="flex rounded-xl bg-blue-500 hover:bg-blue-600 w-96 transition-colors"> |
||
24 | <button onClick={handleSearch} className="flex items-center"> |
||
25 | <AiOutlineSearch className="w-5 h-5 mx-2 text-white" /> |
||
26 | </button> |
||
27 | <input |
||
28 | type="search" |
||
29 | placeholder="Search Location" |
||
30 | value={searchPhrase} |
||
31 | onChange={(e) => { |
||
32 | setSearchPhrase(e.target.value); |
||
33 | }} |
||
34 | className=" |
||
35 | w-full text-gray-700 text-sm rounded-r-xl bg-slate-300 |
||
36 | p-3 placeholder-gray-700 focus:outline-none focus:border-blue-500" |
||
37 | /> |
||
38 | </div> |
||
39 | </div> |
||
40 | ); |
||
41 | }; |
||
42 | |||
43 | export default Search; |
||
44 |