icon icon indicating copy to clipboard operation
icon copied to clipboard

Add universal support for color attribute (similar to CSS icons)

Open Rednas83 opened this issue 1 year ago • 4 comments

<Icon name="uil:github" color="red" /> returns image App.config.ts

// https://github.com/nuxt-modules/icon#configuration-%EF%B8%8F
export default defineAppConfig({
  icon: {
    size: "300%", // default <Icon> size applied
    class: "icon", // default <Icon> class applied
    mode: "css", // svg || css
    aliases: {
      nuxt: "logos:nuxt-icon",
    },
  },
})

Rednas83 avatar Jun 22 '24 09:06 Rednas83

Use style="color:red" instead.

antfu avatar Jun 22 '24 14:06 antfu

This works just like class="text-red-600" for tailwind users. But the docs still mentions color in the example image

Will color as a shorthand be supported again or should the docs be updated?

Rednas83 avatar Jul 01 '24 08:07 Rednas83

This works just like class="text-red-600" for tailwind users. But the docs still mentions color in the example image

Will color as a shorthand be supported again or should the docs be updated?

The color attribute in that reference is regarding the built-in attribute available on the SVG element, that's why it's below the message "you can give all the attributes of the native element" and has a link to the mozilla doc for SVG.

With that said, I do agree that it's a bit confusing in that context.

When using CSS icons (the default now), you must use style or class, otherwise for SVG icons you can continue to use color like you did previously.

danjrwalsh avatar Jul 05 '24 16:07 danjrwalsh

Ok, I migrated to style for now

:color="page.name == selected ? settings.color : page.name == 'Alarms' && coptions.alarm ? 'red' : 'black'" // ISSUE: Not supported
:class="page.name == selected ? `text-[${settings.color}]` : page.name == 'Alarms' && coptions.alarm ? 'text-red-600' : 'text-black'" // ISSUE: Only typed colors are supported
:style="{ color: page.name == selected ? settings.color : page.name == 'Alarms' && coptions.alarm ? 'red' : 'black' }" // ISSUE: Little less convenient??

Is it an idea to also support the color attribute for svg icons? It would make the library much more universal I think🤔

And perhaps also add universal support stroke-width while at it?

Rednas83 avatar Jul 06 '24 11:07 Rednas83

color attribute is a SVG specific feature, just updated the docs to correct the example.

For stroke-width, please keep an eye on https://github.com/nuxt/icon/pull/199

antfu avatar Jul 15 '24 16:07 antfu