├── .env ├── .github └── FUNDING.yml ├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── content ├── 1.png ├── 2.png ├── Screenshot from 2021-04-30 23-19-16.png └── filestructure.yml ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.js ├── components ├── data │ └── data.js ├── map │ ├── SearchChildList.js │ └── searchList.js └── search │ └── search.js ├── index.css └── index.js /.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Nika Shamiladze 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React-Search 2 | 3 | # Why i using react-search? 4 | 5 | 12 |
13 |

14 | Input without result, searched

15 | 16 |

17 |
18 |

19 | Input with list

20 | 21 |

22 |
23 |

24 | Input With Searched

25 | 26 |

27 | 28 |

The example below ensures that all items in JSON are retrieved and sorted by search. You will notice a strange removeItem pointer performing a deletion of an item in JSON. Depending on which one the user chooses to search. react-search is not a framework nor a package it is a simple code that helps you not to rewrite the same code several times in different projects

29 | 30 | ```jsx 31 | { 32 | renderData.length > 0 && ( 33 |
34 | {renderData 35 | .filter((val) => { 36 | if (val.title.toLowerCase().includes(input.toLowerCase())) { 37 | return val; 38 | } 39 | }) 40 | .map((item) => { 41 | const { id } = item; 42 | return ( 43 | <> 44 | removeItem(id)} /> 45 | 46 | ); 47 | })} 48 |
49 | ); 50 | } 51 | ``` 52 | 53 |

In the example below we will process a popup and we will indicate that it will process the photo, name, and ID. Hopefully the code is very easy to write and easy to modify and is built entirely on the 2 useState method. Which handles the entire code.

54 | 55 | ```jsx 56 |
57 |
58 | {title} 59 |

{title}

60 |
61 |
62 | 65 |
66 |
67 | ``` 68 | 69 | ## Contributing 70 | 71 | The main purpose of this repository is to continue evolving React Search core, making it faster and easier to use. Development of React Search happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving React Search. 72 | 73 | ## [Code of Conduct](CODE_OF_CONDUCT.md) 74 | 75 | React Search has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated. 76 | 77 | ## [Contributing Guide](CONTRIBUTING.md) 78 | 79 | Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React Search. 80 | 81 | ## License 82 | 83 | React Search is [MIT licensed](LICENSE) 84 | -------------------------------------------------------------------------------- /content/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asyncfinkd/react-search/041a8466cf879f73f556875e281f5943e3be17f7/content/1.png -------------------------------------------------------------------------------- /content/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asyncfinkd/react-search/041a8466cf879f73f556875e281f5943e3be17f7/content/2.png -------------------------------------------------------------------------------- /content/Screenshot from 2021-04-30 23-19-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asyncfinkd/react-search/041a8466cf879f73f556875e281f5943e3be17f7/content/Screenshot from 2021-04-30 23-19-16.png -------------------------------------------------------------------------------- /content/filestructure.yml: -------------------------------------------------------------------------------- 1 | - file: src 2 | file_child: app.js 3 | file_child: index.js 4 | file_child: index.css 5 | - child_folder: components 6 | file_child: data/data.js 7 | file_child: map/searchList.js 8 | file_child: map/searchChildList.js 9 | file_child: search/search.js 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-search", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.12.0", 7 | "@testing-library/react": "^11.2.6", 8 | "@testing-library/user-event": "^12.8.3", 9 | "react": "^17.0.2", 10 | "react-dom": "^17.0.2", 11 | "react-scripts": "4.0.3", 12 | "web-vitals": "^1.1.1" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asyncfinkd/react-search/041a8466cf879f73f556875e281f5943e3be17f7/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | react-search 8 | 9 | 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asyncfinkd/react-search/041a8466cf879f73f556875e281f5943e3be17f7/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asyncfinkd/react-search/041a8466cf879f73f556875e281f5943e3be17f7/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import Search from "./components/search/search"; 3 | 4 | export default function App() { 5 | const [input, setInput] = useState(""); 6 | const [showPopup, setShowPopup] = useState(false); 7 | return ( 8 | <> 9 | setInput(e.target.value)} 13 | setPopup={() => { 14 | setShowPopup(true); 15 | }} 16 | closePopup={() => { 17 | setShowPopup(false); 18 | }} 19 | /> 20 | 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /src/components/data/data.js: -------------------------------------------------------------------------------- 1 | export const data = [ 2 | { 3 | id: 0, 4 | title: "Mark Zuckerberg", 5 | image: 6 | "https://www.crn.com/resources/01f8-09ea46bdfc45-87d2b95884d8-1000/zuckerberg_mark_facebook400.jpg", 7 | }, 8 | { 9 | id: 1, 10 | title: "Bill Gates", 11 | image: "https://myhero.com/content/images/thumbs/0035826_bill-gates.jpeg", 12 | }, 13 | { 14 | id: 2, 15 | title: "Elon Musk", 16 | image: 17 | "https://www.sme.org/globalassets/sme.org/technologies/articles/2018/08---august/elon-musk-twitter.jpg", 18 | }, 19 | { 20 | id: 3, 21 | title: "Jeff Bezos", 22 | image: 23 | "https://global-uploads.webflow.com/5dfd5aca7badfa129f80056c/5f89c9db933d223a087f5aa3_JeffBezosRecommendedBooks.jpeg", 24 | }, 25 | ]; 26 | -------------------------------------------------------------------------------- /src/components/map/SearchChildList.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export default function SearchChildList({ id, image, title, removeItem }) { 4 | return ( 5 | <> 6 |
7 |
8 | {title} 9 |

{title}

10 |
11 |
12 | 15 |
16 |
17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /src/components/map/searchList.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { data } from "../data/data"; 3 | import SearchChildList from "./SearchChildList"; 4 | 5 | export default function SearchList({ input }) { 6 | const [renderData, setRenderData] = useState(data); 7 | const removeItem = (id) => { 8 | const newItem = renderData.filter((data2) => data2.id !== id); 9 | setRenderData(newItem); 10 | }; 11 | return ( 12 | <> 13 | {renderData.length > 0 && ( 14 | 33 | )} 34 | 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /src/components/search/search.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import SearchList from "../map/searchList"; 3 | 4 | export default function Search({ 5 | value, 6 | onChange, 7 | popup, 8 | setPopup, 9 | closePopup, 10 | }) { 11 | return ( 12 | <> 13 |
24 |
{ 26 | e.preventDefault(); 27 | }} 28 | className="form" 29 | > 30 |
31 |
32 | 42 | 43 | 44 |
45 |
46 | 53 |
54 |
55 | {popup && } 56 | 57 | 58 | ); 59 | } 60 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | box-sizing: border-box; 5 | } 6 | 7 | body { 8 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, 9 | Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; 10 | padding: 0 10px 0 10px; 11 | overflow-x: hidden; 12 | } 13 | 14 | .form { 15 | display: flex; 16 | align-items: center; 17 | flex-direction: column; 18 | margin-top: 1rem; 19 | z-index: 10; 20 | } 21 | 22 | .child-input-container { 23 | width: 88%; 24 | max-width: 100%; 25 | } 26 | 27 | .form .input-container { 28 | width: 350px; 29 | max-width: 100%; 30 | border: 1px solid #dfe1e5; 31 | display: flex; 32 | align-items: center; 33 | height: 44px; 34 | } 35 | 36 | .form .input-container .input { 37 | color: rgba(0, 0, 0, 0.87); 38 | outline: none; 39 | flex: 1; 40 | border: none; 41 | width: 100%; 42 | } 43 | 44 | .form .input-container .input.h-full { 45 | height: 35px; 46 | margin-left: 8px; 47 | margin-right: 8px; 48 | } 49 | 50 | .form .input-container .input.h-min { 51 | height: 27px; 52 | margin-left: 8px; 53 | margin-right: 8px; 54 | } 55 | 56 | .form .input-container.def { 57 | border-radius: 4px; 58 | } 59 | 60 | .form .input-container .input::placeholder { 61 | text-transform: capitalize; 62 | } 63 | 64 | .container-searchList { 65 | background-color: white; 66 | width: 350px; 67 | overflow-y: scroll; 68 | height: 300px; 69 | margin-top: 10px; 70 | border: 1px solid #dfe1e5; 71 | max-width: 100%; 72 | border-radius: 4px; 73 | padding: 15px; 74 | } 75 | 76 | #modal::-webkit-scrollbar { 77 | width: 8px; 78 | } 79 | 80 | /* Track */ 81 | #modal::-webkit-scrollbar-track { 82 | border-radius: 10px; 83 | } 84 | 85 | /* Handle */ 86 | #modal::-webkit-scrollbar-thumb { 87 | background: #3e4042b6; 88 | border-radius: 10px; 89 | } 90 | 91 | /* Handle on hover */ 92 | #modal::-webkit-scrollbar-thumb:hover { 93 | background: rgba(62, 69, 69, 0.775); 94 | } 95 | 96 | .content-image-searchList { 97 | height: 44px; 98 | border-radius: 50%; 99 | object-fit: contain; 100 | } 101 | 102 | .flex { 103 | display: flex; 104 | align-items: center; 105 | } 106 | 107 | .content-searchList:hover { 108 | background-color: #eee; 109 | } 110 | 111 | .content-searchList:nth-child(1) { 112 | margin-top: 0px; 113 | } 114 | 115 | .content-searchList { 116 | margin-top: 10px; 117 | display: flex; 118 | padding: 8px; 119 | border-radius: 5px; 120 | cursor: pointer; 121 | max-width: 100%; 122 | align-items: center; 123 | justify-content: space-between; 124 | } 125 | 126 | .mleft { 127 | margin-left: 8px; 128 | color: #202124; 129 | } 130 | 131 | .close-btn { 132 | background: none; 133 | border: none; 134 | color: #777; 135 | cursor: pointer; 136 | font-size: 22px; 137 | line-height: 15px; 138 | opacity: 0.6; 139 | height: 30px; 140 | width: 30px; 141 | } 142 | 143 | @media (max-width: 375px) { 144 | .input.h-full { 145 | margin-right: 0px !important; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "./index.css"; 4 | import App from "./App"; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById("root") 11 | ); 12 | 13 | // If you want to start measuring performance in your app, pass a function 14 | // to log results (for example: reportWebVitals(console.log)) 15 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 16 | --------------------------------------------------------------------------------