Center Morph Modal
围绕中心向各方向展开模态框,关闭时回到同一点。
适用场景
- 当界面需要以下行为时使用 Center Morph Modal:围绕中心向各方向展开模态框,关闭时回到同一点。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/center-morph-modal.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
packages/vue/src/motion/center-morph-modal/demo.vue
<script setup lang="ts">
import { useId } from "vue";
import { ArrowUpRight, Check } from "lucide-vue-next";
import { CenterMorphModal, CenterMorphModalClose, CenterMorphModalContent, CenterMorphModalTrigger } from "@/components/orvui/motion/center-morph-modal";
const descriptionId = `${useId()}-description`;
const features = ["Animated Vue components", "Composition API and TypeScript", "Editable source and registry"];
</script>
<template><div class="flex min-h-[420px] w-full items-center justify-center"><CenterMorphModal>
<CenterMorphModalTrigger><button type="button" class="inline-flex h-10 items-center justify-center rounded-full bg-foreground px-5 text-sm font-medium text-background press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background">Open modal</button></CenterMorphModalTrigger>
<CenterMorphModalContent ariaLabel="orvui" :ariaDescribedBy="descriptionId"><div class="p-7 sm:p-8"><p class="text-sm font-medium text-muted-foreground">orvui</p>
<h2 class="mt-5 max-w-xs pr-8 text-2xl font-medium tracking-tight text-foreground">Ship the whole experience.</h2>
<p :id="descriptionId" class="mt-3 text-sm leading-relaxed text-muted-foreground">Create distinctive Vue interfaces with accessible controls and thoughtful movement throughout.</p>
<div class="mt-7 space-y-3 border-y border-border py-5"><div v-for="feature in features" :key="feature" class="flex items-center gap-3 text-sm text-foreground"><Check class="h-4 w-4 text-muted-foreground" aria-hidden="true" /><span>{{ feature }}</span></div></div>
<CenterMorphModalClose><button class="mt-7 inline-flex h-11 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-sm font-medium text-background press focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">Start creating<ArrowUpRight class="h-4 w-4" aria-hidden="true" /></button></CenterMorphModalClose>
</div></CenterMorphModalContent>
</CenterMorphModal></div></template>
packages/vue/src/motion/center-morph-modal/src/CenterMorphModal.vue
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
CenterMorphModal | v-model:openboolean | update:open |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
CenterMorphModal
open?booleanundefineddefaultOpen?booleanfalse事件
update:open—@update:open插槽
default—作用域参数: open
#defaultCenterMorphModalContent
ariaLabelstring—ariaDescribedBy?string—dismissible?booleantrueshowCloseButton?booleantruecloseButtonLabel?string"Close modal"backdropClassName?string—插槽
default() => VNodeChild#default无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Center Morph Modal?
- 通过 open、defaultOpen 配置 Center Morph Modal;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:open,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
更新于
来源与许可 ↗MIT · 0.1.1