-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
34 lines (29 loc) · 937 Bytes
/
main.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
const heroicons = {
toSvg: function () {
if (typeof document === 'undefined') {
throw new Error(
'`heroicons.toSvg()` only works in a browser environment.'
);
}
const elementsToReplace = document.querySelectorAll('[data-icon]');
Array.from(elementsToReplace).forEach(async (element) => {
const name = element.getAttribute('data-icon');
const type = element.getAttribute('data-type');
import(`./icons/${type}/${name}`).then((icon) => {
const svg = new DOMParser().parseFromString(
icon.default().trim(),
'text/html'
);
const newChild = svg.body.querySelector('svg');
element
.getAttribute('class')
.split(' ')
.forEach((el) => {
newChild.classList.add(el);
});
element.parentNode.replaceChild(newChild, element);
});
});
},
};
export default heroicons;