组件
列表 List
List:列表。Root 是列表容器,Item 是一行,Leading 放文字前的标识,Content 放标题和辅助说明,Actions 放操作。bordered 变体绘制发丝线;hoverable 变体让每一行都有悬停底色;调用方把某行设为可点击(`role="button"`)后,该行自行响应指针。
#基础用法
- SWSeal registryWho pressed which seal, and when.
- LWLetter roomCorrespondence awaiting the registrar.
- ABArchive annexShelved records, fourth row, eastern cabinet.
<script setup lang="ts">
import { Avatar, Button, List } from "@bysages/vue";
const rows = [
{
initials: "SW",
title: "Seal registry",
description: "Who pressed which seal, and when.",
},
{
initials: "LW",
title: "Letter room",
description: "Correspondence awaiting the registrar.",
},
{
initials: "AB",
title: "Archive annex",
description: "Shelved records, fourth row, eastern cabinet.",
},
];
</script>
<template>
<List.Root class="w-full">
<List.Item v-for="row in rows" :key="row.title">
<List.Leading>
<Avatar.Root>
<Avatar.Fallback>{{ row.initials }}</Avatar.Fallback>
</Avatar.Root>
</List.Leading>
<List.Content>
<template #title>{{ row.title }}</template>
<template #description>{{ row.description }}</template>
</List.Content>
<List.Actions>
<Button variant="ghost" size="sm">Open</Button>
</List.Actions>
</List.Item>
</List.Root>
</template>
- Morning readingsBarometer steady, ink flows well.
- Noon deliveriesTwo crates of paper from the mill.
- Evening closingsThe lamps are trimmed at dusk.
Nothing opened yet.
<script setup lang="ts">
import { List } from "@bysages/vue";
import { ref } from "vue";
const opened = ref("");
const ledger = [
{ title: "Morning readings", description: "Barometer steady, ink flows well." },
{ title: "Noon deliveries", description: "Two crates of paper from the mill." },
{ title: "Evening closings", description: "The lamps are trimmed at dusk." },
];
const open = (title: string) => {
opened.value = title;
};
</script>
<template>
<div class="w-full">
<List.Root bordered hoverable class="w-full">
<List.Item
v-for="row in ledger"
:key="row.title"
role="button"
tabindex="0"
@click="open(row.title)"
@keydown.enter.prevent="open(row.title)"
@keydown.space.prevent="open(row.title)"
>
<List.Content>
<template #title>{{ row.title }}</template>
<template #description>{{ row.description }}</template>
</List.Content>
</List.Item>
</List.Root>
<p role="status" class="mt-4 text-sm text-tertiary">
{{ opened ? `Opened “${opened}”.` : "Nothing opened yet." }}
</p>
</div>
</template>
#属性
#ListRoot
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
bordered | Boolean | false | 是否在行间显示发丝线 |
hoverable | Boolean | false | 行悬停时是否显示浅色背景 |
#ListItem
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#ListLeading
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#ListActions
纯造型的部件——自身没有属性,沿用部件结构的共享样式。
#ListContent
列表行的文字区域。标题和描述分别使用具名插槽,默认插槽排在后面,用于放其他内容。
纯造型的部件——自身没有属性,沿用部件结构的共享样式。