forked from reactplay/react-play
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/searcbox/countries statistic (reactplay#526)
* completed search suggestion UI * search suggestion * search functionality * added the auto search functionality * searchbox functionality completed * on map click update the searchbox * added currency symbol along with name * currency sign, population with commas, disabled autocomeplete * clickable searcbar functionality * tab index of map disabled * sorted the search suggestion, defocus event,fixed the unique key warning, * tabindex for input and searchbtn, searchOnKeyEnter function * fixed the scrolling on key press * bug fix hide search results onClikc searchbtn * fixed scrolling bugs Co-authored-by: Koustov <[email protected]>
- Loading branch information
1 parent
888e843
commit 31d391e
Showing
6 changed files
with
252 additions
and
17 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createContext } from "react"; | ||
|
||
export const GeoContext = createContext(); |
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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { useContext } from "react"; | ||
import { BsSearch } from "react-icons/bs"; | ||
import "./countriesStatistic.css"; | ||
|
||
import { GeoContext } from "./Context"; | ||
|
||
const SearchAndFilter = () => { | ||
const { | ||
showSuggestions, | ||
index, | ||
selected, | ||
SearchResult, | ||
searchSuggestionRef, | ||
searchResultItemRef, | ||
keyPressHandler, | ||
handleOnchange, | ||
handleOnFocus, | ||
handleOnBlur, | ||
searchResultClickHandler, | ||
searchbarClickHandler, | ||
searchInputClickHandler, | ||
} = useContext(GeoContext); | ||
|
||
return ( | ||
<div className="w-full max-w-[550px] mx-auto flex justify-center"> | ||
<div | ||
className="relative w-full h-fit" | ||
tabIndex="0" | ||
onBlur={(e) => handleOnBlur(e)} | ||
> | ||
<input | ||
tabIndex="0" | ||
type="text" | ||
className="geo-now-searchbar w-full rounded-lg bg-inherit my-4" | ||
placeholder="Enter the country..." | ||
value={selected} | ||
onChange={(e) => handleOnchange(e)} | ||
onFocus={handleOnFocus} | ||
autoComplete="new-password" | ||
onClick={searchInputClickHandler} | ||
onKeyDown={keyPressHandler} | ||
/> | ||
<div | ||
tabIndex="0" | ||
className="absolute top-[50%] translate-y-[-50%] right-0 w-[30px] h-[30px] mx-2 bg-cyan-500 cursor-pointer" | ||
onClick={searchbarClickHandler} | ||
onKeyDown={keyPressHandler} | ||
> | ||
<BsSearch className="absolute top-1 left-1 text-2xl text-white " /> | ||
</div> | ||
{showSuggestions && ( | ||
<div | ||
tabIndex="-1" | ||
ref={searchSuggestionRef} | ||
className="absolute w-full max-h-[290px] bg-white p-4 overflow-y-auto outline-none" | ||
onKeyDown={(e) => keyPressHandler(e)} | ||
> | ||
{SearchResult.map((country, i) => { | ||
return ( | ||
<div | ||
key={i} | ||
ref={index === i ? searchResultItemRef : null} | ||
onClick={() => searchResultClickHandler(i)} | ||
className={`border-b cursor-pointer hover:bg-cyan-100 font-bold px-2 my-[0.9rem] ${ | ||
index === i ? "geo-search-selected" : "" | ||
}`} | ||
> | ||
{country.properties.name} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SearchAndFilter; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.geo-now-searchbar { | ||
border: 2px solid lightblue !important; | ||
outline: none; | ||
padding-left: 1.5rem !important; | ||
} | ||
.geo-now-searchbar:focus { | ||
outline: solid; | ||
outline-color: lightblue; | ||
outline-width: 2px; | ||
border: none; | ||
background-color: #fff; | ||
} | ||
|
||
.geo-search-selected { | ||
background: lightblue; | ||
} |