iconify: Icon not showing in simple JavaScript
I am trying to use iconify but I cannot. Is this correct? Nothing shows for me. What should I do with Iconify
after import? The documentation is very vauge.
import Iconify from '@iconify/iconify';
export function createIcon(iconName) {
const icon = document.createElement("div");
icon.innerHTML = `
<span class="iconify" data-icon="${iconName}"></span>
`
return icon
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (8 by maintainers)
There are big changes in beta 4 that has just been released, which can solve your problem differently. You don’t really need it, but I think it is worth mentioning if it helps anyone else to solve similar issue.
In original message you wanted Iconify to replace icons in node that isn’t attached to DOM. It wasn’t possible in old version because Iconify scanned only body. Now it is possible.
Method 1 can scan node once, do not watch it for changes:
Iconify.scan(node)
.Method 2 will scan node and will observe it for changes:
Iconify.observe(node)
. To remove observer, useIconify.stopObserving(node)
.I forgot that in version 2 I’ve already added function similar to createElement: renderSVG
It will return null if icon does not exist, which would usually complicate things a bit, however because you also want offline usage, this is not an issue because icon should always exist.
If you want to make sure an element is always returned, even when icon is missing, use this:
As for offline use, best option is to create a bundle.
In your test files I’ve made
build-iconify.js
in root directory that createslib/iconify-bundle.js
:Install
@iconify/json
as dev dependency, runnode build-iconify
.Then I’ve replaced
lib/icon-service/iconify.js
with this:Bundle is 7.35mb in size, which I think is reasonable considering that it includes multiple icon sets.
In
build-iconify.js
change icon sets list as needed. Because you have prefixes for icon sets that are sometimes different from ones used in Iconify, I’ve made variableiconSet
an object, where key is Iconify prefix, value is prefix you want to use.Few notes about icon sets:
Thanks! Got it working.
2 missing commands:
Not sure if first one was needed.
Unfortunately I couldn’t debug it today, so will do it tomorrow. It is working!
Can you try it with version 2?
@iconify/iconify@beta
On Sun, 26 Jul 2020, 13:29 Amin Yahyaabadi, notifications@github.com wrote: