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
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
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
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
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
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
Property | Description | Type | Accepted Values | Default |
---|---|---|---|---|
visible | the visible of popover, will override trigger and turn on manual mode | Boolean | - | undefined |
disabled | whether disabled the popover, when disabled the popover will not be shown | Boolean | - | false |
placement | the placement of popover | String | top /top-start /top-end /right /right-start /right-end /bottom /bottom-start /bottom-end /left /left-start /left-end | bottom |
trigger | how to trigger the popover | String | hover /click /focus | hover |
content | the content of popover | String | - | - |
theme | the theme of popover | String | dark /light | dark |
hide-hover-popper | whether to hide popper when hover it | Boolean | - | false |
hide-on-click | whether to hide popper when click, only effective when the trigger is click | Boolean | - | true |
show-arrow | whether the popover is with arrow | Boolean | - | true |
popper-options | custom options of popper | Object | - | - |
popper-class | custom class of popper | String | - | - |
popper-style | custom style object of popper | Object | - | - |
popper-style | custom style object of popper | Object | - | - |
class | custom class of trigger | Object | - | - |
style | custom style object of trigger | Object | - | - |
append-to-body | whether append popper to body | Boolean | - | true |
auto-close | auto close popper, 0 means do not use auto close | Number | - | 0 |
transition | popper transition name | String | - | yoga-fade-in-linear |
Events
Event | Description | Parameters |
---|---|---|
after-enter | trigger after mouse enter popover | - |
after-leave | trigger after mouse leave popover | - |
before-enter | trigger before mouse enter popover | - |
before-leave | trigger before mouse leave popover | - |
Slots
Name | Description | Parameters |
---|---|---|
default | popper display element | - |
trigger | popper trigger element | - |