Expandable Action Bar
在紧凑图标操作行中,为当前活动操作展开标签。
适用场景
- 当界面需要以下行为时使用 Expandable Action Bar:在紧凑图标操作行中,为当前活动操作展开标签。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/expandable-action-bar.json
此示例还需要:
终端
pnpm add lucide-vue-next@^0.468.0首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
packages/vue/src/blocks/expandable-action-bar/demo.vue
<script setup lang="ts">
import { h, computed, ref } from "vue";
import { motion, AnimatePresence } from "motion-v";
import { Archive, Bell, Copy, Download, Send, Settings } from "lucide-vue-next";
import { ExpandableActionBar, type ExpandableActionBarItem } from "@/components/orvui/blocks/expandable-action-bar";
const expanded = ref(false),
activeId = ref("send");
const descriptors = [
{
id: "send",
label: "Send",
icon: Send,
shortcut: "S",
motion: "motion-safe:group-hover:animate-action-send",
},
{
id: "copy",
label: "Copy",
icon: Copy,
shortcut: "C",
motion: "motion-safe:group-hover:animate-action-copy",
},
{
id: "download",
label: "Export",
icon: Download,
shortcut: "E",
motion: "motion-safe:group-hover:animate-action-download",
},
{
id: "archive",
label: "Archive",
icon: Archive,
motion: "motion-safe:group-hover:animate-action-archive",
},
{
id: "alerts",
label: "Alerts",
icon: Bell,
badge: "3",
motion: "origin-top motion-safe:group-hover:animate-action-bell",
},
{
id: "settings",
label: "Settings",
icon: Settings,
motion: "motion-safe:group-hover:animate-action-settings",
},
];
const items = computed<ExpandableActionBarItem[]>(() =>
descriptors.map(({ icon, motion: animation, ...item }) => ({
...item,
active: item.id === activeId.value,
icon: () => h(icon, { class: `h-4 w-4 ${animation}` }),
})),
);
</script>
<template>
<div class="flex min-h-72 w-full flex-col items-center justify-center gap-6">
<div class="flex min-h-24 w-full items-center justify-center">
<ExpandableActionBar
:items="items"
v-model:expanded="expanded"
:active-id="activeId"
@action="activeId = $event.id"
:class-names="{ item: 'group' }"
/>
</div>
<div class="flex flex-wrap items-center justify-center gap-2">
<motion.button
type="button"
@click="expanded = !expanded"
class="relative flex h-9 w-[110px] items-center justify-center overflow-hidden rounded-full border border-border bg-card text-xs font-medium text-foreground transition-colors hover:border-(--color-border-strong)"
:while-hover="{ scale: 1.02 }"
:while-press="{ scale: 0.96 }"
><motion.div layout class="flex items-center gap-1.5"
><motion.svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
:stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="h-3.5 w-3.5 shrink-0"
><motion.path
:initial="false"
:animate="{
d: expanded ? 'M 10 20 L 10 14 L 4 14' : 'M 9 21 L 3 21 L 3 15',
}"
:transition="{
type: 'spring',
bounce: 0,
duration: 0.3,
}" /><motion.path
:initial="false"
:animate="{
d: expanded ? 'M 14 4 L 14 10 L 20 10' : 'M 15 3 L 21 3 L 21 9',
}"
:transition="{ type: 'spring', bounce: 0, duration: 0.3 }" /><line
x1="14"
x2="21"
y1="10"
y2="3" /><line x1="3" x2="10" y1="21" y2="14" /></motion.svg
><AnimatePresence mode="popLayout" :initial="false"
><motion.span
:key="expanded ? 'expanded' : 'collapsed'"
:initial="{ opacity: 0, y: -25, filter: 'blur(4px)' }"
:animate="{ opacity: 1, y: 0, filter: 'blur(0px)' }"
:exit="{ opacity: 0, y: 25, filter: 'blur(4px)' }"
:transition="{ type: 'spring', bounce: 0, duration: 0.3 }"
>{{ expanded ? "Collapse" : "Expand" }}</motion.span
></AnimatePresence
></motion.div
></motion.button
>
</div>
</div>
</template>
packages/vue/src/blocks/expandable-action-bar/src/ExpandableActionBar.vue
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
ExpandableActionBar | v-model:expandedboolean | update:expanded |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
itemsExpandableActionBarItem[]—expanded?booleanundefineddefaultExpanded?booleanfalseactiveId?string—size?"sm" | "md""md"expandOnHover?booleantrueexpandOnFocus?booleantruecollapseDelay?number90classNames?ExpandableActionBarClassNames—事件
update:expanded[value: boolean]@update:expandedexpandedChange[value: boolean]@expandedChangeaction[item: ExpandableActionBarItem]@action插槽
item—作用域参数: item, expanded, active
#item无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Expandable Action Bar?
- 通过 items、expanded、defaultExpanded、activeId、size、expandOnHover、expandOnFocus、collapseDelay、classNames 配置 Expandable Action Bar;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:expanded、expandedChange、action,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
请留意
部分组件参考了开源作品,相关署名与独立许可请参阅 NOTICE。
更新于
来源与许可 ↗MIT · 0.1.1