ColorModeButton

ButtonGitLab
Um Button para alternar entre os modos claro e escuro.

Uso

O componente ColorModeButton estende o componente Button, então você pode passar qualquer propriedade como color, variant, size, etc.

<template>
  <NColorModeButton />
</template>
O botão usa por padrão color="neutral" e variant="ghost".

Exemplos

Com ícones personalizados

Use o app.config.ts para personalizar o ícone com a propriedade ui.icons:

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

Use o vite.config.ts para personalizar o ícone com a propriedade ui.icons:

vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nitro/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        icons: {
          light: 'i-ph-sun',
          dark: 'i-ph-moon'
        }
      }
    })
  ]
})

Com slot de fallback

Como o botão é envolvido em um componente ClientOnly, você pode passar um slot fallback para exibir um placeholder enquanto o componente está carregando.

<template>
  <NColorModeButton>
    <template #fallback>
      <NButton loading variant="ghost" color="neutral" />
    </template>
  </NColorModeButton>
</template>

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" | "accent" | "success" | "info" | "warning" | "error" | "neutral"
variant'ghost' "link" | "ghost" | "solid" | "outline" | "soft" | "subtle"
trailingIconany

Display an icon on the right side.

name string
trailingboolean

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

loadingboolean

When true, the loading icon will be displayed.

iconany

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"
disabledboolean
type'button' "reset" | "submit" | "button"

The type of the button when not a link.

label string
activeColor "primary" | "secondary" | "accent" | "success" | "info" | "warning" | "error" | "neutral"
activeVariant "link" | "ghost" | "solid" | "outline" | "soft" | "subtle"
squareboolean

Render the button with equal padding on all sides.

blockboolean

Render the button full width.

loadingAutoboolean

Set loading state automatically based on the @click promise state

leadingboolean

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

leadingIconany

Display an icon on the left side.

loadingIconappConfig.ui.icons.loadingany

The icon when the loading prop is true.

ui { base?: SlotClass; label?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailingIcon?: SlotClass; }
Este componente também suporta todos os atributos HTML nativos de <button>.

Slots

Slot Type

Changelog

No recent changes