Use a diretiva v-model para controlar o estado marcado do Checkbox.
<script setup lang="ts">
const value = ref(true)
</script>
<template>
<NCheckbox v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(true)
</script>
<template>
<NCheckbox v-model="value" />
</template>
Use a prop default-value para definir o valor inicial quando você não precisa controlar o estado.
<template>
<NCheckbox default-value />
</template>
Use o valor indeterminate na diretiva v-model ou na prop default-value para colocar o Checkbox em um estado indeterminado.
<template>
<NCheckbox default-value="indeterminate" />
</template>
Use a prop indeterminate-icon para personalizar o ícone de indeterminado. O padrão é i-lucide-minus.
<template>
<NCheckbox default-value="indeterminate" indeterminate-icon="i-lucide-plus" />
</template>
Use a prop label para definir o rótulo do Checkbox.
<template>
<NCheckbox label="Check me" />
</template>
Ao usar a prop required, um asterisco é adicionado ao lado do rótulo.
<template>
<NCheckbox required label="Check me" />
</template>
Use a prop description para definir a descrição do Checkbox.
This is a checkbox.
<template>
<NCheckbox label="Check me" description="This is a checkbox." />
</template>
Use a prop icon para definir o ícone do Checkbox quando ele está marcado. O padrão é i-lucide-check.
<template>
<NCheckbox icon="i-lucide-heart" default-value label="Check me" />
</template>
Use a prop color para alterar a cor do Checkbox.
<template>
<NCheckbox color="neutral" default-value label="Check me" />
</template>
Use a prop variant para alterar a variante do Checkbox.
<template>
<NCheckbox color="primary" variant="card" default-value label="Check me" />
</template>
Use a prop size para alterar o tamanho do Checkbox.
<template>
<NCheckbox size="xl" variant="list" default-value label="Check me" />
</template>
Use a prop indicator para alterar a posição ou ocultar o indicador. O padrão é start.
<template>
<NCheckbox indicator="end" variant="card" default-value label="Check me" />
</template>
Use a prop disabled para desabilitar o Checkbox.
<template>
<NCheckbox disabled label="Check me" />
</template>
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
label | string | |
description | string | |
color | 'primary' | "primary" | "secondary" | "accent" | "success" | "info" | "warning" | "error" | "neutral" |
variant | 'list' | "card" | "list" |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
indicator | 'start' | "start" | "end" | "hidden"Position of the indicator. |
highlight | boolean Highlight the ring color like a focus state. | |
icon | appConfig.ui.icons.check | anyThe icon displayed when checked. |
indeterminateIcon | appConfig.ui.icons.minus | anyThe icon displayed when the checkbox is indeterminate. |
disabled | boolean When | |
required | boolean When | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
value | "on" | null | string | number | bigint | Record<string, any>The value given as data when submitted with a |
id | stringId of the element | |
defaultValue | T | "indeterminate"The value of the checkbox when it is initially rendered. Use when you do not need to control its value. | |
modelValue | null | T | "indeterminate"The controlled value of the checkbox. Can be binded with v-model. | |
trueValue | TThe value used when the checkbox is checked. Defaults to | |
falseValue | TThe value used when the checkbox is unchecked. Defaults to | |
autofocus | false | true | "true" | "false" | |
ui | { root?: SlotClass; container?: SlotClass; base?: SlotClass; indicator?: SlotClass; icon?: SlotClass; wrapper?: SlotClass; label?: SlotClass; description?: SlotClass; } |
| Slot | Type |
|---|---|
label | { label: string | undefined; } |
description | { description: string | undefined; } |
| Event | Type |
|---|---|
change | [event: Event] |
update:modelValue | [value: T | "indeterminate"] |
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-3',
indicator: 'flex items-center justify-center size-full text-inverted',
icon: 'shrink-0 size-full',
wrapper: 'w-full',
label: 'block font-medium text-default',
description: 'text-muted'
},
variants: {
color: {
primary: {
base: 'outline-primary/25 focus-visible:ring-primary',
indicator: 'bg-primary'
},
secondary: {
base: 'outline-secondary/25 focus-visible:ring-secondary',
indicator: 'bg-secondary'
},
accent: {
base: 'outline-accent/25 focus-visible:ring-accent',
indicator: 'bg-accent'
},
success: {
base: 'outline-success/25 focus-visible:ring-success',
indicator: 'bg-success'
},
info: {
base: 'outline-info/25 focus-visible:ring-info',
indicator: 'bg-info'
},
warning: {
base: 'outline-warning/25 focus-visible:ring-warning',
indicator: 'bg-warning'
},
error: {
base: 'outline-error/25 focus-visible:ring-error',
indicator: 'bg-error'
},
neutral: {
base: 'outline-inverted/25 focus-visible:ring-inverted',
indicator: 'bg-inverted'
}
},
variant: {
list: {
root: ''
},
card: {
root: 'border border-muted rounded-lg'
}
},
indicator: {
start: {
root: 'flex-row',
wrapper: 'ms-2'
},
end: {
root: 'flex-row-reverse',
wrapper: 'me-2'
},
hidden: {
base: 'sr-only',
wrapper: 'text-center'
}
},
size: {
xs: {
base: 'size-3',
container: 'h-4',
wrapper: 'text-xs'
},
sm: {
base: 'size-3.5',
container: 'h-4',
wrapper: 'text-xs'
},
md: {
base: 'size-4',
container: 'h-5',
wrapper: 'text-sm'
},
lg: {
base: 'size-4.5',
container: 'h-5',
wrapper: 'text-sm'
},
xl: {
base: 'size-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: ''
},
checked: {
true: ''
}
},
compoundVariants: [
{
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: 'card',
class: {
root: 'has-data-[state=checked]:border-primary'
}
},
{
color: 'neutral',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-inverted'
}
},
{
variant: 'card',
disabled: true,
class: {
root: 'cursor-not-allowed'
}
},
{
color: 'primary',
highlight: true,
class: {
base: 'ring-primary'
}
},
{
color: 'neutral',
highlight: true,
class: {
base: 'ring-inverted'
}
}
],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'list',
indicator: 'start'
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nitro/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
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-3',
indicator: 'flex items-center justify-center size-full text-inverted',
icon: 'shrink-0 size-full',
wrapper: 'w-full',
label: 'block font-medium text-default',
description: 'text-muted'
},
variants: {
color: {
primary: {
base: 'outline-primary/25 focus-visible:ring-primary',
indicator: 'bg-primary'
},
secondary: {
base: 'outline-secondary/25 focus-visible:ring-secondary',
indicator: 'bg-secondary'
},
accent: {
base: 'outline-accent/25 focus-visible:ring-accent',
indicator: 'bg-accent'
},
success: {
base: 'outline-success/25 focus-visible:ring-success',
indicator: 'bg-success'
},
info: {
base: 'outline-info/25 focus-visible:ring-info',
indicator: 'bg-info'
},
warning: {
base: 'outline-warning/25 focus-visible:ring-warning',
indicator: 'bg-warning'
},
error: {
base: 'outline-error/25 focus-visible:ring-error',
indicator: 'bg-error'
},
neutral: {
base: 'outline-inverted/25 focus-visible:ring-inverted',
indicator: 'bg-inverted'
}
},
variant: {
list: {
root: ''
},
card: {
root: 'border border-muted rounded-lg'
}
},
indicator: {
start: {
root: 'flex-row',
wrapper: 'ms-2'
},
end: {
root: 'flex-row-reverse',
wrapper: 'me-2'
},
hidden: {
base: 'sr-only',
wrapper: 'text-center'
}
},
size: {
xs: {
base: 'size-3',
container: 'h-4',
wrapper: 'text-xs'
},
sm: {
base: 'size-3.5',
container: 'h-4',
wrapper: 'text-xs'
},
md: {
base: 'size-4',
container: 'h-5',
wrapper: 'text-sm'
},
lg: {
base: 'size-4.5',
container: 'h-5',
wrapper: 'text-sm'
},
xl: {
base: 'size-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: ''
},
checked: {
true: ''
}
},
compoundVariants: [
{
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: 'card',
class: {
root: 'has-data-[state=checked]:border-primary'
}
},
{
color: 'neutral',
variant: 'card',
class: {
root: 'has-data-[state=checked]:border-inverted'
}
},
{
variant: 'card',
disabled: true,
class: {
root: 'cursor-not-allowed'
}
},
{
color: 'primary',
highlight: true,
class: {
base: 'ring-primary'
}
},
{
color: 'neutral',
highlight: true,
class: {
base: 'ring-inverted'
}
}
],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'list',
indicator: 'start'
}
}
}
})
]
})