-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch.jsx
94 lines (72 loc) · 1.99 KB
/
Search.jsx
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { useState } from "react";
import "./Search.css"
import Trie from "./trie";
import datas from "./data"
// -------- FEED DATA INTO THE DS ---------
const search = new Trie() ;
datas.forEach(elem => {
search.insertWord(elem[0],elem[1]) ;
});
// ----------------------------------------
// ------- CONFIGURE THE STYLE HERE ------
const componentHeight = "250px" ; // Height of the component
const componentWidth = "100%" ;
const inputHeight = "25px" ; // Height of the text input box
//------- CSS code for futher styling---------
const searchDiv = {
display: "flex",
flexDirection: "column",
width: `${componentWidth}`,
position: "absolute",
zIndex: "10",
left: "0"
}
const inputStyl = {
height: `${inputHeight}`,
borderRight: "none",
borderRadius: "4rem 0 0 4rem",
outline: "none",
paddingLeft: "10px",
width: `calc(100% - ${inputHeight} - 20px)` ,
}
const resultDiv = {
display: "flex" ,
flexDirection: "column",
maxHeight: `${componentHeight}`,
overflowY: "scroll",
borderRadius: "0 0 2rem 2rem" ,
}
const resultStyl = {
textTransform: "capitalize",
cursor: "pointer",
height: "25px" ,
textDecoration: "none",
paddingLeft: "2%",
fontSize: "1.2rem",
fontFamily: "monospace",
backgroundColor: "#EEEEEE",
}
// -----------------------------------------
const Search = () => {
const [Display, setDisplay] = useState([]) ;
const handleChange = (e) => {
setDisplay( search.getWords(e.target.value) ) ;
}
return (
<div id="search" style={searchDiv}>
<div className="input-div">
<input type="text" onChange={handleChange} style={inputStyl} />
<p className="input-icon" style={{height: `${inputHeight}` , width: `${inputHeight}` }}>🔍</p>
</div>
<div style={resultDiv}>
{ Display.map((outer) => (
outer.links.map((inner,ind) => (
<a key={ind} href={inner} style={resultStyl} >{outer.str}</a>
))
))
}
</div>
</div>
)
}
export default Search;