-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
54 lines (53 loc) · 1.49 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search JS</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,300;1,400;1,600&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Source Sans Pro', sans-serif;
background-color: #424243;
}
.product-image {
width: 50px;
height: 50px;
object-fit: contain;
background: #ededed;
border-radius: 5px;
}
</style>
</head>
<body>
</body>
<script src="search-js.js"></script>
<script>
async function getFromApi(keyword = '') {
let res = await fetch('https://dummyjson.com/products/search?q='+keyword)
let json = await res.json()
return json.products.map((p) => {
p.icon = `<img class="product-image" src="${p.thumbnail}" />`
return p
})
}
const searchJs = SearchJS({
theme: 'github-light',
width: '600px',
positionTop: '50px',
data: [],
search : {
placeholder: 'Search products'
},
onSelected : (route) => {
console.log(route)
},
onSearch: (keyword) => {
return getFromApi(keyword)
}
})
searchJs.open()
</script>
</html>