Morphing Tabs
在连续布局过渡中切换标签页并调整其排列顺序。
适用场景
- 当界面需要以下行为时使用 Morphing Tabs:在连续布局过渡中切换标签页并调整其排列顺序。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/morphing-tabs.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
quiet focus
Room 2
A small space for the work that needs a little more air around it.
drag any room to reorder
packages/vue/src/blocks/morphing-tabs/demo.vue
<script setup lang="ts">
import { ref, shallowRef } from "vue";
import { MorphingTabs, type MorphingTabsItem } from "@/components/orvui/blocks/morphing-tabs";
const rooms: Record<
string,
{ eyebrow: string; title: string; detail: string; accent: string }
> = {
"room-2": {
eyebrow: "quiet focus",
title: "Room 2",
detail:
"A small space for the work that needs a little more air around it.",
accent: "#db5b2f",
},
general: {
eyebrow: "shared space",
title: "General",
detail:
"The common room for notes, links and the ideas that are still finding their shape.",
accent: "#1bb273",
},
archive: {
eyebrow: "kept close",
title: "Archive",
detail:
"Past rooms stay available without competing with the conversations in motion.",
accent: "#7a6de2",
},
};
const items = shallowRef<MorphingTabsItem[]>(
Object.keys(rooms).map((id) => ({
id,
label: rooms[id].title,
content: "",
})),
),
value = ref<string | null>("room-2");
function order(ids: string[]) {
items.value = ids.flatMap((id) => {
const item = items.value.find((entry) => entry.id === id);
return item ? [item] : [];
});
}
function close(id: string) {
items.value = items.value.filter((item) => item.id !== id);
if (value.value === id) value.value = items.value[0]?.id ?? null;
}
</script>
<template>
<div
class="flex w-full min-w-0 items-center justify-center bg-[#242424] p-3 md:p-8"
>
<MorphingTabs
v-model="value"
:items="items"
aria-label="Rooms"
class="w-full max-w-5xl"
@order-change="order"
@close="close"
><template #content="{ item }"
><div
class="relative min-h-64 overflow-hidden bg-[radial-gradient(circle_at_1px_1px,#dfe2e3_1px,transparent_1.5px)] bg-[size:4.8rem_4.8rem] px-7 py-8 md:px-12 md:py-10"
>
<div class="relative max-w-xl">
<p
class="text-[.68rem] font-semibold uppercase tracking-[.24em] text-black/40"
>
{{ rooms[item.id].eyebrow }}
</p>
<h3
class="mt-3 text-3xl font-light tracking-[-.055em] text-[#151515] md:text-5xl"
>
{{ rooms[item.id].title }}
</h3>
<p
class="mt-4 max-w-md text-sm leading-6 text-black/55 md:text-base"
>
{{ rooms[item.id].detail }}
</p>
<div
class="mt-8 flex items-center gap-3 text-xs font-medium text-black/50"
>
<span
class="size-2 rounded-full"
:style="{ backgroundColor: rooms[item.id].accent }"
/>drag any room to reorder
</div>
</div>
</div></template
></MorphingTabs
>
</div>
</template>
packages/vue/src/blocks/morphing-tabs/src/MorphingTabs.vue
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
MorphingTabs | v-modelnull | string | update:modelValue |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
itemsMorphingTabsItem[]—modelValue?null | string—defaultValue?null | stringprops.items[0]?.idariaLabel?string"Tabs"closable?booleanfalseclassNames?MorphingTabsClassNames—事件
update:modelValue[id: string | null]@update:modelValuevalueChange[id: string | null]@valueChangeorderChange[ids: string[]]@orderChangeclose[id: string]@close插槽
content—作用域参数: item
#content无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Morphing Tabs?
- 通过 items、modelValue、defaultValue、ariaLabel、closable、classNames 配置 Morphing Tabs;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:modelValue、valueChange、orderChange、close,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
请留意
部分组件参考了开源作品,相关署名与独立许可请参阅 NOTICE。
更新于
来源与许可 ↗MIT · 0.1.1