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

[Question] Recommended way to change icon based on CSS states #270

Open
itpropro opened this issue Oct 6, 2024 · 1 comment
Open

[Question] Recommended way to change icon based on CSS states #270

itpropro opened this issue Oct 6, 2024 · 1 comment

Comments

@itpropro
Copy link

itpropro commented Oct 6, 2024

With UnoCSS, I could do this if I want to change the icon on hover

<button class="i-carbon-close-outline hover:i-carbon-close-filled">
  <span class="sr-only">Close</span>
</button>

What is the recommended way to do this with native CSS and NuxtIcon?
These variants are all a bit much and don't really work well

This avoids group, as there can already be a group class somewhere up the hierarchy.

<button>
  <div class="relative size-4">
    <UIcon name="i-carbon-close-outline" class="absolute top-0 left-0 size-4 peer hover:hidden block" />
    <UIcon name="i-carbon-close-filled" class="absolute top-0 left-0 size-4 peer-hover:block hidden" />
  </div>
</button>

I would also like to avoid JS (same with :name)

const icon = ref<HTMLElement | null>(null)
const isHovered = useElementHover(icon)
...
<button>
  <div ref="icon" class="size-4">
    <UIcon v-show="isHovered" name="i-carbon-close-outline" class="size-4" />
    <UIcon v-show="!isHovered" name="i-carbon-close-filled" class="size-4" />
  </div>
</button>
@itpropro itpropro changed the title [Question] Recommended way to change icon with CSS states [Question] Recommended way to change icon based on CSS states Oct 6, 2024
@itpropro
Copy link
Author

itpropro commented Oct 8, 2024

Any hint @antfu ? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant