The ColorModeButton component extends the Button component, so you can pass any property such as color, variant, size, etc.
<template>
<UColorModeButton />
</template>
color="neutral" and variant="ghost".Use the app.config.ts to customize the icon with the ui.icons property:
export default defineAppConfig({
ui: {
icons: {
light: 'i-ph-sun',
dark: 'i-ph-moon'
}
}
})
Use the vite.config.ts to customize the icon with the ui.icons property:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
icons: {
light: 'i-ph-sun',
dark: 'i-ph-moon'
}
}
})
]
})
As the button is wrapped in a ClientOnly component, you can pass a fallback slot to display a placeholder while the component is loading.
<template>
<UColorModeButton>
<template #fallback>
<UButton loading variant="ghost" color="neutral" />
</template>
</UColorModeButton>
</template>
| Prop | Default | Type |
|---|---|---|
as | 'button' | anyThe element or component this component should render as when not a link. |
color | 'neutral' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
variant | 'ghost' | "link" | "ghost" | "solid" | "outline" | "soft" | "subtle" |
trailingIcon | string | objectDisplay an icon on the right side. | |
name | string | |
active | boolean Force the link to be active independent of the current route. | |
trailing | boolean When | |
loading | boolean When | |
referrerpolicy | "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | |
icon | string | objectDisplay an icon based on the | |
size | 'md' | "md" | "xs" | "sm" | "lg" | "xl" |
avatar | AvatarPropsDisplay an avatar on the left side.
| |
to | string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGenericRoute Location the link should navigate to when clicked on.
| |
autofocus | false | true | "true" | "false" | |
disabled | boolean | |
type | 'button' | "reset" | "submit" | "button"The type of the button when not a link. |
download | any | |
hreflang | string | |
media | string | |
ping | string | |
target | null | string & {} | "_blank" | "_parent" | "_self" | "_top"Where to display the linked URL, as the name for a browsing context. | |
trailingSlash | "append" | "remove"An option to either add or remove trailing slashes in the | |
label | string | |
activeColor | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | |
activeVariant | "link" | "ghost" | "solid" | "outline" | "soft" | "subtle" | |
square | boolean Render the button with equal padding on all sides. | |
block | boolean Render the button full width. | |
loadingAuto | boolean Set loading state automatically based on the | |
leading | boolean When | |
leadingIcon | string | objectDisplay an icon on the left side. | |
loadingIcon | appConfig.ui.icons.loading | string | objectThe icon when the |
ui | { base?: ClassNameValue; label?: ClassNameValue; leadingIcon?: ClassNameValue; leadingAvatar?: ClassNameValue; leadingAvatarSize?: ClassNameValue; trailingIcon?: ClassNameValue; } |
| Slot | Type |
|---|