44 lines
1.1 KiB
Vue
44 lines
1.1 KiB
Vue
<script setup>
|
|||
|
|
import { computed, ref } from 'vue'
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 复选框:原生 input 仅作为无障碍与表单语义载体,视觉完全自绘。
|
||
|
|
*/
|
||
|
|
const props = defineProps({
|
||
|
|
modelValue: { type: Boolean, default: false },
|
||
|
|
value: { type: [String, Number, Boolean], default: true },
|
||
|
|
disabled: Boolean,
|
||
|
|
indeterminate: Boolean,
|
||
|
|
label: { type: String, default: '' }
|
||
|
|
})
|
||
|
|
|
||
|
|
const emit = defineEmits(['update:modelValue', 'change'])
|
||
|
|
const inputRef = ref(null)
|
||
|
|
|
||
|
|
const checked = computed(() => Boolean(props.modelValue))
|
||
|
|
|
||
|
|
function onChange(event) {
|
||
|
|
const next = event.target.checked
|
||
|
|
emit('update:modelValue', next)
|
||
|
|
emit('change', next)
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<template>
|
||
|
|
<label class="qk-checkbox" :class="{ 'is-disabled': disabled }" @click.stop>
|
||
|
|
<input
|
||
|
|
ref="inputRef"
|
||
|
|
class="qk-checkbox__input"
|
||
|
|
type="checkbox"
|
||
|
|
:checked="checked"
|
||
|
|
:disabled="disabled"
|
||
|
|
:indeterminate="indeterminate"
|
||
|
|
@change="onChange"
|
||
|
|
/>
|
||
|
|
<span class="qk-checkbox__box" aria-hidden="true" />
|
||
|
|
<span v-if="label || $slots.default" class="qk-checkbox__text">
|
||
|
|
<slot>{{ label }}</slot>
|
||
|
|
</span>
|
||
|
|
</label>
|
||
|
|
</template>
|