All files / react-app/src/components/SupportPage search.tsx

100% Statements 10/10
100% Branches 2/2
100% Functions 4/4
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                      77x 18x   18x 1x     18x 3x 3x     18x                                                                     1x 1x                                    
import { XIcon } from "lucide-react";
import { useState } from "react";
 
import { Button } from "@/components";
import { cn } from "@/utils";
 
interface searchProps {
  handleSearch: (s: string) => void;
  placeholderText: string;
}
 
const Search = ({ handleSearch, placeholderText }: searchProps) => {
  const [searchText, setSearchText] = useState("");
 
  const handleButtonClick = () => {
    handleSearch(searchText);
  };
 
  const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const updateText = event.target.value;
    setSearchText(updateText);
  };
 
  const isHidden = searchText ? "visible" : "invisible";
 
  return (
    <div className="flex items-center">
      <form>
        <div className="flex items-center border-gray-500 bg-white mr-5 lg:w-[25rem]">
          <svg
            xmlns="http://www.w3.org/2000/svg"
            className="w-6 h-6 mx-2 text-gray-500"
            fill="none"
            viewBox="0 0 24 24"
            stroke="currentColor"
          >
            <path
              strokeLinecap="round"
              strokeLinejoin="round"
              strokeWidth={2}
              d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
            />
          </svg>
          <div className="border-l h-10 mr-2 border-gray-500"></div>
          <input
            id="searchInput"
            type="text"
            className="w-full py-2 text-gray-500 outline-none focus:bg-white placeholder:italic"
            maxLength={28}
            value={searchText}
            onChange={handleInputChange}
            placeholder={placeholderText}
          />
 
          <XIcon
            className={cn("text-gray-500 mr-2 cursor-pointer", isHidden)}
            data-testid="close-icon"
            onClick={() => {
              setSearchText("");
              handleSearch("");
            }}
            name="close"
          />
        </div>
      </form>
      <Button
        onClick={handleButtonClick}
        variant="outline"
        className="bg-white rounded-sm border-2 hover:border-white hover:text-white"
      >
        Search
      </Button>
    </div>
  );
};
 
export default Search;