-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
143 lines (124 loc) · 3.77 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<input id="query" name="query">
<div id="results">
<div class="warn">
Type something to start looking for icons!
</div>
</div>
<style>
input#query {
width: 75%;
height: 30px;
top: 15px;
position: absolute;
left: 50%;
transform: translateX(-50%);
outline: none;
box-shadow: none;
border: 1px solid #000000;
}
div.warn {
text-align: center;
font-size: 6em;
color: #444;
font-family: sans-serif;
font-weight: bold;
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
width: 90%;
}
div#results {
margin-top: 60px;
display: flex;
flex-flow: wrap;
}
div.result {
flex-basis: 0;
min-width: 120px;
padding: 4px 8px;
flex-grow: 1;
text-align: center;
cursor: copy;
display: flex;
flex-flow: column;
}
div.icon {
font-size: 64px;
font-family: 'Material Design Icons';
color: #000000;
}
div.label {
font-size: 14px;
font-family: monospace;
color: #444444;
}
@media screen and (prefers-color-scheme: dark) {
input {
background-color: #222222;
color: #eeeeee;
border: 1px solid #eeeeee;
}
body {
background-color: #000000;
}
div.icon {
color: #dddddd;
}
div.label {
color: #aaaaaa;
}
}
</style>
<script src="icons.js"></script>
<script>
const MAX_ICONS = 200
const iconNames = Object.keys(mdiIcons)
function buildNodesFromResults(results) {
return results.map((result) => {
let container = document.createElement('div')
container.classList = 'result'
container.addEventListener('click', (e) => {
e.preventDefault();
e.stopImmediatePropagation();
navigator.clipboard.writeText(result.icon);
})
let iconContainer = document.createElement('div')
iconContainer.classList = 'icon';
iconContainer.innerText = result['icon']
let labelContainer = document.createElement('div')
labelContainer.classList = 'label'
labelContainer.innerText = result['label']
container.appendChild(iconContainer)
container.appendChild(labelContainer)
return container;
})
}
function search(query) {
query = query.trim().replace(/ /g, '-');
// TODO: add sorting
let nameResults = iconNames.filter((val) => val.indexOf(query) !== -1)
if (nameResults.length > MAX_ICONS) nameResults = nameResults.slice(0, MAX_ICONS)
nameResults.sort((a,b) => {
return a.indexOf(query)
})
return nameResults.map((label) => ({label, icon: String.fromCodePoint(parseInt(mdiIcons[label], 16))}))
}
var input = document.getElementById('query');
var resultsContainer = document.getElementById('results')
input.addEventListener('keyup', function() {
let results = search(input.value);
let nodes = buildNodesFromResults(results);
while (resultsContainer.firstChild) resultsContainer.removeChild(resultsContainer.firstChild)
if (nodes.length === 0) {
let notFound = document.createElement('div')
notFound.classList = 'warn';
notFound.innerText = 'No icons matching your query have been found'
resultsContainer.append(notFound)
} else {
resultsContainer.append(...nodes)
}
})
window.addEventListener('keydown', (e) => {
input.focus();
})
</script>