Checkbox
Turn an option on or off.
Demos
Size
State
Include archived projectsShow completed work in this view.
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy Checkbox.vue and index.ts into app/components/ui/checkbox/.
app/components/ui/checkbox/Checkbox.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Disables the checkbox. |
id | string | auto | HTML id for the button element. |
name | string | — | HTML name for form submission. |
required | boolean | false | Marks the field as required. |
trueValue | unknown | true | Model value when checked. |
falseValue | unknown | false | Model value when unchecked. |
label | string | — | Label text. Slot #label takes priority. |
description | string | — | Description text. Slot #description takes priority. |
ariaLabel | string | — | Accessible name when no visible label is rendered. |
ariaDescribedby | string | — | IDs of external descriptive elements. |
ui | CheckboxUi | — | CSS class overrides. |
Slots
| Slot | Scoped props | Description |
|---|---|---|
indicator | { checked } | Visual check mark inside the button. checked is true, false, or "indeterminate". |
label | — | Label text. Defaults to the label prop. |
description | — | Description text. Defaults to the description prop. |
Events
| Event | Payload | Description |
|---|---|---|
value-change | [value: CheckboxValue, details] | Fired when the checked state changes. |
Keyboard
| Key | Behavior |
|---|---|
Enter / Space | Toggles focused checkbox. |
Tab / Shift + Tab | Uses native document focus order. |
Visible label is a real <label> associated with control, so pointer and touch activation on label toggles checkbox too.