GitHub

@@ -1,5 +1,5 @@

11

<script lang="ts">

2-

import type { CheckboxRootProps } from 'reka-ui'

2+

import type { CheckboxRootProps, CheckboxRootEmits } from 'reka-ui'

33

import type { VNode } from 'vue'

44

import type { AppConfig } from '@nuxt/schema'

55

import theme from '#build/ui/checkbox'

@@ -9,7 +9,7 @@ import type { ComponentConfig } from '../types/tv'

991010

type Checkbox = ComponentConfig<typeof theme, AppConfig, 'checkbox'>

111112-

export interface CheckboxProps extends Pick<CheckboxRootProps, 'disabled' | 'required' | 'name' | 'value' | 'id' | 'defaultValue'>, /** @vue-ignore */ Omit<ButtonHTMLAttributes, 'type' | 'disabled' | 'name'> {

12+

export interface CheckboxProps<T = boolean> extends Pick<CheckboxRootProps<T>, 'disabled' | 'required' | 'name' | 'value' | 'id' | 'defaultValue' | 'modelValue' | 'trueValue' | 'falseValue'>, /** @vue-ignore */ Omit<ButtonHTMLAttributes, 'type' | 'disabled' | 'name'> {

1313

/**

1414

* The element or component this component should render as.

1515

* @defaultValue 'div'

@@ -50,7 +50,7 @@ export interface CheckboxProps extends Pick<CheckboxRootProps, 'disabled' | 'req

5050

ui?: Checkbox['slots']

5151

}

525253-

export type CheckboxEmits = {

53+

export interface CheckboxEmits<T = boolean> extends CheckboxRootEmits<T> {

5454

change: [event: Event]

5555

}

5656

@@ -60,9 +60,9 @@ export interface CheckboxSlots {

6060

}

6161

</script>

626263-

<script setup lang="ts">

63+

<script setup lang="ts" generic="T = boolean">

6464

import { computed, useAttrs, useId } from 'vue'

65-

import { Primitive, CheckboxRoot, CheckboxIndicator, Label, useForwardProps } from 'reka-ui'

65+

import { Primitive, CheckboxRoot, CheckboxIndicator, Label, useForwardPropsEmits } from 'reka-ui'

6666

import { reactivePick } from '@vueuse/core'

6767

import { useAppConfig } from '#imports'

6868

import { useComponentUI } from '../composables/useComponentUI'

@@ -72,18 +72,16 @@ import UIcon from './Icon.vue'

72727373

defineOptions({ inheritAttrs: false })

747475-

const props = defineProps<CheckboxProps>()

75+

const props = defineProps<CheckboxProps<T>>()

7676

const slots = defineSlots<CheckboxSlots>()

77-

const emits = defineEmits<CheckboxEmits>()

78-79-

const modelValue = defineModel<boolean | 'indeterminate'>({ default: undefined })

77+

const emits = defineEmits<CheckboxEmits<T>>()

80788179

const appConfig = useAppConfig() as Checkbox['AppConfig']

8280

const uiProp = useComponentUI('checkbox', props)

838184-

const rootProps = useForwardProps(reactivePick(props, 'required', 'value', 'defaultValue'))

82+

const rootProps = useForwardPropsEmits(reactivePick(props, 'required', 'value', 'defaultValue', 'modelValue', 'trueValue', 'falseValue'), emits)

858386-

const { id: _id, emitFormChange, emitFormInput, size, color, name, disabled, ariaAttrs } = useFormField<CheckboxProps>(props)

84+

const { id: _id, emitFormChange, emitFormInput, size, color, name, disabled, ariaAttrs } = useFormField<CheckboxProps<T>>(props)

8785

const id = _id.value ?? useId()

88868987

const attrs = useAttrs()

@@ -118,16 +116,15 @@ function onUpdate(value: any) {

118116

<CheckboxRoot

119117

:id="id"

120118

v-bind="{ ...rootProps, ...forwardedAttrs, ...ariaAttrs }"

121-

v-model="modelValue"

122119

:name="name"

123120

:disabled="disabled"

124121

data-slot="base"

125122

:class="ui.base({ class: uiProp?.base })"

126123

@update:model-value="onUpdate"

127124

>

128-

<template #default="{ modelValue }">

125+

<template #default="{ state }">

129126

<CheckboxIndicator data-slot="indicator" :class="ui.indicator({ class: uiProp?.indicator })">

130-

<UIcon v-if="modelValue === 'indeterminate'" :name="indeterminateIcon || appConfig.ui.icons.minus" data-slot="icon" :class="ui.icon({ class: uiProp?.icon })" />

127+

<UIcon v-if="state === 'indeterminate'" :name="indeterminateIcon || appConfig.ui.icons.minus" data-slot="icon" :class="ui.icon({ class: uiProp?.icon })" />

131128

<UIcon v-else :name="icon || appConfig.ui.icons.check" data-slot="icon" :class="ui.icon({ class: uiProp?.icon })" />

132129

</CheckboxIndicator>

133130

</template>

Read the original on github.com ↗