Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tailwind4 plugin - usage question #2

Open
reisi007 opened this issue Feb 8, 2025 · 4 comments
Open

Tailwind4 plugin - usage question #2

reisi007 opened this issue Feb 8, 2025 · 4 comments

Comments

@reisi007
Copy link

reisi007 commented Feb 8, 2025

Hi,

I will start with having the plugin configured as following:

@plugin "@iconify/tailwind4" {
    prefixes: mdi, material-symbols;
}

I am successfully able to use

  • icon-[material-symbols--open-in-full-rounded]
  • iconify material-symbols--open-in-full-rounded

However I do not understand why the following is not supported (The additional iconify class seems redundant in clean naming mode and it feels counterintuitive in tailwind to use both files):

  • material-symbols--open-in-full-rounded (without iconify)
  • material-symbols--[open-in-full-rounded] / material-symbols-[open-in-full-rounded]

I would have expected instead of iconify-color to have something like material-symbols--colored--open-in-full-rounded

Using

"@iconify/tailwind4": "^1.0.3",
"tailwindcss": "^4.0.4"

Thank you!

@cyberalien
Copy link
Member

Each icon has multiple CSS rules. For example, for material-symbols:open-in-full-rounded actual CSS is:

.material-symbols--open-in-full-rounded {
  display: inline-block;
  --svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M4 21q-.425 0-.712-.288T3 20v-6q0-.425.288-.712T4 13t.713.288T5 14v3.6L17.6 5H14q-.425 0-.712-.288T13 4t.288-.712T14 3h6q.425 0 .713.288T21 4v6q0 .425-.288.713T20 11t-.712-.288T19 10V6.4L6.4 19H10q.425 0 .713.288T11 20t-.288.713T10 21z'/%3E%3C/svg%3E");
  background-color: currentColor;
  -webkit-mask-image: var(--svg);
  mask-image: var(--svg);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}

For other icons code is almost identical, the only difference is in value of --svg variable.

When you use icon-[material-symbols--open-in-full-rounded], plugin renders all CSS above for each icon.

That causes a lot of duplication. Tailwind CSS cannot reduce it.

For that reason, there is a cleaner syntax with common selectors moved to iconify and iconify-color classes. In Tailwind CSS this cannot be done without extra class name.

@cyberalien cyberalien transferred this issue from iconify/iconify Feb 8, 2025
@cyberalien
Copy link
Member

Moved issue to Tailwind 4 plugin repository.

@reisi007
Copy link
Author

reisi007 commented Feb 8, 2025

Hi,

Thanks for commenting.

I was able to use the following additional CSS:

    [class*="mdi--"]:not([class*="iconify"]), [class*="material-symbols--"]:not([class*="iconify"]) {
        @apply iconify;
    }

I am not sure if programatically adding this is possible, but it certainly seems to be a nice workaround. Do you have any input on that. I expext when using icon-[] there is a similar logic under the hood....

If twice the classes are added I am sure also color mode could easily be supported (not needed in my project, but needs consideration on the library level)

I purposely excluded all elements containing iconify classes so that this solution is backward compatible....

edit: Updated selector from starts with to contains

@cyberalien
Copy link
Member

Yes, that works too. Unfortunately, that cannot be done via plugin.

reisi007 added a commit to reisi007/website that referenced this issue Feb 8, 2025
Added the "workaround" from iconify/iconify-tailwind#2 so that people find the solution more easily
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants