feat: establish composed color field and input group protocols

This commit is contained in:
maoyingjie
2026-10-25 15:20:02 +08:00
parent a41517aa76
commit db18d0d3da
31 changed files with 1859 additions and 39 deletions
@@ -0,0 +1,153 @@
<script setup lang="ts">
import { shallowRef } from "vue";
import ColorField from "../../../packages/vue/src/components/color-field/ColorField.vue";
import ColorInputGroup from "../../../packages/vue/src/components/color-field/ColorInputGroup.vue";
import ColorInputGroupInput from "../../../packages/vue/src/components/color-field/ColorInputGroupInput.vue";
import Prefix from "../../../packages/vue/src/components/color-field/ColorInputGroupPrefix.vue";
import Suffix from "../../../packages/vue/src/components/color-field/ColorInputGroupSuffix.vue";
import Picker from "../../../packages/vue/tests/fixtures/ColorPickerComposition.vue";
import { parseColor } from "../../../packages/vue/src/components/color/value";
import { Label, Description, FieldError, Button } from "@heroui-vue/components";
const value = shallowRef(parseColor("#123456")),
submitted = shallowRef("尚未提交"),
channelSubmitted = shallowRef("尚未提交");
function submit(event: Event, channel = false) {
const json = JSON.stringify([
...new FormData(event.target as HTMLFormElement),
]);
if (channel) channelSubmitted.value = json;
else submitted.value = json;
}
</script>
<template>
<main class="color-field-lab">
<h1>颜色字段正式协议 · 内部验收</h1>
<p>
组合部件、原生关联、格式化通道、提交和共享颜色;公开导出与正式文档尚未接入。
</p>
<div class="color-field-grid">
<section id="field-native">
<h2>受控 Hex / 原生 Enter</h2>
<form @submit.prevent="submit($event)">
<ColorField v-model="value" name="hex" is-required>
<Label>品牌颜色</Label>
<ColorInputGroup>
<Prefix>#</Prefix>
<ColorInputGroupInput id="brand-color" />
<Suffix>
<Button variant="ghost" size="sm" type="button">帮助</Button>
</Suffix>
</ColorInputGroup>
<Description>Enter 提交已接受的颜色。</Description>
<FieldError />
</ColorField>
<div class="field-actions">
<Button type="submit">提交</Button>
<Button variant="secondary" type="reset">重置</Button>
</div>
<output>{{ submitted }}</output>
<output>接受值:{{ value?.toString("hex") ?? "empty" }}</output>
</form>
</section>
<section id="field-channel">
<h2>百分数显示 / 小数提交</h2>
<form @submit.prevent="submit($event, true)">
<ColorField
channel="saturation"
color-space="hsb"
default-value="hsb(270,50%,50%)"
name="saturation"
locale="de-DE"
>
<Label>饱和度</Label>
<ColorInputGroup><ColorInputGroupInput /></ColorInputGroup>
<Description>50% 提交为 0.5;聚焦后可滚轮增减。</Description>
<FieldError />
</ColorField>
<Button type="submit">提交通道</Button>
<output>{{ channelSubmitted }}</output>
</form>
</section>
<section id="field-required">
<h2>空值 / 必填 / 错误关联</h2>
<form @submit.prevent>
<ColorField name="required" is-required>
<Label>必填颜色</Label>
<ColorInputGroup><ColorInputGroupInput /></ColorInputGroup>
<Description>支持浅色和深色主题。</Description>
<FieldError />
</ColorField>
<div class="field-actions">
<Button type="submit">校验</Button>
<Button variant="secondary" type="reset">重置</Button>
</div>
</form>
</section>
<section id="field-standalone">
<h2>独立输入组</h2>
<ColorInputGroup>
<Prefix>Text</Prefix>
<ColorInputGroupInput
aria-label="Standalone text"
default-value="plain text"
/>
<Suffix>suffix</Suffix>
</ColorInputGroup>
</section>
<section id="field-picker">
<h2>正式字段接入 Picker</h2>
<form>
<Picker name="color" />
<Button variant="secondary" type="reset">重置 Picker</Button>
</form>
</section>
</div>
</main>
</template>
<style>
.color-field-lab {
padding: 32px;
min-height: 100vh;
background: var(--background);
color: var(--foreground);
font-family: Inter, sans-serif;
}
.color-field-lab h1 {
font-size: 24px;
font-weight: 600;
margin-bottom: 8px;
}
.color-field-lab > p {
color: var(--muted);
margin-bottom: 24px;
}
.color-field-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 24px;
}
.color-field-grid section {
padding: 24px;
border: 1px solid var(--border);
border-radius: 20px;
}
.color-field-grid h2 {
font-size: 16px;
font-weight: 600;
margin-bottom: 20px;
}
.color-field-grid form {
display: flex;
flex-direction: column;
gap: 16px;
}
.color-field-grid output {
display: block;
overflow-wrap: anywhere;
font-size: 14px;
}
.field-actions {
display: flex;
gap: 12px;
}
</style>