-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpreview-icons.js
69 lines (58 loc) · 1.54 KB
/
preview-icons.js
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
#!/usr/bin/env node
const fs=require('fs');
const http = require('http');
const {getSprite}=require('./svg-to-sprite');
const PORT = process.env.PORT_PREVIEW_ICON || 8001;
const getContent = (svgIcons='') => `
<!doctype html>
<html>
<head><title>svg icon preview</title></head>
<style>
.preview-wrap {
display: grid;
grid-template-columns: repeat(6, minmax(80px, 1fr));
grid-gap: 10px;
}
.svg-item {
text-align: center;
}
.svg-item:hover {
background: #ededed;
}
.svg-item > svg {
width: 48px;
height: 48px;
}
.svg-icon {
width: 20px;
height: 20px;
color: #324558;
fill: #B6C2CD;
margin-right: 8px;
}
</style>
<body>
${svgIcons}
<div class="preview-wrap"></div>
<script>
var allSymbols=document.querySelectorAll('svg > symbol')
var svgElems=[]
allSymbols.forEach(function(item) {
var id=item.getAttribute('id')
svgElems.push('<span class="svg-item">' +
'<svg class="svg-icon" href:link><use xlink:href="#' + id +
'"></use></svg>' +
'<div class="label">' + id.replace('svg-icon-', '') +
'</div></span>'
)
})
document.getElementsByClassName('preview-wrap')[0].innerHTML=svgElems.join('')
</script>
</body>
</html>
`;
const server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
getSprite().then(sprite => res.end(getContent(sprite)));
});
server.listen(PORT, () => console.log(`Open http://localhost:${PORT} to preview svg icons..`));