Skip to content

Commit 5cf2707

Browse files
committed
feat: notification add top & bottom placement
1 parent d716421 commit 5cf2707

File tree

6 files changed

+122
-33
lines changed

6 files changed

+122
-33
lines changed

components/notification/demo/placement.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
<docs>
22
---
3-
order: 6
3+
order: 5
44
title:
55
zh-CN: 位置
66
en-US: Placement
77
---
88

99
## zh-CN
1010

11-
可以设置通知从右上角、右下角、左下角、左上角弹出。
11+
使用 `placement` 可以配置通知从右上角、右下角、左下角、左上角弹出。
1212

1313
## en-US
1414

15-
A notification box can pop up from `topRight` or `bottomRight` or `bottomLeft` or `topLeft`.
15+
A notification box can appear from the `topRight`, `bottomRight`, `bottomLeft` or `topLeft` of the viewport via `placement`.
1616

1717
</docs>
1818

1919
<template>
2020
<div>
21+
<a-button type="primary" @click="openNotification('top')">
22+
<template #icon><BorderTopOutlined /></template>
23+
top
24+
</a-button>
25+
<a-button type="primary" @click="openNotification('bottom')">
26+
<template #icon><BorderBottomOutlined /></template>
27+
bottom
28+
</a-button>
2129
<a-button type="primary" @click="openNotification('topLeft')">
22-
<radius-upleft-outlined />
30+
<template #icon><radius-upleft-outlined /></template>
2331
topLeft
2432
</a-button>
2533
<a-button type="primary" @click="openNotification('topRight')">
26-
<radius-upright-outlined />
34+
<template #icon><radius-upright-outlined /></template>
2735
topRight
2836
</a-button>
2937
<a-divider />
3038
<a-button type="primary" @click="openNotification('bottomLeft')">
31-
<radius-bottomleft-outlined />
39+
<template #icon><radius-bottomleft-outlined /></template>
3240
bottomLeft
3341
</a-button>
3442
<a-button type="primary" @click="openNotification('bottomRight')">
35-
<radius-bottomright-outlined />
43+
<template #icon><radius-bottomright-outlined /></template>
3644
bottomRight
3745
</a-button>
3846
</div>
@@ -43,6 +51,8 @@ import {
4351
RadiusUprightOutlined,
4452
RadiusBottomleftOutlined,
4553
RadiusBottomrightOutlined,
54+
BorderTopOutlined,
55+
BorderBottomOutlined,
4656
} from '@ant-design/icons-vue';
4757
import { notification } from 'ant-design-vue';
4858
import { defineComponent } from 'vue';
@@ -53,6 +63,8 @@ export default defineComponent({
5363
RadiusUprightOutlined,
5464
RadiusBottomleftOutlined,
5565
RadiusBottomrightOutlined,
66+
BorderTopOutlined,
67+
BorderBottomOutlined,
5668
},
5769
setup() {
5870
const openNotification = (placement: NotificationPlacement) => {

components/notification/index.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The properties of config are as follows:
4040
| icon | Customized icon | VNode \| () => VNode | - | |
4141
| key | The unique identifier of the Notification | string | - | |
4242
| message | The title of notification box (required) | string\| VNode \| () => VNode | - | |
43-
| placement | Position of Notification, can be one of `topLeft` `topRight` `bottomLeft` `bottomRight` | string | `topRight` | |
43+
| placement | Position of Notification, can be one of `top` `topLeft` `topRight` `bottom` `bottomLeft` `bottomRight` | string | `topRight` | `top` `bottom` 3.3.0 |
4444
| style | Customized inline style | Object \| string | - | |
4545
| top | Distance from the top of the viewport, when `placement` is `topRight` or `topLeft` (unit: pixels). | string | `24px` | |
4646
| onClick | Specify a function that will be called when the notification is clicked | Function | - | |

components/notification/index.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import { globalConfig } from '../config-provider';
1111
import type { NotificationInstance as VCNotificationInstance } from '../vc-notification/Notification';
1212
import classNames from '../_util/classNames';
1313

14-
export type NotificationPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
14+
export type NotificationPlacement =
15+
| 'top'
16+
| 'topLeft'
17+
| 'topRight'
18+
| 'bottom'
19+
| 'bottomLeft'
20+
| 'bottomRight';
1521

1622
export type IconType = 'success' | 'info' | 'error' | 'warning';
1723

@@ -76,6 +82,15 @@ function getPlacementStyle(
7682
) {
7783
let style: CSSProperties;
7884
switch (placement) {
85+
case 'top':
86+
style = {
87+
left: '50%',
88+
transform: 'translateX(-50%)',
89+
right: 'auto',
90+
top,
91+
bottom: 'auto',
92+
};
93+
break;
7994
case 'topLeft':
8095
style = {
8196
left: '0px',
@@ -90,6 +105,15 @@ function getPlacementStyle(
90105
bottom: 'auto',
91106
};
92107
break;
108+
case 'bottom':
109+
style = {
110+
left: '50%',
111+
transform: 'translateX(-50%)',
112+
right: 'auto',
113+
top: 'auto',
114+
bottom,
115+
};
116+
break;
93117
case 'bottomLeft':
94118
style = {
95119
left: '0px',
@@ -177,6 +201,7 @@ export interface NotificationArgsProps {
177201
duration?: number | null;
178202
icon?: VueNode | (() => VueNode);
179203
placement?: NotificationPlacement;
204+
maxCount?: number;
180205
style?: CSSProperties;
181206
prefixCls?: string;
182207
class?: string;

components/notification/index.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ config 参数如下:
4141
| icon | 自定义图标 | VNode \| () => VNode | - | |
4242
| key | 当前通知唯一标志 | string | - | |
4343
| message | 通知提醒标题,必选 | string \| VNode \| () => VNode | - | |
44-
| placement | 弹出位置,可选 `topLeft` `topRight` `bottomLeft` `bottomRight` | string | topRight | |
44+
| placement | 弹出位置,可选 `top` `topLeft` `topRight` `bottom` `bottomLeft` `bottomRight` | string | `topRight` | `top` `bottom` 3.3.0 |
4545
| style | 自定义内联样式 | Object \| string | - | |
4646
| top | 消息从顶部弹出时,距离顶部的位置,单位像素。 | string | `24px` | |
4747
| onClick | 点击通知时触发的回调函数 | Function | - | |

components/notification/style/index.less

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616
z-index: @zindex-notification;
1717
margin-right: @notification-margin-edge;
1818

19-
&-topLeft,
20-
&-bottomLeft {
21-
margin-right: 0;
22-
margin-left: @notification-margin-edge;
23-
24-
.@{notification-prefix-cls}-fade-enter.@{notification-prefix-cls}-fade-enter-active,
25-
.@{notification-prefix-cls}-fade-appear.@{notification-prefix-cls}-fade-appear-active {
26-
animation-name: NotificationLeftFadeIn;
27-
}
28-
}
29-
3019
&-close-icon {
3120
font-size: @font-size-base;
3221
cursor: pointer;
@@ -50,6 +39,12 @@
5039
border-radius: @border-radius-base;
5140
box-shadow: @shadow-2;
5241

42+
.@{notification-prefix-cls}-top &,
43+
.@{notification-prefix-cls}-bottom & {
44+
margin-right: auto;
45+
margin-left: auto;
46+
}
47+
5348
.@{notification-prefix-cls}-topLeft &,
5449
.@{notification-prefix-cls}-bottomLeft & {
5550
margin-right: auto;
@@ -192,18 +187,6 @@
192187
}
193188
}
194189

195-
@keyframes NotificationLeftFadeIn {
196-
0% {
197-
right: @notification-width;
198-
opacity: 0;
199-
}
200-
201-
100% {
202-
right: 0;
203-
opacity: 1;
204-
}
205-
}
206-
207190
@keyframes NotificationFadeOut {
208191
0% {
209192
max-height: 150px;
@@ -221,3 +204,4 @@
221204
}
222205

223206
@import './rtl';
207+
@import './placement';
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.@{notification-prefix-cls} {
2+
&-top,
3+
&-bottom {
4+
margin-right: 0;
5+
margin-left: 0;
6+
}
7+
8+
&-top {
9+
.@{notification-prefix-cls}-fade-enter.@{notification-prefix-cls}-fade-enter-active,
10+
.@{notification-prefix-cls}-fade-appear.@{notification-prefix-cls}-fade-appear-active {
11+
animation-name: NotificationTopFadeIn;
12+
}
13+
}
14+
15+
&-bottom {
16+
.@{notification-prefix-cls}-fade-enter.@{notification-prefix-cls}-fade-enter-active,
17+
.@{notification-prefix-cls}-fade-appear.@{notification-prefix-cls}-fade-appear-active {
18+
animation-name: NotificationBottomFadeIn;
19+
}
20+
}
21+
22+
&-topLeft,
23+
&-bottomLeft {
24+
margin-right: 0;
25+
margin-left: @notification-margin-edge;
26+
27+
.@{notification-prefix-cls}-fade-enter.@{notification-prefix-cls}-fade-enter-active,
28+
.@{notification-prefix-cls}-fade-appear.@{notification-prefix-cls}-fade-appear-active {
29+
animation-name: NotificationLeftFadeIn;
30+
}
31+
}
32+
}
33+
34+
@keyframes NotificationTopFadeIn {
35+
0% {
36+
margin-top: -100%;
37+
opacity: 0;
38+
}
39+
40+
100% {
41+
margin-top: 0;
42+
opacity: 1;
43+
}
44+
}
45+
46+
@keyframes NotificationBottomFadeIn {
47+
0% {
48+
margin-bottom: -100%;
49+
opacity: 0;
50+
}
51+
52+
100% {
53+
margin-bottom: 0;
54+
opacity: 1;
55+
}
56+
}
57+
58+
@keyframes NotificationLeftFadeIn {
59+
0% {
60+
right: @notification-width;
61+
opacity: 0;
62+
}
63+
64+
100% {
65+
right: 0;
66+
opacity: 1;
67+
}
68+
}

0 commit comments

Comments
 (0)