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
@@ -1,17 +1,12 @@
<script setup lang="ts">
import { inject, onBeforeUnmount, useId, useAttrs } from "vue";
import { switchKey } from "../switch/context";
const ctx = inject(switchKey, undefined);
import { useAttrs } from "vue";
import { useFieldPart } from "../field/useFieldPart";
defineOptions({ inheritAttrs: false });
const attrs = useAttrs();
const id = String(attrs.id ?? useId());
if (ctx) ctx.descriptionIds.value = [...ctx.descriptionIds.value, id];
onBeforeUnmount(() => {
if (ctx)
ctx.descriptionIds.value = ctx.descriptionIds.value.filter(
(value) => value !== id,
);
});
const { id } = useFieldPart("description", attrs);
</script>
<template>
<p :id="id" class="hv-description" data-slot="description"><slot /></p>
<p v-bind="attrs" :id="id" class="hv-description" data-slot="description">
<slot />
</p>
</template>