nuxt / ui

A UI Library for Modern Web Apps, powered by Vue & Tailwind CSS.
https://ui.nuxt.com
MIT License
3.59k stars 420 forks source link

[Opinion] nuxt-icon <Icon> VS nuxtlabs ui <UIcon> is confusing and adds fragmentation #197

Closed ddahan closed 1 year ago

ddahan commented 1 year ago

I love nuxtlabs UI, but the current state of icons in Nuxt is now confusing to me, and I'll try to explain why. Maybe I missed something and people will help me clarify.
 While one of the main advantage to use official stuff is conventions, there are now two official ways to use icons in a Nuxt project: nuxt-icons and nuxtlabs UI.

So first naïve question: which one should I use? I tried to list differences between both projects:

What would I expect instead?

I would expect a single official and clear way to add icons in my project:

As a whole, I think a great advantage of Nuxt is to have conventions and no brainer choices, and that fragmentation should be avoided to keep the great DX and Nuxt philosophy. Please feel free to disagree, I'm no expert and may have missed lots of things here.

Atinux commented 1 year ago

We are aware about this. As the author of Nuxt-icon I agree that right now it is not the best solution to have two different way of using Icons.

Nuxt-icon works with any UI library but has the drawback of downloading the icon at runtime, I plan to rework it as soon as I get more time. The advantage is that you can update icons at runtime (ex from a CMS) and respect the Iconify convention.

NuxtLabs UI icons is aimed for best performance and based on the TailwindCSS icons plugin directly, embedding the base64 directly in the source code at build time and avoid any HTTP calls (even cached) to Iconify. We took this solution for now until Nuxt-icon can level up. It would be nice to see if we can find a way to respect the same convention as Iconify in this plugin though.

I agree in any case and thank you for the feedback. we decided to open source the UI library even if not ideal to offer to the community our work to help ship nice applications faster ❤️

TechAkayy commented 1 year ago

Unocss's preset-icon works similar to UIcon.

@Atinux, with unocss preset-icons, we can install the whole @iconify/json package (larger in size of course) instead of @iconify-json/{collection_name}, that way we can use any iconify icon without installing specific icon collections. Is this possible with UIcon? They key advantage here is we can avoid looking-up the collection-name and defining them in the ui>icons array.

Also, it would be a good idea to stick to the collection:name instead of the i-collection-name. Here are some usage stats from the wider community.

Iconify - Uses collection:name. No prefix supported when copying Icones - Uses collection:name. Supports both formats, supports prefix Nuxt-Icon - Uses collection:name. No prefix support Astro-Icon - Uses collection:name. No prefix support Unocss preset-icons - Supports both formats, supports prefix

Given the fact that collection:name is uses everywhere, it would be good to stick to this (or support both formats). Prefix config would be a bonus.

When we copy from iconify or icones, we don't have to replace the colon with a hyphen everytime. Thanks again!

benjamincanac commented 1 year ago

As we're using https://github.com/egoist/tailwindcss-icons underneath, you can also install the whole @iconify/json package. This plugin follows the same convention as UnoCSS icons preset and uses i-collection-name.

This plugin parses all of your code to search for icons like Tailwind JIT with classes and bundles them, it's quite convenient to have a prefix to achieve this otherwise the boot time would be way too long I guess.

benjamincanac commented 1 year ago

And also, when going to https://icones.js.org, you have a little arrow to select which format you want that will be saved in your local storage: CleanShot 2023-05-19 at 10.28.32@2x.png

TechAkayy commented 1 year ago

Thanks bunch for the detailed explanations. So, if I want to use any icons by installing @iconify/json, how do I specify this in the ui/icons array in the config? Something like:

icons: ['*']?

TechAkayy commented 1 year ago

Just checked the underlying plugin https://github.com/egoist/tailwindcss-icons/blob/main/src/core.ts#L25 and looks like it accepts a string "all" instead of an array of collections.

I tried the below, and it worked, I didn't had to specify which iconsets I wanted to use. Though, it throws a type error because our package expects an array.

  ui: {
    icons: 'all',
  },
benjamincanac commented 1 year ago

@TechAkayy Will change the type to string | string[] then.

Atinux commented 1 year ago

We may also document it too I think

benjamincanac commented 1 year ago

This has been done in https://github.com/nuxtlabs/ui/commit/85b10ba4ee00ae00dcf9ab93220ed0d03361765d and https://github.com/nuxtlabs/ui/commit/0b097352b429e3e11422ee3340a4c5d29786a4b8.

ddahan commented 11 months ago

I guess the work can be done from the other side too, that's why I suggested a small update of the extension: https://github.com/antfu/vscode-iconify/issues/51

ddahan commented 11 months ago

FYI, the Iconify VS Code extension has been updated by antfy to support the NuxtLabs UI syntax as well.