feat: migrate ListBox with virtual collection and accessible parts

This commit is contained in:
maoyingjie
2026-10-23 15:02:30 +08:00
parent dea5ded716
commit 65db60a7ac
39 changed files with 2694 additions and 12 deletions
@@ -0,0 +1,87 @@
<script setup lang="ts">
import { ref } from "vue";
import { IconPencil, IconSquarePlus, IconTrash } from "@tabler/icons-vue";
import {
Description,
Header,
Kbd,
KbdAbbr,
KbdContent,
Label,
ListBox,
ListBoxItem,
ListBoxSection,
Separator,
Surface,
} from "@heroui-vue/components";
const message = ref("");
const actions = [
{
id: "new-file",
title: "新建文件",
description: "创建新文件",
shortcut: "N",
icon: IconSquarePlus,
},
{
id: "edit-file",
title: "编辑文件",
description: "进行修改",
shortcut: "E",
icon: IconPencil,
},
];
</script>
<template>
<div class="space-y-3">
<Surface class="w-[256px] rounded-3xl shadow-surface">
<ListBox
aria-label="文件操作"
class="w-full p-2"
selection-mode="none"
@action="message = `已选项目:${$event}`"
>
<ListBoxSection>
<Header>操作</Header>
<ListBoxItem
v-for="action in actions"
:key="action.id"
:id="action.id"
:text-value="action.title"
>
<div class="flex h-8 items-start justify-center pt-px">
<component :is="action.icon" class="size-4 shrink-0 text-muted" />
</div>
<div class="flex flex-col">
<Label>{{ action.title }}</Label>
<Description>{{ action.description }}</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdContent>{{ action.shortcut }}</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
<Separator />
<ListBoxSection>
<Header>危险区域</Header>
<ListBoxItem id="delete-file" text-value="删除文件" variant="danger">
<div class="flex h-8 items-start justify-center pt-px">
<IconTrash class="size-4 shrink-0 text-danger" />
</div>
<div class="flex flex-col">
<Label>删除文件</Label>
<Description>移至废纸篓</Description>
</div>
<Kbd class="ms-auto" variant="light">
<KbdAbbr key-value="command" />
<KbdAbbr key-value="shift" />
<KbdContent>D</KbdContent>
</Kbd>
</ListBoxItem>
</ListBoxSection>
</ListBox>
</Surface>
<p v-if="message" role="status" class="text-sm text-muted">{{ message }}</p>
</div>
</template>