Expandable Tabs
在图标条中导航,选中项展开以显示标签。
适用场景
- 当界面需要以下行为时使用 Expandable Tabs:在图标条中导航,选中项展开以显示标签。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/expandable-tabs.json
此示例还需要:
终端
pnpm add lucide-vue-next@^0.468.0首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
packages/vue/src/blocks/expandable-tabs/demo.vue
<script setup lang="ts">
import { h, type Component } from "vue";
import {
BadgeCheck,
Brush,
CalendarClock,
ChartSpline,
ChevronRight,
ClipboardCheck,
CloudUpload,
FileText,
Gauge,
GitBranch,
Images,
Inbox,
Megaphone,
MessageCircle,
PackageOpen,
RefreshCw,
Rocket,
Siren,
SwatchBook,
UploadCloud,
Users,
Webhook,
Workflow,
} from "lucide-vue-next";
import { ExpandableTabs, type ExpandableTabsItem } from "@/components/orvui/blocks/expandable-tabs";
type MenuRow = readonly [Component, string];
function content(rows: readonly MenuRow[]) {
return () =>
h(
"div",
{ class: "flex w-[17.125rem] flex-col gap-0.5" },
rows.map(([icon, label]) =>
h(
"button",
{
key: label,
type: "button",
class:
"flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-left text-sm font-medium text-foreground transition-colors hover:bg-muted",
},
[
h(icon, { class: "h-4 w-4 text-muted-foreground" }),
h("span", { class: "flex-1" }, label),
h(ChevronRight, { class: "h-4 w-4 text-muted-foreground" }),
],
),
),
);
}
const sections: readonly {
id: string;
label: string;
icon: Component;
rows: readonly MenuRow[];
}[] = [
{
id: "launch",
label: "Launch",
icon: Rocket,
rows: [
[FileText, "Release Brief"],
[ClipboardCheck, "Launch Checklist"],
[Megaphone, "Campaign Notes"],
[CalendarClock, "Rollout Calendar"],
[CloudUpload, "Ship Build"],
],
},
{
id: "inbox",
label: "Inbox",
icon: Inbox,
rows: [
[MessageCircle, "Client Feedback"],
[Users, "Team Requests"],
[BadgeCheck, "Approval Notes"],
],
},
{
id: "flows",
label: "Flows",
icon: Workflow,
rows: [
[GitBranch, "Trigger Map"],
[Webhook, "Webhook Runs"],
[RefreshCw, "Retry Queue"],
],
},
{
id: "assets",
label: "Assets",
icon: PackageOpen,
rows: [
[SwatchBook, "Brand Kit"],
[Images, "Mockup Library"],
[Brush, "Design Tokens"],
[UploadCloud, "Export Queue"],
],
},
{
id: "status",
label: "Status",
icon: ChartSpline,
rows: [
[Gauge, "Activation"],
[ChartSpline, "Conversion"],
[Siren, "Incidents"],
],
},
];
const items: ExpandableTabsItem[] = sections.map(({ rows, ...section }) => ({
...section,
content: content(rows),
}));
</script>
<template>
<div class="flex min-h-88 w-full items-end justify-center">
<ExpandableTabs :items="items" />
</div>
</template>
packages/vue/src/blocks/expandable-tabs/src/ExpandableTabs.vue
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
ExpandableTabs | v-modelnull | string | update:modelValue |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
itemsExpandableTabsItem[]—modelValue?null | string—defaultValue?null | stringnullclassNames?ExpandableTabsClassNames—事件
update:modelValue[value: string | null]@update:modelValuevalueChange[value: string | null]@valueChange插槽
content—作用域参数: item, item
#content无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Expandable Tabs?
- 通过 items、modelValue、defaultValue、classNames 配置 Expandable Tabs;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:modelValue、valueChange,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
请留意
部分组件参考了开源作品,相关署名与独立许可请参阅 NOTICE。
更新于
来源与许可 ↗MIT · 0.1.1