-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2166 from nagalakshmi08/searchbar
Added functionality to Searchbar
- Loading branch information
Showing
6 changed files
with
181 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import React from "react"; | ||
import { FaSearch } from "react-icons/fa"; | ||
|
||
const SearchBar = ({ searchTerm, handleSearch }) => ( | ||
const SearchBar = ({ searchTerm, handleSearch, searchResults, onResultClick }) => ( | ||
<> | ||
<div className="flex items-center rounded-full border-green-800 border-2 bg-gray-200 px-4 py-2 w-80"> | ||
<input | ||
type="text" | ||
placeholder="Search" | ||
className="bg-transparent outline-none w-full text-green-700" | ||
value={searchTerm} | ||
onChange={handleSearch} | ||
/> | ||
<FaSearch className="text-green-800" /> | ||
<div className="relative"> | ||
<div className="flex items-center rounded-full border-green-800 border-2 bg-gray-200 px-4 py-2 w-80"> | ||
<input | ||
type="text" | ||
placeholder="Search for products" | ||
className="bg-transparent outline-none w-full text-green-700" | ||
value={searchTerm} | ||
onChange={handleSearch} | ||
/> | ||
<FaSearch className="text-green-800" /> | ||
</div> | ||
{searchResults.length > 0 && ( | ||
<ul className="absolute top-12 left-0 bg-white border border-green-800 w-full rounded-md shadow-lg z-10"> | ||
{searchResults.map((result, index) => ( | ||
<li | ||
key={index} | ||
className="px-4 py-2 text-green-700 hover:bg-green-200 cursor-pointer list-none" | ||
onClick={() => onResultClick(result.link)}> | ||
{result.name} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
</> | ||
); | ||
|
||
export default SearchBar; | ||
// SearchBar.jsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters