본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

색상 모드 버튼

원문 보기 위키 갱신

색상 모드 버튼 (ColorModeButton)

라이트 모드와 다크 모드를 전환하는 Button 컴포넌트예요. ColorModeButton은 Button 컴포넌트를 확장해서 만들어졌기 때문에 color, variant, size 등 어떤 속성이든 그대로 전달할 수 있어요.

출처: Nuxt UI

본문

사용법 (Usage)

ColorModeButton 컴포넌트는 Button 컴포넌트를 확장하므로 color, variant, size 같은 어떤 속성이든 전달할 수 있어요.

<template>
  <UColorModeButton />
</template>

[!NOTE]

이 버튼은 기본값으로 color="neutral", variant="ghost"를 사용해요.

예시 (Examples)

커스텀 아이콘 사용하기 (With custom icons)

Nuxt:

app.config.ts의 ui.icons 속성을 사용해 아이콘을 커스텀하세요.

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

Vue:

vite.config.ts의 ui.icons 속성을 사용해 아이콘을 커스텀하세요.

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

/**
 * Props for the ColorModeButton component
 */
interface ColorModeButtonProps {
  /**
   * @default 'neutral'
   */
  color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
  /**
   * @default 'ghost'
   */
  variant?: "link" | "ghost" | "solid" | "outline" | "soft" | "subtle" | undefined;
  /**
   * The element or component this component should render as when not a link.
   * @default 'button'
   */
  as?: any;
  /**
   * Display an icon on the right side.
   */
  trailingIcon?: any;
  ui?: { base?: SlotClass; label?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailingIcon?: SlotClass; } | undefined;
  name?: string | undefined;
  /**
   * When `true`, the icon will be displayed on the right side.
   */
  trailing?: boolean | undefined;
  /**
   * When `true`, the loading icon will be displayed.
   */
  loading?: boolean | undefined;
  onClick?: (event: MouseEvent): void | ((event: MouseEvent) => void)[] | undefined;
  /**
   * Display an icon based on the `leading` and `trailing` props.
   */
  icon?: any;
  /**
   * @default 'md'
   */
  size?: "md" | "xs" | "sm" | "lg" | "xl" | undefined;
  /**
   * Display an avatar on the left side.
   */
  avatar?: AvatarProps | undefined;
  /**
   * Class to apply when the link is exact active
   */
  exactActiveClass?: string | undefined;
  /**
   * Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
   */
  viewTransition?: boolean | undefined;
  autofocus?: false | true | "false" | "true" | undefined;
  disabled?: boolean | undefined;
  form?: string | undefined;
  formaction?: string | undefined;
  formenctype?: string | undefined;
  formmethod?: string | undefined;
  formnovalidate?: false | true | "false" | "true" | undefined;
  formtarget?: string | undefined;
  /**
   * The type of the button when not a link.
   * @default 'button'
   */
  type?: "reset" | "submit" | "button" | undefined;
  label?: string | undefined;
  activeColor?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
  activeVariant?: "link" | "ghost" | "solid" | "outline" | "soft" | "subtle" | undefined;
  /**
   * Render the button with equal padding on all sides.
   */
  square?: boolean | undefined;
  /**
   * Render the button full width.
   */
  block?: boolean | undefined;
  /**
   * Set loading state automatically based on the `@click` promise state
   */
  loadingAuto?: boolean | undefined;
  /**
   * When `true`, the icon will be displayed on the left side.
   */
  leading?: boolean | undefined;
  /**
   * Display an icon on the left side.
   */
  leadingIcon?: any;
  /**
   * The icon when the `loading` prop is `true`.
   * @default appConfig.ui.icons.loading
   */
  loadingIcon?: any;
}

[!NOTE] See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes

This component also supports all native <button> HTML attributes.

[!NOTE]

이 컴포넌트는 네이티브 <button> HTML 속성도 모두 지원해요. 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes 문서를 참고해 주세요.

변경 내역 (Changelog)

컴포넌트와 테마의 커밋 기록을 확인해 보세요.


사이트맵 (Sitemap)

전체 사이트맵에서 모든 페이지를 확인할 수 있어요.

더 알아보기 (Learn more)