feat: establish shared field and form foundation
This commit is contained in:
@@ -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"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user