ColorModeButton

ライトモードとダークモードを切り替えるボタン。

使用法

ColorModeButtonコンポーネントはButtonコンポーネントを拡張しているため、color、variant、sizeなどの任意のプロパティを渡すことができます。

<template>
  <UColorModeButton />
</template>
ボタンのデフォルトはcolor="neutral"とvariant="ghost"です。

サンプル

カスタムアイコン付き

app.config.tsを使用して、ui.iconsプロパティでアイコンをカスタマイズします。

app/app.config.ts
export default defineAppConfig({
  ui: {
    icons: {
      light: 'i-lucide-sun-medium',
      dark: 'i-lucide-moon-star'
    }
  }
})

vite.config.tsを使用して、ui.iconsプロパティでアイコンをカスタマイズします。

vite.config.ts
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-lucide-sun-medium',
          dark: 'i-lucide-moon-star'
        }
      }
    })
  ]
})

API

Props

Prop Default Type
as
'button'
any

The 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
any

Display an icon on the right side.

name
string
trailing
boolean

When true, the icon will be displayed on the right side.

loading
boolean

When true, the loading icon will be displayed.

icon
any

Display an icon based on the leading and trailing props.

size
'md'
"md" | "xs" | "sm" | "lg" | "xl"
avatar
AvatarProps

Display an avatar on the left side.

autofocus
false | true | "true" | "false"
disabled
boolean
type
'button'
"reset" | "submit" | "button"

The type of the button when not a link.

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 @click promise state

leading
boolean

When true, the icon will be displayed on the left side.

leadingIcon
any

Display an icon on the left side.

loadingIcon
appConfig.ui.icons.loading
any

The icon when the loading prop is true.

ui
{ base?: SlotClass; label?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailingIcon?: SlotClass; }
このコンポーネントはすべてのネイティブ<button> HTML属性もサポートします。

Changelog

No recent changes