aboutsummaryrefslogtreecommitdiff
path: root/src/components/Util/SearchBar.tsx
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-08-08 19:23:18 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-08-08 19:23:18 +0530
commit97d32bb98dd669d6ef934036cbf8d4278de0b481 (patch)
tree9a618b759920fdd8e70a9a6dc5708fbf1c36ad41 /src/components/Util/SearchBar.tsx
parent04ef09bba76f8ce3572120c19a3070c45a4af86c (diff)
somehow created a search bar
Diffstat (limited to 'src/components/Util/SearchBar.tsx')
-rw-r--r--src/components/Util/SearchBar.tsx50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/components/Util/SearchBar.tsx b/src/components/Util/SearchBar.tsx
new file mode 100644
index 0000000..d26415b
--- /dev/null
+++ b/src/components/Util/SearchBar.tsx
@@ -0,0 +1,50 @@
+/*
+ * OpenBills - Self hosted browser app to generate and keep track of simple invoices
+ * Version - 0
+ * Licensed under the MIT license - https://opensource.org/licenses/MIT
+ *
+ * Copyright (c) 2021 Vidhu Kant Sharma
+*/
+
+import React, { useState } from "react";
+import "./SearchBar.scss";
+
+const SearchBar: React.FC = () => {
+ const sampledata: string[] = ["one", "two", "three", "four", "five", "six"]
+
+ const [searchValue, setSearchValue] = useState<string>("");
+ const [searchSelection, setSearchSelection] = useState<string>("");
+
+ const setSelectionValue = (value: string) => {
+ setSearchValue("");
+ setSearchSelection(value);
+ console.log(searchSelection);
+ }
+
+ return (
+ <div className="searchBar">
+ <div className="searchBarInput">
+ <input
+ type="text"
+ value={searchValue}
+ onChange={
+ (event) => {
+ setSearchValue(event.target.value);
+ console.log(searchSelection);
+ }
+ }
+ />
+ </div>
+
+ <div className="searchResults">
+ {
+ searchValue === ""
+ || sampledata.map((i) => i.toLowerCase().includes(searchValue.toLowerCase())
+ && (<p key={i} className={"searchResult"} onClick={() => setSelectionValue(i)}>{i}</p>))
+ }
+ </div>
+ </div>
+ );
+}
+
+export default SearchBar;