Preview Rail
在紧凑导航轨道中预览目标,焦点项目附近的刻度随之展开。
适用场景
- 当界面需要以下行为时使用 Preview Rail:在紧凑导航轨道中预览目标,焦点项目附近的刻度随之展开。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/preview-rail.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
packages/vue/src/motion/preview-rail/demo.vue
<script setup lang="ts">
import { PreviewRail } from "@/components/orvui/motion/preview-rail";
const sections = [
["dashboard", "Dashboard", "Return to your workspace overview and recent activity."],
["components", "Components", "Browse motion primitives for Vue."],
["blocks", "Blocks", "Explore composed, product-ready interface blocks."],
["playground", "Playground", "Tune motion values and preview behavior live."],
["docs", "Documentation", "Read installation, usage, and API reference notes."],
["changelog", "Changelog", "Review newly launched components and improvements."],
["source", "Open source", "Explore the component source and implementation notes."],
["patterns", "Patterns", "Combine components in reusable interface patterns."],
["examples", "Examples", "See components composed in practical interface patterns."],
["templates", "Templates", "Start from polished layouts built with orvui components."],
["guides", "Guides", "Learn how to combine motion primitives effectively."],
["community", "Community", "Discover what other builders are creating with orvui."],
["github", "GitHub", "View the source, report issues, and contribute improvements."],
["about", "About", "Learn more about the ideas and people behind orvui."],
].map(([id, label, description]) => ({ id, label, description, href: `#${id}` }));
</script>
<template><div class="flex w-full flex-col gap-8"><PreviewRail v-for="orientation in ['vertical', 'horizontal'] as const" :key="orientation" :items="sections" :orientation="orientation" default-active-id="docs" :class="['mx-auto w-full max-w-2xl', orientation === 'vertical' ? 'h-[360px]' : 'h-[280px]']" /></div></template>
packages/vue/src/motion/preview-rail/src/PreviewRail.vue
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
PreviewRail | v-model:activeIdstring | update:activeId |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
itemsRailItem[]—label?string"Section navigation"orientation?"vertical" | "horizontal""vertical"activeId?string—defaultActiveId?stringprops.items[0]?.idshowPreview?booleantruepreviewSide?"before" | "after""after"highlightActive?booleanfalseitemSize?number24railClassName?string—previewContainerClassName?string—previewClassName?string—事件
update:activeId[id: string]@update:activeIdactiveChange[id: string]@activeChangeitemSelect[item: RailItem]@itemSelect插槽
preview—作用域参数: item
#previewdefault() => VNodeChild#default无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Preview Rail?
- 通过 items、label、orientation、activeId、defaultActiveId、showPreview、previewSide、highlightActive、itemSize、railClassName、previewContainerClassName、previewClassName 配置 Preview Rail;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:activeId、activeChange、itemSelect,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
更新于
来源与许可 ↗MIT · 0.1.1