src/components/Searchbar.jsx   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 44
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 1
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 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