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,91 @@
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue";
import { useIntersectionObserver } from "@vueuse/core";
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
Spinner,
Button,
} from "@heroui-vue/components";
const items = ref<{ id: string; textValue: string }[]>([]);
const cursor = ref<string | null>("https://pokeapi.co/api/v2/pokemon");
const loading = ref(false),
error = ref(false),
sentinel = ref<HTMLElement>();
let controller: AbortController | undefined;
async function loadMore() {
if (loading.value || !cursor.value) return;
controller = new AbortController();
loading.value = true;
error.value = false;
try {
const response = await fetch(cursor.value, { signal: controller.signal });
if (!response.ok) throw new Error("Unable to load Pokémon");
const page = (await response.json()) as {
next: string | null;
results: { name: string }[];
};
const seen = new Set(items.value.map((item) => item.id));
items.value.push(
...page.results
.filter((item) => !seen.has(item.name))
.map((item) => ({ id: item.name, textValue: item.name })),
);
cursor.value = page.next;
} catch (cause) {
if (!controller.signal.aborted) error.value = true;
} finally {
loading.value = false;
}
}
useIntersectionObserver(sentinel, ([entry]) => {
if (entry?.isIntersecting && !error.value) void loadMore();
});
onMounted(loadMore);
onBeforeUnmount(() => controller?.abort());
</script>
<template>
<Select class="w-[256px]" placeholder="请选择宝可梦" :items="items">
<Label>选择宝可梦</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover class="max-h-80">
<ListBox :items="items" :aria-busy="loading || undefined">
<template #default="{ item }">
<ListBoxItem :id="item.id" :text-value="item.textValue">
{{ item.textValue }}
<ListBoxItemIndicator />
</ListBoxItem>
</template>
<template #empty>
<p class="px-4 py-2 text-sm text-muted">
{{ error ? "加载失败,请重试" : "正在加载…" }}
</p>
</template>
</ListBox>
<div
v-if="cursor"
ref="sentinel"
class="flex items-center justify-center gap-2 py-2"
role="status"
>
<template v-if="loading">
<Spinner size="sm" />
<span class="text-sm text-muted">加载更多…</span>
</template>
<Button v-else variant="ghost" size="sm" @click="loadMore">
{{ error ? "重试" : "加载更多…" }}
</Button>
</div>
</SelectPopover>
</Select>
</template>
@@ -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>
@@ -0,0 +1,57 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
Button,
} from "@heroui-vue/components";
import { ref } from "vue";
const open = ref(false);
</script>
<template>
<div class="space-y-4">
<Select v-model:open="open" class="w-[256px]" placeholder="请选择">
<Label>州</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="特拉华">
特拉华
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="华盛顿">
华盛顿
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
<Button @click="open = !open">{{ open ? "关闭" : "打开" }}选择框</Button>
<p class="text-sm text-muted">选择框{{ open ? "已打开" : "已关闭" }}</p>
</div>
</template>
+75
View File
@@ -0,0 +1,75 @@
<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");
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">
<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>
@@ -0,0 +1,53 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
import { IconSelector } from "@tabler/icons-vue";
</script>
<template>
<Select class="w-[256px]" placeholder="请选择">
<Label>州</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator class="size-3">
<IconSelector />
</SelectIndicator>
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="特拉华">
特拉华
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="华盛顿">
华盛顿
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</template>
+38
View File
@@ -0,0 +1,38 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
const itemClass =
"rounded-lg data-[focused=true]:bg-accent/10 data-[selected=true]:text-foreground";
</script>
<template>
<Select class="w-56" placeholder="选择套餐" variant="secondary">
<Label class="font-medium text-foreground">套餐</Label>
<SelectTrigger class="rounded-xl bg-default">
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover
class="rounded-xl border border-border bg-surface p-1 shadow-lg"
>
<ListBox>
<ListBoxItem :class="itemClass" id="free" text-value="免费">
免费
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem :class="itemClass" id="pro" text-value="专业版">
专业版
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</template>
+107
View File
@@ -0,0 +1,107 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
Description,
} from "@heroui-vue/components";
import { Avatar, AvatarImage, AvatarFallback } from "@heroui-vue/components";
const users = [
{
id: "1",
name: "Bob",
email: "bob@heroui.com",
fallback: "B",
avatarUrl:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg",
},
{
id: "2",
name: "Fred",
email: "fred@heroui.com",
fallback: "F",
avatarUrl:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg",
},
{
id: "3",
name: "Martha",
email: "martha@heroui.com",
fallback: "M",
avatarUrl:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg",
},
{
id: "4",
name: "John",
email: "john@heroui.com",
fallback: "J",
avatarUrl:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/red.jpg",
},
{
id: "5",
name: "Jane",
email: "jane@heroui.com",
fallback: "J",
avatarUrl:
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/orange.jpg",
},
];
</script>
<template>
<Select class="w-[256px]" placeholder="请选择用户">
<Label>用户</Label>
<SelectTrigger>
<SelectValue v-slot="{ defaultChildren, isPlaceholder, selectedItems }">
<template v-if="isPlaceholder || !selectedItems.length">
{{ defaultChildren }}
</template>
<template v-else-if="selectedItems.length > 1">
{{ selectedItems.length }} 位用户已选
</template>
<div v-else class="flex items-center gap-2">
<Avatar class="size-4" size="sm">
<AvatarImage
:src="
users.find((u) => u.id === selectedItems[0]?.key)?.avatarUrl ??
''
"
/>
<AvatarFallback>
{{ users.find((u) => u.id === selectedItems[0]?.key)?.fallback }}
</AvatarFallback>
</Avatar>
<span>{{ defaultChildren }}</span>
</div>
</SelectValue>
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem
v-for="user in users"
:key="user.id"
:id="user.id"
:text-value="user.name"
>
<Avatar size="sm">
<AvatarImage :src="user.avatarUrl" />
<AvatarFallback>{{ user.fallback }}</AvatarFallback>
</Avatar>
<div class="flex flex-col">
<Label>{{ user.name }}</Label>
<Description>{{ user.email }}</Description>
</div>
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</template>
+50
View File
@@ -0,0 +1,50 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
</script>
<template>
<Select class="w-[256px]" placeholder="请选择">
<Label>州</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="特拉华">
特拉华
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="华盛顿">
华盛顿
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</template>
+98
View File
@@ -0,0 +1,98 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
</script>
<template>
<div class="flex flex-col gap-4">
<Select
is-disabled
class="w-[256px]"
default-value="california"
placeholder="请选择"
>
<Label>州</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="特拉华">
特拉华
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="华盛顿">
华盛顿
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
<Select
is-disabled
class="w-[256px]"
:default-value="['argentina', 'japan', 'france']"
placeholder="请选择国家"
selection-mode="multiple"
>
<Label>拟访问国家</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="argentina" text-value="阿根廷">
阿根廷
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="venezuela" text-value="委内瑞拉">
委内瑞拉
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="japan" text-value="日本">
日本
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="france" text-value="法国">
法国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="italy" text-value="意大利">
意大利
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="spain" text-value="西班牙">
西班牙
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</div>
</template>
+40
View File
@@ -0,0 +1,40 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
</script>
<template>
<div class="w-[400px] space-y-4">
<Select full-width placeholder="请选择">
<Label>喜爱的动物</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="cat" text-value="猫">
猫
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="dog" text-value="狗">
狗
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="bird" text-value="鸟">
鸟
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</div>
</template>
@@ -0,0 +1,62 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
</script>
<template>
<Select class="w-[256px]" placeholder="请选择国家" selection-mode="multiple">
<Label>拟访问国家</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox selection-mode="multiple">
<ListBoxItem id="argentina" text-value="阿根廷">
阿根廷
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="venezuela" text-value="委内瑞拉">
委内瑞拉
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="japan" text-value="日本">
日本
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="france" text-value="法国">
法国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="italy" text-value="意大利">
意大利
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="spain" text-value="西班牙">
西班牙
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="thailand" text-value="泰国">
泰国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-zealand" text-value="新西兰">
新西兰
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="iceland" text-value="冰岛">
冰岛
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</template>
+113
View File
@@ -0,0 +1,113 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
Form,
FieldError,
Button,
Surface,
} from "@heroui-vue/components";
import { ref } from "vue";
const submitted = ref(false);
</script>
<template>
<Surface class="w-[320px] rounded-3xl p-6">
<Form class="flex w-full flex-col gap-4" @submit.prevent="submitted = true">
<Select
is-required
class="w-full"
name="state"
placeholder="请选择"
variant="secondary"
>
<Label>州</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="特拉华">
特拉华
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="华盛顿">
华盛顿
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
<FieldError />
</Select>
<Select
is-required
class="w-full"
name="country"
placeholder="请选择国家"
variant="secondary"
>
<Label>国家</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="usa" text-value="美国">
美国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="canada" text-value="加拿大">
加拿大
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="mexico" text-value="墨西哥">
墨西哥
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="uk" text-value="英国">
英国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="france" text-value="法国">
法国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="germany" text-value="德国">
德国
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
<FieldError />
</Select>
<Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-success">
表单提交成功!
</p>
</Form>
</Surface>
</template>
@@ -0,0 +1,50 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
</script>
<template>
<Select class="w-[256px]" placeholder="请选择" as="div" data-custom="foo">
<Label>州</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="特拉华">
特拉华
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="华盛顿">
华盛顿
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</template>
+101
View File
@@ -0,0 +1,101 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
Form,
FieldError,
Button,
} from "@heroui-vue/components";
import { ref } from "vue";
const submitted = ref(false);
</script>
<template>
<Form
class="flex w-[256px] flex-col gap-4"
@submit.prevent="submitted = true"
>
<Select is-required class="w-full" name="state" placeholder="请选择">
<Label>州</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="特拉华">
特拉华
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="华盛顿">
华盛顿
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
<FieldError />
</Select>
<Select is-required class="w-full" name="country" placeholder="请选择国家">
<Label>国家</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="usa" text-value="美国">
美国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="canada" text-value="加拿大">
加拿大
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="mexico" text-value="墨西哥">
墨西哥
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="uk" text-value="英国">
英国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="france" text-value="法国">
法国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="germany" text-value="德国">
德国
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
<FieldError />
</Select>
<Button type="submit">提交</Button>
<p v-if="submitted" role="status" class="text-sm text-success">
表单提交成功!
</p>
</Form>
</template>
+55
View File
@@ -0,0 +1,55 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
</script>
<template>
<div class="flex flex-col gap-4">
<Select class="w-[256px]" placeholder="请选择" variant="primary">
<Label>主要变体</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="option1" text-value="选项 1">
Option 1
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="option2" text-value="选项 2">
Option 2
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
<Select class="w-[256px]" placeholder="请选择" variant="secondary">
<Label>次要变体</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="option1" text-value="选项 1">
Option 1
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="option2" text-value="选项 2">
Option 2
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</div>
</template>
@@ -0,0 +1,52 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectClearButton,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
</script>
<template>
<Select class="w-[256px]" default-value="california" placeholder="Select one">
<Label>State</Label>
<SelectTrigger>
<SelectValue />
<SelectClearButton />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="Florida">
Florida
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="Delaware">
Delaware
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="California">
California
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="Texas">
Texas
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="New York">
New York
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="Washington">
Washington
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</template>
@@ -0,0 +1,52 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
Description,
} from "@heroui-vue/components";
</script>
<template>
<Select class="w-[256px]" placeholder="请选择">
<Label>州</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="florida" text-value="佛罗里达">
佛罗里达
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="delaware" text-value="特拉华">
特拉华
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="california" text-value="加利福尼亚">
加利福尼亚
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="texas" text-value="德克萨斯">
德克萨斯
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="new-york" text-value="纽约">
纽约
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="washington" text-value="华盛顿">
华盛顿
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
<Description>请选择居住州</Description>
</Select>
</template>
@@ -0,0 +1,54 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Label,
} from "@heroui-vue/components";
</script>
<template>
<Select
class="w-[256px]"
:disabled-keys="['cat', 'kangaroo']"
placeholder="请选择动物"
>
<Label>动物</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxItem id="dog" text-value="狗">
狗
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="cat" text-value="猫">
猫
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="bird" text-value="鸟">
鸟
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="kangaroo" text-value="袋鼠">
袋鼠
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="elephant" text-value="大象">
大象
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="tiger" text-value="老虎">
老虎
<ListBoxItemIndicator />
</ListBoxItem>
</ListBox>
</SelectPopover>
</Select>
</template>
+88
View File
@@ -0,0 +1,88 @@
<script setup lang="ts">
import {
Select,
SelectTrigger,
SelectValue,
SelectIndicator,
SelectPopover,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
ListBoxSection,
Label,
Header,
Separator,
} from "@heroui-vue/components";
</script>
<template>
<Select class="w-[256px]" placeholder="请选择国家">
<Label>国家</Label>
<SelectTrigger>
<SelectValue />
<SelectIndicator />
</SelectTrigger>
<SelectPopover>
<ListBox>
<ListBoxSection>
<Header>北美洲</Header>
<ListBoxItem id="usa" text-value="美国">
美国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="canada" text-value="加拿大">
加拿大
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="mexico" text-value="墨西哥">
墨西哥
<ListBoxItemIndicator />
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>欧洲</Header>
<ListBoxItem id="uk" text-value="英国">
英国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="france" text-value="法国">
法国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="germany" text-value="德国">
德国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="spain" text-value="西班牙">
西班牙
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="italy" text-value="意大利">
意大利
<ListBoxItemIndicator />
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>亚洲</Header>
<ListBoxItem id="japan" text-value="日本">
日本
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="china" text-value="中国">
中国
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="india" text-value="印度">
印度
<ListBoxItemIndicator />
</ListBoxItem>
<ListBoxItem id="south-korea" text-value="韩国">
韩国
<ListBoxItemIndicator />
</ListBoxItem>
</ListBoxSection>
</ListBox>
</SelectPopover>
</Select>
</template>