refactor: CheckboxItem typing

This commit is contained in:
axolotle 2024-07-05 17:03:55 +02:00
parent 0414f82d53
commit 5cd0ed23a5
2 changed files with 26 additions and 11 deletions

View file

@ -1,31 +1,39 @@
<script setup lang="ts">
import type { CheckboxItemProps, BaseItemComputedProps } from '@/types/form'
withDefaults(
defineProps<{
modelValue: boolean
id?: string
label?: string
labels?: { true: string; false: string }
}>(),
defineProps<CheckboxItemProps & BaseItemComputedProps<boolean>>(),
{
id: undefined,
name: undefined,
placeholder: undefined,
touchKey: undefined,
label: undefined,
labels: () => ({ true: 'yes', false: 'no' }),
ariaDescribedby: undefined,
modelValue: undefined,
state: undefined,
validation: undefined,
},
)
const emit = defineEmits<{
defineEmits<{
'update:modelValue': [value: boolean]
}>()
const model = defineModel<boolean>()
</script>
<template>
<BFormCheckbox
:modelValue="modelValue"
@update:modelValue="emit('update:modelValue', $event)"
:id="id"
:aria-describedby="$parent.id + '__BV_description_'"
v-model="model"
:name="name"
:aria-describedby="ariaDescribedby"
:state="state"
switch
>
{{ label || $t(labels[modelValue]) }}
{{ label || $t(labels[modelValue ? 'true' : 'false']) }}
</BFormCheckbox>
</template>

View file

@ -26,3 +26,10 @@ export type AdressModelValue = {
separator: string
domain: string | null
}
export type CheckboxItemProps = BaseWritableItemProps & {
label?: string
labels?: { true: string; false: string }
// FIXME unused?
// choices: string[]
}