feat: establish shared field and form foundation

This commit is contained in:
maoyingjie
2026-10-21 22:33:19 +08:00
parent 4f43789f60
commit 7f11afeaa6
35 changed files with 1677 additions and 165 deletions
+12 -7
View File
@@ -1,9 +1,10 @@
<script setup lang="ts">
import { inject, useAttrs } from "vue";
import { switchKey } from "../switch/context";
const ctx = inject(switchKey, undefined);
import { fieldContextKey } from "../field/context";
defineOptions({ inheritAttrs: false });
const field = inject(fieldContextKey, undefined);
const attrs = useAttrs();
defineProps<{
const props = defineProps<{
isRequired?: boolean;
isDisabled?: boolean;
isInvalid?: boolean;
@@ -11,12 +12,16 @@ defineProps<{
</script>
<template>
<component
:is="ctx && !attrs.for ? 'span' : 'label'"
:is="field?.kind === 'toggle' && !attrs.for ? 'span' : 'label'"
v-bind="attrs"
:for="
attrs.for ?? (field?.kind === 'text' ? field.controlId.value : undefined)
"
class="hv-label"
:class="{
'hv-label--required': isRequired,
'hv-label--disabled': isDisabled,
'hv-label--invalid': isInvalid,
'hv-label--required': props.isRequired || field?.required.value,
'hv-label--disabled': props.isDisabled || field?.disabled.value,
'hv-label--invalid': props.isInvalid || field?.invalid.value,
}"
data-slot="label"
>