Files
heroui-vue/apps/docs/demos/list-box-controlled.vue

68 lines
1.8 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import {
Avatar,
AvatarImage,
AvatarFallback,
Description,
Label,
ListBox,
ListBoxItem,
ListBoxItemIndicator,
Surface,
} from "@heroui-vue/components";
import { IconCheck } from "@tabler/icons-vue";
import { ref } from "vue";
import type { ListBoxKey } from "@heroui-vue/components";
const selected = ref<ListBoxKey[]>(["1"]);
const users = [
{
id: "1",
name: "Bob",
email: "bob@heroui.com",
src: "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/blue.jpg",
},
{
id: "2",
name: "Fred",
email: "fred@heroui.com",
src: "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/green.jpg",
},
{
id: "3",
name: "Martha",
email: "martha@heroui.com",
src: "https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/avatars/purple.jpg",
},
];
</script>
<template>
<div class="space-y-4">
<Surface class="w-[256px] rounded-3xl shadow-surface">
<ListBox
:items="users"
v-slot="{ item: user }"
aria-label="用户"
selection-mode="multiple"
v-model="selected"
>
<ListBoxItem :id="user.id" :text-value="user.name">
<Avatar size="sm">
<AvatarImage :alt="user.name" :src="user.src" />
<AvatarFallback>{{ user.name[0] }}</AvatarFallback>
</Avatar>
<div class="flex flex-col">
<Label>{{ user.name }}</Label>
<Description>{{ user.email }}</Description>
</div>
<ListBoxItemIndicator v-slot="{ isSelected }">
<IconCheck v-if="isSelected" class="size-4 text-accent" />
</ListBoxItemIndicator>
</ListBoxItem>
</ListBox>
</Surface>
<p class="text-sm text-muted">
已选:{{ selected.length ? selected.join("、") : "无" }}
</p>
</div>
</template>