面板

一个样式化的面板组件,用于基于 Vue Flow 的画布,用于定位自定义 UI 元素。

Panel 组件为 Vue Flow 画布上的自定义 UI 元素提供了一个定位容器。 它包括现代卡片样式,带有背景模糊和灵活的定位选项。

使用 CLI 安装

AI Elements Vue
shadcn-vue CLI
npx ai-elements-vue@latest add panel

手动安装

将以下代码复制并粘贴到同一文件夹中。

Panel.vue
index.ts
<script setup lang="ts">
import type { PanelPositionType } from '@vue-flow/core'
import type { HTMLAttributes } from 'vue'
import { cn } from '@repo/shadcn-vue/lib/utils'
import { Panel as PanelPrimitive } from '@vue-flow/core'
import { reactiveOmit } from '@vueuse/core'

interface PanelProps {
  class?: HTMLAttributes['class']
  position?: PanelPositionType
}

const props = withDefaults(defineProps<PanelProps>(), {
  position: 'top-right',
})

const delegatedProps = reactiveOmit(props, 'class')
</script>

<template>
  <PanelPrimitive
    data-slot="panel"
    v-bind="delegatedProps"
    :class="cn('m-4 overflow-hidden rounded-md border bg-card p-1', props.class)"
  >
    <slot />
  </PanelPrimitive>
</template>

特性

  • 灵活的定位(左上、右上、左下、右下、顶部居中、底部居中)
  • 圆角药丸设计,带有背景模糊
  • 主题感知的卡片背景
  • Flexbox 布局,便于内容对齐
  • 微妙的投影以增加深度
  • 完整的 TypeScript 支持
  • 与 Vue Flow 的面板系统兼容

Props

<Panel />

classstring
''
应用于面板的额外 CSS 类。
positionPanelPositionType
top-right
面板在画布上的位置。