Adding custom icons to weweb

Hey, I struggled with this for a long long time so wanted to share in case anyone is wondering.

Credits to: StateChange

Suppose you wanted a 3rd party icon library, such as https://phosphoricons.com/

Here are the steps necessary to install the library.

  1. Find the CDN that you can include
    In the case of phosporicons, its

<script src="https://unpkg.com/@phosphor-icons/web"></script>

  1. Generate JS actions
    Go to https://weweb-embed.statechange.ai/ and paste in the above code like so:

  1. Copy output JS code

  2. Create a global workflow in your weweb app, set the event as on app load (before collection fetch)
    Paste the code like so:

  1. Now you can use the icons anywhere (buttons, icon element)
    Example:

Paste it here:

image

Voila!!

Bonus (not tested yet): You can create a json to have it available in the picker element, from my understanding all you need to do is create a json array like so:

[
{
“name”: “Check Circle”,
“class”: “ph-fill ph-check-circle”
}
]

Then you need to host it somewhere, I suppose you can upload it directly to your app under files.
It will be a long manual process, but then you will be able to just select icons in the editor.

If anyone knows a good way to generate this json dynamically that would be very helpful and time saving!

Hope this helps.

4 Likes

Thanks for sharing this one!

1 Like

@ben bonus tip I just figured out!

If you take the CSS thats here in case of phosphor icons: UNPKG - @phosphor-icons/web

You can upload that to ChatGPT with advanced data analysis mode on, upload the CSS file and ask it to generate the JSON. Uploaded the fonts in WeWeb and now have visual icons selection!!

Fonts and css are uploaded on weweb cdn

ChatGPT Share: Generate Phosphor Icons Array

4 Likes

Thanks for sharing

@AJAW thanks for sharing! given that you are storing all the font files yourself, is there still a need to fetch the icons with the unpkg script on app load? This may be redundant, but not sure.

Yes, you can remove the script from the app load if you upload the icons :slight_smile:

1 Like

Would you know if it’s possible to do this with Google’s Material Icons? I’ve been pulling my hair out trying to figure out how to make them work in the icon section

Its the same process really, here you have a github repo with material icons css and fonts.

You can just install these fonts in your weweb settings → files

Then you need to construct this JSON array that maps the name of the icons to its class, have a look above at how I achieved this with chatgpt.

image

Here you put

Name: Material Icons - Regular/Filled/Whatever
Icons file URL: URL to the .woff2 file you uploaded to weweb
Icons List URL: The JSON mentioned above, this is the hardest part, look here how I made this: Generate Phosphor Icons Array

2 Likes

thanks for this. worked perfectly

Hi, @AJAW! Do you have any idea how to import flat-color-icons like this? Tried it, but flat-color-icons have no font, just an iconify lib that doesn’t work this way. There is another ptoject, @iconify-json/flat-color-icons, but I still didn’t succeed.

how about using the iconify web component inside weweb’s html component?

2 Likes

I’ve tried it at codepen. I can use it as an html, but this way I can’t use it as an icon for the button.
flat-color-icons:google (codepen.io)

That’s very cool, but also it feels like WeWeb should have a more straightforward way to upload custom icon sets? Can we make that a feature request?

1 Like

iconify has an API to generate css, containing required icons (or all of them):

api.iconify.design/flat-color-icons.css?icons=…

I think we can use it to add these icons to Weweb. I’m sure it should be better to have any visual way to add svg icons or iconify sets.

Icons should be in Library. If the lift to make a more simple import is too much - someone needs to just take the 10 most popular open source icon libraries and make plugins to install. It’s kinda insane that building custom components is now easier than just getting icons into the editor.

1 Like

made it!

1 Like

Congrats, neat!

Lol!! It’s funny and also sad we high-five each other for …. successfully importing icons. Someone really needs to build a plugin if the WeWeb team can’t make adding fonts easier.

2 Likes

@AJAW, @Mark_Pederson I’ve made an adaptive converter css → wewb icon json.
topic: Custom Iconify icons as Weweb icons and a tool

2 Likes

how did you make it work? I uploaded the otf and some test json in the same format as above but with md class and it didn’t work. Can you please give me the json file? Please I’m begging you.