Comments (16)
from iconify.
Thanks! Got it working.
2 missing commands:
apm install .
apm link
Not sure if first one was needed.
Unfortunately I couldn't debug it today, so will do it tomorrow. It is working!
from iconify.
I forgot that in version 2 I've already added function similar to createElement: renderSVG
export function createIconElement(icon) {
return Iconify.renderSVG(icon);
}
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:
export function createIconElement(icon) {
return Iconify.iconExists(icon) ? Iconify.renderSVG(icon) : document.createElement('span');
}
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 creates lib/iconify-bundle.js
:
const fs = require("fs");
const iconFinder = require("@iconify/json");
// Source file for Iconify
const iconifySource = "@iconify/iconify/dist/iconify.without-api";
// Bundle file
const outputFile = "./lib/iconify-bundle.js";
// Icon sets to load. Key = prefix in Iconify sets, value = prefix in output
const iconSets = {
octicon: "octicon",
ion: "ion",
foundation: "fi", // Rename "foundation" to "fi"
"icomoon-free": "icomoon", // Rename "icomoon-free" to "icomoon"
mdi: "mdi",
ic: "ic",
"fa-brands": "fab", // Rename "fa-brands" to "fab"
fa: "fa",
};
// Bundle Iconify
const resolvedIconify = require.resolve(iconifySource);
let bundle = fs.readFileSync(resolvedIconify, "utf8");
// Bundle icon sets
Object.keys(iconSets).forEach((prefix) => {
const source = iconFinder.locate(prefix);
if (!source) {
throw new Error(`Unable to locate icon set "${prefix}"`);
}
const data = JSON.parse(fs.readFileSync(source, "utf8"));
// Remove useless metadata
["info", "categories", "themes", "chars"].forEach((attr) => {
delete data[attr];
});
// Change prefix
data.prefix = iconSets[prefix];
// Add to bundle
bundle += "\nIconify.addCollection(" + JSON.stringify(data) + ");";
});
// Save bundle
fs.writeFileSync(outputFile, bundle, "utf8");
console.log(`Saved ${outputFile} (${bundle.length} bytes)`);
// Try to copy .d.ts
const tsSource = resolvedIconify.replace(".js", ".d.ts");
try {
const tsContent = fs.readFileSync(tsSource);
fs.writeFileSync(outputFile.replace(".js", ".d.ts"), tsContent);
} catch (err) {
//
}
Install @iconify/json
as dev dependency, run node build-iconify
.
Then I've replaced lib/icon-service/iconify.js
with this:
import Iconify from "../iconify-bundle";
export function createIconElement(icon) {
return Iconify.iconExists(icon) ? Iconify.renderSVG(icon) : document.createElement('span');
}
// the icon property will be passed into createIconElement automatically
export const testIcons = [
{ icon: "ic:baseline-access-time", color: "yellow" },
{ icon: "mdi:content-save", color: "red" },
];
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 variable iconSet
an object, where key is Iconify prefix, value is prefix you want to use.
Few notes about icon sets:
- Do not use FontAwesome, especially version 4. Version 4 was imported from icon font, icons have very inconsistent spacing and might look terrible. Version 5 is better, but still doesn't follow any sensible grid. It is a badly designed icon set.
- IonIcons you've listed use "ios-" and "md-" prefixes. That's outdated version of IonIcons. New version no longer uses prefixes. Good news is Iconify icon set does include icons with those prefixes, so it will work. Iconify used to include those icons a while ago, crawler instead of removing icons makes them hidden, so old icons are always available in any icon set.
from iconify.
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, use Iconify.stopObserving(node)
.
from iconify.
If you are able to use it without a bundler, you can simply add this line to your header
<script src="https://code.iconify.design/1/1.0.7/iconify.min.js"></script>
from iconify.
I do not have an HTML file to include this in. I am writing a package for Atom which is written inside Electron. I am using Rollup, but I declared iconify as external so the bundler does not make a difference.
See this to know what I am talking about: https://github.com/suda/tool-bar/pull/310/files. I switched to @mdi/js here, however, I was wondering if I can use iconify which allows me to have access to all of the icons.
My question is that what this import does?
import Iconify from '@iconify/iconify';
Is this a function I can call or a class I should initialize?
Basic documentation is needed. This single import will be removed with any type of bundler or minifier. I have disabled all of those but I do not have still any luck
from iconify.
from iconify.
This is my final HTML using the previous method
If it needs to be created using DOM, I can do that too. It is pretty easy for this case.
from iconify.
Using DOM:
import Iconify from '@iconify/iconify';
export async function createMDIIcon(iconName) {
const icon = document.createElement("span")
icon.classList.add("iconify")
icon.setAttribute("data-icon", "ic:baseline-access-time")
return icon
}
from iconify.
I got it working using the beta version.
Also, the async
seems to cause some issues. I went sync
here:
from iconify.
Could you add this simple example to the documentation so others can use?
import Iconify from '@iconify/iconify';
export function createIconElement(iconName) {
const icon = document.createElement("span")
icon.classList.add("iconify")
icon.setAttribute("data-icon", iconName)
return icon
}
const icon = createIconElement("ic:baseline-access-time") // gives your desired icon as an element
I believe something like this createIconElement
function should be part of @iconify
itself.
import Iconify from '@iconify/iconify';
Iconify.createIconElement("..")
from iconify.
from iconify.
I will keep this close until you add those. Thanks!
from iconify.
Do you know of a very simple Atom package that I can play with, which won't require a lot of Electron/Atom knowledge to setup? I'd like to test Iconify behaviour in it.
from iconify.
I set up an environment for you.
- install atom
- (if you like) install atom-ide-javascript
apm install atom-ide-javascript
- clone my branch:
cd ~/.atom/packages
git clone --single-branch --branch iconify https://github.com/aminya/tool-bar.git
cd tool-bar
- Install the deps for the package and fire up Rollup
npm install
npm run dev
- open Atom in dev mode
atom --dev .
-
I set up the
lib/icon-service/iconify.js
for you to edit. This is the only file you need to care about. It has my simple function which makes the icon element. -
To see the changes press (CTRL+SHIFT+F5) to reload Atom.
-
You can open Chrome's dev menu by (CTRL+Shift+P -> running "Window: toggle dev tools")
from iconify.
@cyberalien Thank you so much! I will try these and will let you know how it goes
from iconify.
Related Issues (20)
- Package `@iconify/icons-material-symbols-light` not published to npm HOT 1
- Iconify on Svelte problem - Cannot find module HOT 1
- ✨ Align syntax for icons HOT 2
- Penpot integration HOT 2
- bug[React]: Icon Component does not render icon on first render when using `loadIcons` to preload HOT 5
- iconExists() not working on deployed site HOT 2
- [DEP0166] DeprecationWarning HOT 10
- [BUG] Deprecation Warning on Nuxt.js build due to package.json export HOT 2
- Workerd SSR issues HOT 1
- Hey I found an Issue !! HOT 2
- iconify/vue 使用addCollection加载图标集 还会向远程服务器发起请求吗 我想就将图标集打包到项目中
- Release of icons with android library HOT 8
- @iconify/tailwindcss redundant code HOT 16
- 在uniapp中怎么使用unocss+iconify实现图标展示啊? HOT 1
- 在uniapp中显示不出来图标 HOT 1
- @iconify/tailwind can't use underline HOT 3
- Opacity on icons HOT 1
- Feat: Type definition for all icon names HOT 1
- Icon toggles visibility when scrolled in/out of viewport - observer="false" does not work? HOT 7
- `@iconify-icon/react` prop `observe` didn't work HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iconify.