ColorModeSwitch
라이트 모드와 다크 모드를 전환하는 스위치 컴포넌트예요.
출처: Nuxt UI
본문
사용법
ColorModeSwitch 컴포넌트는 Switch 컴포넌트를 확장하므로 color, size 등 어떤 속성이든 전달할 수 있어요.
<template>
<UColorModeSwitch />
</template>
예시
커스텀 아이콘 사용하기
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 ColorModeSwitch component
*/
interface ColorModeSwitchProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* Highlight the ring color like a focus state.
*/
highlight?: boolean | undefined;
ui?: { root?: SlotClass; base?: SlotClass; container?: SlotClass; thumb?: SlotClass; icon?: SlotClass; wrapper?: SlotClass; label?: SlotClass; description?: SlotClass; } | undefined;
/**
* The name of the field. Submitted with its owning form as part of a name/value pair.
*/
name?: string | undefined;
/**
* When `true`, the loading icon will be displayed.
*/
loading?: boolean | undefined;
/**
* @default 'md'
*/
size?: "md" | "xs" | "sm" | "lg" | "xl" | undefined;
autofocus?: false | true | "false" | "true" | undefined;
/**
* When `true`, prevents the user from interacting with the switch.
*/
disabled?: boolean | undefined;
form?: string | undefined;
formaction?: string | undefined;
formenctype?: string | undefined;
formmethod?: string | undefined;
formnovalidate?: false | true | "false" | "true" | undefined;
formtarget?: string | undefined;
label?: string | undefined;
/**
* The icon when the `loading` prop is `true`.
* @default appConfig.ui.icons.loading
*/
loadingIcon?: any;
/**
* The state of the switch when it is initially rendered. Use when you do not need to control its state.
*/
defaultValue?: boolean | undefined;
/**
* When `true`, indicates that the user must set the value before the owning form can be submitted.
*/
required?: boolean | undefined;
id?: string | undefined;
/**
* The value given as data when submitted with a `name`.
*/
value?: string | undefined;
description?: string | undefined;
/**
* The value used when the switch is on. Defaults to `true`.
*/
trueValue?: boolean | undefined;
/**
* The value used when the switch is off. Defaults to `false`.
*/
falseValue?: boolean | undefined;
}
변경 기록
사이트맵
전체 페이지 목록은 사이트맵에서 확인할 수 있어요.