Popper借助Popper.js实现,主要作为其他组件的辅助类使用,尽量不要单独使用。由Popper派生的组件主要有下面几个:

  • Tooltip: 用于文字提示
  • Popover: 用于轻量级的Modal
  • Select: 选择器
  • Dropdown: 下拉菜单
  • Menu: 菜单
  • Cascader: 级联选择器
  • DatePicker: 日期选择器
  • TimePicker: 时间选择器

Base

<template>
 <y-popper>
   <template #trigger>
     <y-button>Hover</y-button>
   </template>
   popper content
 </y-popper>
 <y-popper :show-arrow="false">
   <template #trigger>
     <y-button style="margin-left: 12px;">No Arrow</y-button>
   </template>
   popper content
 </y-popper>
</template>

<script>
import { defineComponent } from "vue";

export default defineComponent({
 name: "Base",
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

Theme

<template>
 <y-popper theme="dark">
   <template #trigger>
     <y-button>Dark</y-button>
   </template>
   popper content
 </y-popper>
 <y-popper theme="light">
   <template #trigger>
     <y-button style="margin-left: 12px;">Light</y-button>
   </template>
   popper content
 </y-popper>
</template>

<script>
import { defineComponent } from "vue";

export default defineComponent({
 name: "Theme",
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

Trigger

<template>
 <y-popper trigger="hover">
   <template #trigger>
     <y-button style="margin-left: 12px;">Hover</y-button>
   </template>
   popper content
 </y-popper>
 <y-popper trigger="click">
   <template #trigger>
     <y-button style="margin-left: 12px;">Click</y-button>
   </template>
   popper content
 </y-popper>
 <y-popper trigger="focus">
   <template #trigger>
     <y-button style="margin-left: 12px;">Focus</y-button>
   </template>
   popper content
 </y-popper>
 <y-popper :visible="visible">
   <template #trigger>
     <y-button style="margin-left: 12px;" @click="visible = !visible">Manual</y-button>
   </template>
   popper content
 </y-popper>
</template>

<script>
import { defineComponent, ref } from "vue";

export default defineComponent({
 name: "Trigger",
 setup() {
   const visible = ref(false);

   return {
     visible
   };
 }
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

Placement

<template>
 <y-popper :placement="placement">
   <template #trigger>
     <div class="trigger-box">
       <y-radio-group v-model="placement" type="solid">
         <y-radio
           v-for="p in topPlacements"
           :value="p"
           :key="p">
           {{ p }}
         </y-radio>
       </y-radio-group>
       <div class="flex-box">
         <y-radio-group v-model="placement" type="solid" vertical>
           <y-radio
             v-for="p in leftPlacements"
             :value="p"
             :key="p">
             {{ p }}
           </y-radio>
         </y-radio-group>
         <y-radio-group v-model="placement" type="solid" vertical>
           <y-radio
             v-for="p in rightPlacements"
             :value="p"
             :key="p">
             {{ p }}
           </y-radio>
         </y-radio-group>
       </div>
       <y-radio-group v-model="placement" type="solid">
         <y-radio
           v-for="p in bottomPlacements"
           :value="p"
           :key="p">
           {{ p }}
         </y-radio>
       </y-radio-group>
     </div>
   </template>
   popper content
 </y-popper>
</template>

<script>
import { defineComponent, ref } from "vue";

export default defineComponent({
 name: "Placement",
 setup() {
   const topPlacements = ['top-start', 'top', 'top-end'];
   const rightPlacements = ['right-start', 'right', 'right-end'];
   const bottomPlacements = ['bottom-start', 'bottom', 'bottom-end'];
   const leftPlacements = ['left-start', 'left', 'left-end'];
   const placement = ref('bottom')

   return {
     placement,
     topPlacements,
     rightPlacements,
     bottomPlacements,
     leftPlacements,
   };
 }
});
</script>

<style lang="scss" scoped>
.trigger-box {
 text-align: center;
 width: 320px;
}
.flex-box {
 width: 100%;
 margin: 16px 0px;
 display: flex;
 justify-content: space-between;
}
</style>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

Disabled

<template>
 <y-checkbox v-model="disabled">Disabled</y-checkbox>
 <y-popper :disabled="disabled">
   <template #trigger>
     <y-button>Hover</y-button>
   </template>
   popper content
 </y-popper>
</template>

<script>
import { defineComponent, ref } from "vue";

export default defineComponent({
 name: "Disabled",
 setup() {
   const disabled = ref(false);

   return {
     disabled
   };
 }
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

API

Popper props

PropertyDescriptionTypeAccepted ValuesDefault
visiblethe visible of popover, will override trigger and turn on manual modeBoolean-undefined
disabledwhether disabled the popover, when disabled the popover will not be shownBoolean-false
placementthe placement of popoverStringtop/top-start/top-end/right/right-start/right-end/bottom/bottom-start/bottom-end/left/left-start/left-endbottom
triggerhow to trigger the popoverStringhover/click/focushover
contentthe content of popoverString--
themethe theme of popoverStringdark/lightdark
hide-hover-popperwhether to hide popper when hover itBoolean-false
hide-on-clickwhether to hide popper when click, only effective when the trigger is clickBoolean-true
show-arrowwhether the popover is with arrowBoolean-true
popper-optionscustom options of popperObject--
popper-classcustom class of popperString--
popper-stylecustom style object of popperObject--
popper-stylecustom style object of popperObject--
classcustom class of triggerObject--
stylecustom style object of triggerObject--
append-to-bodywhether append popper to bodyBoolean-true
auto-closeauto close popper, 0 means do not use auto closeNumber-0
transitionpopper transition nameString-yoga-fade-in-linear

Events

EventDescriptionParameters
after-entertrigger after mouse enter popover-
after-leavetrigger after mouse leave popover-
before-entertrigger before mouse enter popover-
before-leavetrigger before mouse leave popover-

Slots

NameDescriptionParameters
defaultpopper display element-
triggerpopper trigger element-