Skip to content

BubbleBox 气泡框

介绍

气泡框组件,用于在页面上显示一个可交互的气泡框,支持点击触发弹出气泡式的卡片浮层。

导入

js
import BubbleBox from '@/components/feedback/BubbleBox.vue'

用法

基本用法

气泡框支持上、下、左、右四个方向的显示位置。

vue
<template>
  <FlexCol align="center" :gap="20">
    <BubbleBox :items="items">
      <Button>上方显示</Button>
    </BubbleBox>
    <FlexRow justify="space-between" :gap="20">
      <BubbleBox :items="items" position="left">
        <Button>左侧显示</Button>
      </BubbleBox>
      <BubbleBox :items="items" position="right">
        <Button>右侧显示</Button>
      </BubbleBox>
    </FlexRow>
    <BubbleBox :items="items" position="bottom">
      <Button>下方显示</Button>
    </BubbleBox>
  </FlexCol>
</template>

<script setup lang="ts">
import Button from '@/components/basic/Button.vue';
import FlexCol from '@/components/layout/FlexCol.vue';
import FlexRow from '@/components/layout/FlexRow.vue';
import { toast } from '@/components/dialog/CommonRoot';

const items = [
  {
    icon: 'edit-filling',
    text: '编辑',
    onClick: () => {
      toast('点击了编辑');
    },
  },
  {
    icon: 'browse',
    text: '查看',
    onClick: () => {
      toast('点击了查看');
    },
  },
]
</script>

自定义内容

通过 content 插槽可以自定义气泡框的内容,替代默认的按钮列表。

vue
<template>
  <BubbleBox>
    <Button>点击显示自定义内容</Button>
    <template #content>
      <FlexCol :padding="[5, 10]" :gap="5">
        <Text bold>自定义标题</Text>
        <Text color="text.secondary" :size="24">这是通过 content 插槽自定义的气泡框内容,可以放置任意内容。</Text>
      </FlexCol>
    </template>
  </BubbleBox>
</template>

<script setup lang="ts">
import Button from '@/components/basic/Button.vue';
import Text from '@/components/basic/Text.vue';
import FlexCol from '@/components/layout/FlexCol.vue';
</script>

API 参考

BubbleBox

气泡框组件,用于在页面上显示一个可交互的气泡框。

Props

名称说明类型必填默认值
position气泡框位置'left' | 'right' | 'top' | 'bottom'-'top'
crossPosition气泡在横轴上的对齐位置'left' | 'center' | 'right'-'center'
trigger触发点击事件模式'click' | 'hover' | 'none'-'click'
direction气泡框按钮排列方向'column' | 'row'-'column'
disabled是否禁用boolean-false
items气泡框按钮数组BubbleBoxItem[]-[]
itemTextColor气泡框按钮文本颜色string-'text.content'
itemTextProps气泡框按钮文本样式TextProps--
itemIconProps气泡框按钮图标样式IconProps--
itemProps气泡框按钮样式FlexProps--
outerStyle气泡框外层容器样式Record<string, string>--
backgroundColor气泡框背景颜色string-'white'
arrowWidth气泡框箭头宽度number-12
radius气泡框圆角半径number-12
innerProps气泡框内层容器样式FlexProps--
innerStyle气泡框内层容器样式Record<string, string>--

BubbleBoxItem

气泡框按钮项的类型定义:

名称说明类型必填默认值
text按钮文本string-
textColor按钮文本颜色string--
icon按钮图标string--
iconProps按钮图标样式IconProps--
onClick点击事件回调() => void-

Slots

名称说明
default气泡框的触发元素
content自定义气泡框内容,替代默认的按钮列表

Methods

名称说明参数
show显示气泡框-
hide隐藏气泡框-

主题变量

名称类型默认值说明
BubbleBoxArrowWidthnumber12气泡框箭头宽度
BubbleBoxItemTextColorstring'text.content'气泡框按钮文本颜色
BubbleBoxBackgroundColorstring'white'气泡框背景颜色
BubbleBoxRadiusnumber12气泡框圆角半径