feat: migrate Select with field, collection and SSR contracts

This commit is contained in:
maoyingjie
2026-10-23 22:05:44 +08:00
parent 65db60a7ac
commit 2b569451b6
52 changed files with 4172 additions and 33 deletions
@@ -0,0 +1,80 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
import { ref, computed } from "vue";
import type { SelectModelValue } from "@heroui-vue/components";
const states = [
{ id: "california", name: "加利福尼亚" },
{ id: "texas", name: "德克萨斯" },
{ id: "florida", name: "佛罗里达" },
{ id: "new-york", name: "纽约" },
{ id: "illinois", name: "伊利诺伊" },
{ id: "pennsylvania", name: "宾夕法尼亚" },
];
const state = ref<SelectModelValue>(["california", "texas"]);
const selected = computed(
() =>
states
.filter((s) =>
Array.isArray(state.value)
? state.value.includes(s.id)
: state.value === s.id,
)
.map((s) => s.name)
.join(", ") || "无",
);
</script>
<template>
<div class="space-y-2">
<Select
class="w-[256px]"
placeholder="请选择州"
v-model="state"
selection-mode="multiple"
>
<Label>州(受控多选)</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="illinois" text-value="伊利诺伊">
伊利诺伊
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="pennsylvania" text-value="宾夕法尼亚">
宾夕法尼亚
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
<p class="text-sm text-muted">已选:{{ selected }}</p>
</div>
</template>