Checkbox 체크박스
체크됨(check)과 체크 해제(uncheck) 상태를 전환하는 입력 요소예요. v-model 지시자로 상태를 제어하고, 레이블·설명·아이콘·색상·변형·크기 등 다양하게 꾸밀 수 있어요.
출처: Nuxt UI
본문
체크됨과 체크 해제 상태를 전환하는 입력 요소예요.
사용법 (Usage)
v-model 지시자를 이용해 Checkbox의 체크 상태를 제어해요.
<script setup lang="ts">
const value = ref(true)
</script>
<template>
<UCheckbox v-model="value" />
</template>
상태를 제어할 필요가 없을 때는 default-value prop으로 초기 값을 설정해요.
<template>
<UCheckbox default-value />
</template>
Indeterminate
v-model 지시자나 default-value prop에 indeterminate 값을 넣어 Checkbox를 불확정(indeterminate) 상태로 만들 수 있어요.
<template>
<UCheckbox default-value="indeterminate" />
</template>
Indeterminate Icon
indeterminate-icon prop으로 불확정 상태 아이콘을 커스터마이즈할 수 있어요. 기본값은 i-lucide-minus예요.
<template>
<UCheckbox default-value="indeterminate" indeterminate-icon="i-lucide-plus" />
</template>
Nuxt:
[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme
app.config.ts의ui.icons.minus키 아래에서 이 아이콘을 전역으로 커스터마이즈할 수 있어요.
Vue:
[!TIP] See: /docs/getting-started/integrations/icons/vue#theme
vite.config.ts의ui.icons.minus키 아래에서 이 아이콘을 전역으로 커스터마이즈할 수 있어요.
Label
label prop으로 Checkbox의 레이블을 설정할 수 있어요.
<template>
<UCheckbox label="Check me" />
</template>
required prop을 사용하면 레이블 옆에 별표(*)가 추가돼요.
<template>
<UCheckbox required label="Check me" />
</template>
Description
description prop으로 Checkbox의 설명을 설정할 수 있어요.
<template>
<UCheckbox label="Check me" description="This is a checkbox." />
</template>
Icon
icon prop으로 Checkbox가 체크됐을 때 표시할 아이콘을 설정할 수 있어요. 기본값은 i-lucide-check예요.
<template>
<UCheckbox icon="i-lucide-heart" default-value label="Check me" />
</template>
Nuxt:
[!TIP] See: /docs/getting-started/integrations/icons/nuxt#theme
app.config.ts의ui.icons.check키 아래에서 이 아이콘을 전역으로 커스터마이즈할 수 있어요.
Vue:
[!TIP] See: /docs/getting-started/integrations/icons/vue#theme
vite.config.ts의ui.icons.check키 아래에서 이 아이콘을 전역으로 커스터마이즈할 수 있어요.
Color
color prop을 이용해 Checkbox의 색상을 바꿀 수 있어요.
<template>
<UCheckbox color="neutral" default-value label="Check me" />
</template>
Variant
variant prop을 이용해 Checkbox의 변형을 바꿀 수 있어요.
<template>
<UCheckbox color="primary" variant="card" default-value label="Check me" />
</template>
Size
size prop을 이용해 Checkbox의 크기를 바꿀 수 있어요.
<template>
<UCheckbox size="xl" variant="list" default-value label="Check me" />
</template>
Indicator
indicator prop으로 표시(indicator) 위치를 바꾸거나 숨길 수 있어요. 기본값은 start예요.
[!NOTE]
indicator가hidden일 때는 아이콘이 대신 레이블 위에 표시돼요.
<template>
<UCheckbox indicator="hidden" variant="card" icon="i-lucide-heart" default-value label="Check me" />
</template>
Disabled
disabled prop으로 Checkbox를 비활성화할 수 있어요.
<template>
<UCheckbox disabled label="Check me" />
</template>
API
Props
/**
* Props for the Checkbox component
*/
interface CheckboxProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
label?: string | undefined;
description?: string | undefined;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* @default 'list'
*/
variant?: "card" | "list" | undefined;
/**
* @default 'md'
*/
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
/**
* Position of the indicator.
* @default 'start'
*/
indicator?: "start" | "end" | "hidden" | undefined;
/**
* Highlight the ring color like a focus state.
* @default false
*/
highlight?: boolean | undefined;
/**
* The icon displayed when checked, or above the label when `indicator` is `hidden`.
* @default appConfig.ui.icons.check
*/
icon?: any;
/**
* The icon displayed when the checkbox is indeterminate.
* @default appConfig.ui.icons.minus
*/
indeterminateIcon?: any;
ui?: { root?: SlotClass; container?: SlotClass; base?: SlotClass; indicator?: SlotClass; icon?: SlotClass; wrapper?: SlotClass; label?: SlotClass; description?: SlotClass; } | undefined;
/**
* When `true`, prevents the user from interacting with the checkbox
*/
disabled?: boolean | undefined;
/**
* When `true`, indicates that the user must set the value before the owning form can be submitted.
*/
required?: boolean | undefined;
/**
* The name of the field. Submitted with its owning form as part of a name/value pair.
*/
name?: string | undefined;
/**
* The value given as data when submitted with a `name`.
* @default "on"
*/
value?: null | string | number | bigint | Record<string, any> | undefined;
/**
* Id of the element
*/
id?: string | undefined;
/**
* The value of the checkbox when it is initially rendered. Use when you do not need to control its value.
*/
defaultValue?: T | "indeterminate" | undefined;
/**
* The controlled value of the checkbox. Can be binded with v-model.
*/
modelValue?: null | T | "indeterminate" | undefined;
/**
* The value used when the checkbox is checked. Defaults to `true`.
*/
trueValue?: T | undefined;
/**
* The value used when the checkbox is unchecked. Defaults to `false`.
*/
falseValue?: T | undefined;
autofocus?: false | true | "true" | "false" | undefined;
form?: string | undefined;
formaction?: string | undefined;
formenctype?: string | undefined;
formmethod?: string | undefined;
formnovalidate?: false | true | "true" | "false" | undefined;
formtarget?: string | undefined;
}
[!NOTE] See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes
이 컴포넌트는 모든 네이티브
<button>HTML 속성도 지원해요.
Slots
/**
* Slots for the Checkbox component
*/
interface CheckboxSlots {
label(): any;
description(): any;
}
Emits
/**
* Emitted events for the Checkbox component
*/
interface CheckboxEmits {
change: (payload: [event: Event]) => void;
update:modelValue: (payload: [value: T | "indeterminate"]) => void;
}
테마 (Theme)
export default defineAppConfig({
ui: {
checkbox: {
slots: {
root: 'relative flex items-start',
container: 'flex items-center',
base: 'rounded-sm ring ring-inset ring-accented overflow-hidden focus-visible:outline-none',
indicator: 'flex items-center justify-center size-full text-inverted',
icon: 'shrink-0',
wrapper: 'w-full',
label: 'block font-medium text-default',
description: 'text-muted'
},
variants: {
color: {
primary: {
indicator: 'bg-primary'
},
secondary: {
indicator: 'bg-secondary'
},
success: {
indicator: 'bg-success'
},
info: {
indicator: 'bg-info'
},
warning: {
indicator: 'bg-warning'
},
error: {
indicator: 'bg-error'
},
neutral: {
indicator: 'bg-inverted'
}
},
variant: {
list: {
root: ''
},
card: {
root: [
'border border-default rounded-lg hover:not-has-disabled:not-has-focus-visible:not-has-data-[state=checked]:bg-elevated/50',
'transition-colors'
]
}
},
indicator: {
start: {
root: 'flex-row',
wrapper: 'ms-2'
},
end: {
root: 'flex-row-reverse',
wrapper: 'me-2'
},
hidden: {
base: 'sr-only',
wrapper: 'flex flex-col items-center gap-1 text-center'
}
},
size: {
xs: {
base: 'size-3',
icon: 'size-2.5',
container: 'h-4',
wrapper: 'text-xs'
},
sm: {
base: 'size-3.5',
icon: 'size-3',
container: 'h-4',
wrapper: 'text-xs'
},
md: {
base: 'size-4',
icon: 'size-3.5',
container: 'h-5',
wrapper: 'text-sm'
},
lg: {
base: 'size-4.5',
icon: 'size-4',
container: 'h-5',
wrapper: 'text-sm'
},
xl: {
base: 'size-5',
icon: 'size-4.5',
container: 'h-6',
wrapper: 'text-base'
}
},
required: {
true: {
label: "after:content-['*'] after:ms-0.5 after:text-error"
}
},
disabled: {
true: {
root: 'opacity-75',
base: 'cursor-not-allowed',
label: 'cursor-not-allowed',
description: 'cursor-not-allowed'
}
},
highlight: {
true: '',
false: ''
},
checked: {
true: ''
}
},
compoundVariants: [
{
indicator: 'hidden',
class: {
container: 'h-auto'
}
},
{
variant: 'card',
highlight: false,
class: {
root: 'hover:not-has-disabled:not-has-focus-visible:not-has-data-[state=checked]:border-accented'
}
},
{
size: 'xs',
indicator: 'hidden',
class: {
icon: 'size-3'
}
},
{
size: 'sm',
indicator: 'hidden',
class: {
icon: 'size-3.5'
}
},
{
size: 'md',
indicator: 'hidden',
class: {
icon: 'size-4'
}
},
{
size: 'lg',
indicator: 'hidden',
class: {
icon: 'size-4.5'
}
},
{
size: 'xl',
indicator: 'hidden',
class: {
icon: 'size-5'
}
},
{
size: 'xs',
variant: 'card',
class: {
root: 'p-2.5'
}
},
{
size: 'sm',
variant: 'card',
class: {
root: 'p-3'
}
},
{
size: 'md',
variant: 'card',
class: {
root: 'p-3.5'
}
},
{
size: 'lg',
variant: 'card',
class: {
root: 'p-4'
}
},
{
size: 'xl',
variant: 'card',
class: {
root: 'p-4.5'
}
},
{
color: 'primary',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-primary/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-primary'
}
},
{
color: 'secondary',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-secondary/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-secondary'
}
},
{
color: 'success',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-success/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-success'
}
},
{
color: 'info',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-info/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-info'
}
},
{
color: 'warning',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-warning/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-warning'
}
},
{
color: 'error',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-error/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-error'
}
},
{
color: 'neutral',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-inverted/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-inverted'
}
},
{
color: 'primary',
variant: 'card',
class: {
root: 'outline-primary/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-primary has-focus-visible:z-[1]'
}
},
{
color: 'secondary',
variant: 'card',
class: {
root: 'outline-secondary/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-secondary has-focus-visible:z-[1]'
}
},
{
color: 'success',
variant: 'card',
class: {
root: 'outline-success/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-success has-focus-visible:z-[1]'
}
},
{
color: 'info',
variant: 'card',
class: {
root: 'outline-info/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-info has-focus-visible:z-[1]'
}
},
{
color: 'warning',
variant: 'card',
class: {
root: 'outline-warning/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-warning has-focus-visible:z-[1]'
}
},
{
color: 'error',
variant: 'card',
class: {
root: 'outline-error/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-error has-focus-visible:z-[1]'
}
},
{
color: 'neutral',
variant: 'card',
class: {
root: 'outline-inverted/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-inverted has-focus-visible:z-[1]'
}
},
{
color: 'primary',
variant: 'list',
indicator: 'hidden',
class: {
root: 'outline-primary/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-primary has-focus-visible:z-[1]'
}
},
{
color: 'secondary',
variant: 'list',
indicator: 'hidden',
class: {
root: 'outline-secondary/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-secondary has-focus-visible:z-[1]'
}
},
{
color: 'success',
variant: 'list',
indicator: 'hidden',
class: {
root: 'outline-success/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-success has-focus-visible:z-[1]'
}
},
{
color: 'info',
variant: 'list',
indicator: 'hidden',
class: {
root: 'outline-info/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-info has-focus-visible:z-[1]'
}
},
{
color: 'warning',
variant: 'list',
indicator: 'hidden',
class: {
root: 'outline-warning/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-warning has-focus-visible:z-[1]'
}
},
{
color: 'error',
variant: 'list',
indicator: 'hidden',
class: {
root: 'outline-error/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-error has-focus-visible:z-[1]'
}
},
{
color: 'neutral',
variant: 'list',
indicator: 'hidden',
class: {
root: 'outline-inverted/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-inverted has-focus-visible:z-[1]'
}
},
{
color: 'primary',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-primary/50 has-data-[state=checked]:bg-primary/10'
}
},
{
color: 'secondary',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-secondary/50 has-data-[state=checked]:bg-secondary/10'
}
},
{
color: 'success',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-success/50 has-data-[state=checked]:bg-success/10'
}
},
{
color: 'info',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-info/50 has-data-[state=checked]:bg-info/10'
}
},
{
color: 'warning',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-warning/50 has-data-[state=checked]:bg-warning/10'
}
},
{
color: 'error',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-error/50 has-data-[state=checked]:bg-error/10'
}
},
{
color: 'neutral',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-inverted/50 has-data-[state=checked]:bg-elevated'
}
},
{
variant: 'card',
disabled: true,
class: {
root: 'cursor-not-allowed'
}
},
{
color: 'primary',
indicator: 'hidden',
highlight: true,
class: {
root: 'not-has-disabled:border-primary not-has-disabled:has-data-[state=checked]:border-primary'
}
},
{
color: 'secondary',
indicator: 'hidden',
highlight: true,
class: {
root: 'not-has-disabled:border-secondary not-has-disabled:has-data-[state=checked]:border-secondary'
}
},
{
color: 'success',
indicator: 'hidden',
highlight: true,
class: {
root: 'not-has-disabled:border-success not-has-disabled:has-data-[state=checked]:border-success'
}
},
{
color: 'info',
indicator: 'hidden',
highlight: true,
class: {
root: 'not-has-disabled:border-info not-has-disabled:has-data-[state=checked]:border-info'
}
},
{
color: 'warning',
indicator: 'hidden',
highlight: true,
class: {
root: 'not-has-disabled:border-warning not-has-disabled:has-data-[state=checked]:border-warning'
}
},
{
color: 'error',
indicator: 'hidden',
highlight: true,
class: {
root: 'not-has-disabled:border-error not-has-disabled:has-data-[state=checked]:border-error'
}
},
{
color: 'neutral',
indicator: 'hidden',
highlight: true,
class: {
root: 'not-has-disabled:border-inverted not-has-disabled:has-data-[state=checked]:border-inverted'
}
},
{
color: 'primary',
highlight: true,
class: {
base: 'ring-primary'
}
},
{
color: 'secondary',
highlight: true,
class: {
base: 'ring-secondary'
}
},
{
color: 'success',
highlight: true,
class: {
base: 'ring-success'
}
},
{
color: 'info',
highlight: true,
class: {
base: 'ring-info'
}
},
{
color: 'warning',
highlight: true,
class: {
base: 'ring-warning'
}
},
{
color: 'error',
highlight: true,
class: {
base: 'ring-error'
}
},
{
color: 'neutral',
highlight: true,
class: {
base: 'ring-inverted'
}
}
],
defaultVariants: {
highlight: false,
size: 'md',
color: 'primary',
variant: 'list',
indicator: 'start'
}
}
}
})