Skip to content

Commit 9412f96

Browse files
author
Tenny
committed
Signed-off-by: Tenny <joel.shu@qq.com>
1 parent 421aaac commit 9412f96

File tree

7 files changed

+95
-0
lines changed

7 files changed

+95
-0
lines changed

docs/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default defineConfig({
4545
{ text: 'Icon 图标', link: '/components/icon' },
4646
{ text: 'Button 按钮', link: '/components/button' },
4747
{ text: 'Input 输入框', link: '/components/input' },
48+
{ text: 'Popover 弹出起泡', link: '/components/popover' },
4849
{ text: 'Tooltip 文字提示', link: '/components/tooltip' },
4950
{ text: 'Message 消息提示', link: '/components/message' },
5051
{ text: 'Card 卡片', link: '/components/card' },

docs/.vitepress/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import '../../../style/progress';
2626
import '../../../style/loading';
2727
import '../../../style/description-panel';
2828
import '../../../style/tabbar';
29+
import '../../../style/popover';
2930
import '../../../style/util/tabs.css';
3031

3132
export default {

docs/components/popover.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Popover 弹出起泡
2+
3+
点击/鼠标移入元素,弹出气泡式的卡片浮层。在内容周围弹出一些隐藏的信息。和 `Tooltip` 的区别是,用户可以对浮层上的元素进行操作,因此它可以承载更复杂的内容,比如链接或按钮等。
4+
5+
## 演示
6+
7+
<script setup>
8+
import { Popover, Button } from '../../src'
9+
10+
function click1() {
11+
console.log('click1')
12+
}
13+
</script>
14+
15+
### 基础用法
16+
17+
18+
19+
<ClientOnly>
20+
<CodePreview>
21+
<textarea lang="vue">
22+
<script setup>
23+
</script>
24+
<template>
25+
</template>
26+
</textarea>
27+
<template #preview>
28+
<Popover>
29+
<Button @click="click1">悬浮</Button>
30+
</Popover>
31+
</template>
32+
</CodePreview>
33+
</ClientOnly>
34+
35+
## API
36+
37+
### Popover Props
38+
39+
| 参数 | 说明 | 类型 | 默认值 |
40+
| ---- | ---- | ---- | ------ |
41+
| x | x | x | x |

src/components/Popover.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<script lang="ts">
2+
import { defineComponent, h, VNode } from 'vue';
3+
import type { PropType } from 'vue';
4+
5+
function getFirstSlotVNode(vnodes?: VNode[]) {
6+
if (vnodes != null) {
7+
return vnodes[0];
8+
}
9+
return null;
10+
}
11+
12+
export default defineComponent({
13+
props: {
14+
trigger: {
15+
type: String as PropType<'hover' | 'click'>,
16+
default: 'hover',
17+
},
18+
},
19+
setup(props, { slots }) {
20+
function handleMouseEnter(e: Event) {
21+
console.log('mouseenter');
22+
}
23+
24+
function hanldeMouseLeave(e: Event) {
25+
console.log('mouseleave');
26+
}
27+
28+
function handleClick(e: Event) {
29+
console.log('click');
30+
}
31+
32+
return () => {
33+
const firstVNode = getFirstSlotVNode(
34+
slots.default != null ? slots.default() : undefined,
35+
);
36+
if (firstVNode == null) {
37+
return null;
38+
}
39+
const prop: any = {};
40+
if (props.trigger === 'hover') {
41+
prop.onMouseenter = handleMouseEnter;
42+
prop.onMouseleave = hanldeMouseLeave;
43+
} else {
44+
prop.onClick = handleClick;
45+
}
46+
return h('div', h(firstVNode, prop));
47+
};
48+
},
49+
});
50+
</script>

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ export { default as Tabbar } from './components/tabbar/Tabbar.vue';
4545
export { default as TabbarItem } from './components/tabbar/TabbarItem.vue';
4646

4747
export type { ColumnOption } from './components/Table.vue';
48+
export { default as Popover } from "./components/Popover.vue"

style/popover/index.css

Whitespace-only changes.

style/popover/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./index.css";

0 commit comments

Comments
 (0)