Skip to content

Commit 9767340

Browse files
committed
feat(Notification): add Hook demo
1 parent acfd684 commit 9767340

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

components/notification/demo/hook.vue

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<docs>
2+
---
3+
order: 10
4+
title:
5+
zh-CN: Hooks 调用(推荐)
6+
en-US: Hooks Usage (Recommend)
7+
---
8+
9+
## zh-CN
10+
11+
通过 `notification.useNotification` 创建支持读取 context 的 `contextHolder`。请注意,我们推荐通过顶层注册的方式代替 `message` 静态方法,因为静态方法无法消费上下文,因而 ConfigProvider 的数据也不会生效。
12+
13+
## en-US
14+
15+
Use `notification.useNotification` to get `contextHolder` with context accessible issue. Please note that, we recommend to use top level registration instead of `notification` static method, because static method cannot consume context, and ConfigProvider data will not work.
16+
17+
</docs>
18+
<template>
19+
<a-space>
20+
<a-button type="primary" @click="() => open('topLeft')">
21+
<RadiusUpleftOutlined />
22+
topLeft
23+
</a-button>
24+
<a-button type="primary" @click="() => open('topRight')">
25+
<RadiusUprightOutlined />
26+
topRight
27+
</a-button>
28+
</a-space>
29+
<a-divider />
30+
<a-space>
31+
<a-button type="primary" @click="() => open('bottomLeft')">
32+
<RadiusBottomleftOutlined />
33+
bottomLeft
34+
</a-button>
35+
<a-button type="primary" @click="() => open('bottomRight')">
36+
<RadiusBottomrightOutlined />
37+
bottomRight
38+
</a-button>
39+
</a-space>
40+
<contextHolder />
41+
</template>
42+
43+
<script lang="ts" setup>
44+
import {
45+
RadiusBottomleftOutlined,
46+
RadiusBottomrightOutlined,
47+
RadiusUpleftOutlined,
48+
RadiusUprightOutlined,
49+
} from '@ant-design/icons-vue';
50+
import { NotificationPlacement, notification } from 'ant-design-vue';
51+
const [api, contextHolder] = notification.useNotification();
52+
const open = (placement: NotificationPlacement) => openNotification(placement);
53+
const openNotification = (placement: NotificationPlacement) => {
54+
api.info({
55+
message: `Notification ${placement}`,
56+
description:
57+
'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
58+
placement,
59+
});
60+
};
61+
</script>

components/notification/demo/index.vue

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<demo-sort>
3+
<hook />
34
<basic />
45
<duratioin />
56
<with-icon />
@@ -12,6 +13,7 @@
1213
</template>
1314
<script lang="ts">
1415
import Basic from './basic.vue';
16+
import Hook from './hook.vue';
1517
import Duratioin from './duration.vue';
1618
import WithIcon from './with-icon.vue';
1719
import CustomIcon from './custom-icon.vue';
@@ -35,6 +37,7 @@ export default defineComponent({
3537
CustomStyle,
3638
Placement,
3739
Update,
40+
Hook,
3841
},
3942
setup() {
4043
return {};

0 commit comments

Comments
 (0)