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

Unocss icons preset as class feature #325

Open
brokuka opened this issue Dec 18, 2024 · 3 comments
Open

Unocss icons preset as class feature #325

brokuka opened this issue Dec 18, 2024 · 3 comments

Comments

@brokuka
Copy link

brokuka commented Dec 18, 2024

Is any chance in future to get https://unocss.dev/presets/icons like behavior ?

@antfu
Copy link
Member

antfu commented Dec 18, 2024

Can you elaborate on what you are expecting?

@brokuka
Copy link
Author

brokuka commented Dec 20, 2024

Using Icon component may cause SSR issue.

Toggle dark theme implementation with UnoCSS:

<script setup lang="ts">
const color = useColorMode()

const isDark = computed(() => color.value === 'dark')
const tooltipText = computed(() => `Change to ${isDark.value ? 'light' : 'dark'} theme`)

function toggleDark() {
  color.preference = isDark.value ? 'light' : 'dark'
}
</script>

<template>
  <Tooltip :text="tooltipText" visible-on-click>
    <UiButton size="icon" variant="outline" @click="toggleDark">
      <span class="i-mdi:weather-sunny dark:i-mdi:weather-night text-xl" />
    </UiButton>
  </Tooltip>
</template>

With Icon component will be:

<template>
	<Tooltip :text="tooltipText" visible-on-click>
		<UiButton size="icon" variant="outline" @click="toggleDark">
			<Icon v-if="isDark" name="mdi:weather-night" />
			<Icon v-else name="mdi:weather-sunny" />
		</UiButton>
	</Tooltip>
</template>

Where you will SSR issue
Image

Of course for "try" to fix this, you have to using Client component, but then there may be UX problems, for example icon loading.

Presumably, to solve this problem you can simply add an optional prop :dark or somehow give the opportunity to use a class instead of icon

@cyberalien
Copy link

If you want to get rid of warning, which is visible only in dev mode and not really an issue, wrap component in <ClientOnly> tag. Dark/light switch is meaningless when UI is not interactive anyway.

@brokuka brokuka changed the title Unocss icons as class feature Unocss icons preset as class feature Dec 25, 2024
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

3 participants