Skip to content

Commit b95760b

Browse files
committed
feat: update notification
1 parent e43f690 commit b95760b

File tree

9 files changed

+296
-248
lines changed

9 files changed

+296
-248
lines changed

build/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
dev: {
3-
componentName: 'modal', // dev components
3+
componentName: 'notification', // dev components
44
},
55
};

components/notification/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ exports[`renders ./components/notification/demo/custom-style.md correctly 1`] =
99
exports[`renders ./components/notification/demo/duration.md correctly 1`] = `<button type="button" class="ant-btn ant-btn-primary"><span>Open the notification box</span></button>`;
1010

1111
exports[`renders ./components/notification/demo/placement.md correctly 1`] = `
12-
<div>
13-
<div tabindex="0" class="ant-select ant-select-enabled" style="width: 120px; margin-right: 10px;">
14-
<div role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="test-uuid" class="ant-select-selection ant-select-selection--single">
15-
<div class="ant-select-selection__rendered">
16-
<div title="topRight" class="ant-select-selection-selected-value" style="display: block; opacity: 1;">topRight</div>
17-
</div><span unselectable="on" class="ant-select-arrow" style="user-select: none;"><i aria-label="icon: down" class="ant-select-arrow-icon anticon anticon-down"><svg viewBox="64 64 896 896" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span>
18-
</div>
19-
</div> <button type="button" class="ant-btn ant-btn-primary"><span>Open the notification box</span></button>
12+
<div><button type="button" class="ant-btn ant-btn-primary"><i aria-label="icon: radius-upleft" class="anticon anticon-radius-upleft"><svg viewBox="64 64 896 896" data-icon="radius-upleft" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
13+
<path d="M656 200h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm58 624h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM192 650h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm696-696h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm-348 0h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm-174 0h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm174-696H358c-127 0-230 103-230 230v182c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V358c0-87.3 70.7-158 158-158h182c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8z"></path>
14+
</svg></i><span>topLeft</span></button> <button type="button" class="ant-btn ant-btn-primary"><i aria-label="icon: radius-upright" class="anticon anticon-radius-upright"><svg viewBox="64 64 896 896" data-icon="radius-upright" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
15+
<path d="M368 128h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm-2 696h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm522-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM192 128h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm348 0h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm174 0h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm-48-696H484c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h182c87.3 0 158 70.7 158 158v182c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V358c0-127-103-230-230-230z"></path>
16+
</svg></i><span>topRight</span></button>
17+
<div role="separator" class="ant-divider ant-divider-horizontal"></div> <button type="button" class="ant-btn ant-btn-primary"><i aria-label="icon: radius-bottomleft" class="anticon anticon-radius-bottomleft"><svg viewBox="64 64 896 896" data-icon="radius-bottomleft" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
18+
<path d="M712 824h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm2-696h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM136 374h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm0-174h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm752 624h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm-348 0h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm-230 72h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm230 624H358c-87.3 0-158-70.7-158-158V484c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v182c0 127 103 230 230 230h182c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8z"></path>
19+
</svg></i><span>bottomLeft</span></button> <button type="button" class="ant-btn ant-btn-primary"><i aria-label="icon: radius-bottomright" class="anticon anticon-radius-bottomright"><svg viewBox="64 64 896 896" data-icon="radius-bottomright" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
20+
<path d="M368 824h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm-58-624h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm578 102h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM192 824h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0-174h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm292 72h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm174 0h56c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm230 276h-56c-4.4 0-8 3.6-8 8v182c0 87.3-70.7 158-158 158H484c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h182c127 0 230-103 230-230V484c0-4.4-3.6-8-8-8z"></path>
21+
</svg></i><span>bottomRight</span></button>
2022
</div>
2123
`;
2224

components/notification/__tests__/index.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { asyncExpect } from '@/tests/utils';
22
import notification from '..';
3+
import Icon from '../../icon';
34

45
describe('notification', () => {
56
beforeEach(() => {
@@ -90,4 +91,33 @@ describe('notification', () => {
9091
});
9192
expect(document.querySelectorAll('.ant-notification').length).toBe(1);
9293
});
94+
95+
it('support closeIcon', async () => {
96+
await asyncExpect(() => {
97+
notification.open({
98+
message: 'Notification Title',
99+
duration: 0,
100+
closeIcon: h => <Icon type="step-backward" />,
101+
});
102+
});
103+
await asyncExpect(() => {
104+
expect(document.querySelectorAll('.anticon-step-backward').length).toBe(1);
105+
});
106+
});
107+
108+
it('support config closeIcon', async () => {
109+
notification.config({
110+
closeIcon: h => <Icon type="step-backward" />,
111+
});
112+
await asyncExpect(() => {
113+
notification.open({
114+
message: 'Notification Title',
115+
duration: 0,
116+
closeIcon: h => <Icon type="step-backward" />,
117+
});
118+
});
119+
await asyncExpect(() => {
120+
expect(document.querySelectorAll('.anticon-step-backward').length).toBe(1);
121+
});
122+
});
93123
});

components/notification/__tests__/placement.test.js

Lines changed: 107 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -30,125 +30,128 @@ describe('Notification.placement', () => {
3030
open();
3131
}
3232

33-
it('change notification placement by `open` method', async () => {
34-
const defaultTop = '24px';
35-
const defaultBottom = '24px';
36-
let style;
33+
describe('placement', () => {
34+
it('change notification placement by `open` method', async () => {
35+
const defaultTop = '24px';
36+
const defaultBottom = '24px';
37+
let style;
3738

38-
// topLeft
39-
open({
40-
placement: 'topLeft',
39+
// topLeft
40+
open({
41+
placement: 'topLeft',
42+
});
43+
await asyncExpect(() => {
44+
style = getStyle($$('.ant-notification-topLeft')[0]);
45+
expect(style.top).toBe(defaultTop);
46+
expect(style.left).toBe('0px');
47+
expect(style.bottom).toBe('');
48+
});
49+
open({
50+
placement: 'topLeft',
51+
});
52+
await asyncExpect(() => {
53+
expect($$('.ant-notification-topLeft').length).toBe(1);
54+
});
55+
// topRight
56+
open({
57+
placement: 'topRight',
58+
});
59+
await asyncExpect(() => {
60+
style = getStyle($$('.ant-notification-topRight')[0]);
61+
expect(style.top).toBe(defaultTop);
62+
expect(style.right).toBe('0px');
63+
expect(style.bottom).toBe('');
64+
});
65+
open({
66+
placement: 'topRight',
67+
});
68+
await asyncExpect(() => {
69+
expect($$('.ant-notification-topRight').length).toBe(1);
70+
});
71+
// bottomRight
72+
open({
73+
placement: 'bottomRight',
74+
bottom: '100px',
75+
});
76+
await asyncExpect(() => {
77+
style = getStyle($$('.ant-notification-bottomRight')[0]);
78+
expect(style.top).toBe('');
79+
expect(style.right).toBe('0px');
80+
expect(style.bottom).toBe('100px');
81+
});
82+
open({
83+
placement: 'bottomRight',
84+
});
85+
await asyncExpect(() => {
86+
expect($$('.ant-notification-bottomRight').length).toBe(1);
87+
});
88+
// bottomLeft
89+
open({
90+
placement: 'bottomLeft',
91+
});
92+
await asyncExpect(() => {
93+
style = getStyle($$('.ant-notification-bottomLeft')[0]);
94+
expect(style.top).toBe('');
95+
expect(style.left).toBe('0px');
96+
expect(style.bottom).toBe(defaultBottom);
97+
});
98+
open({
99+
placement: 'bottomLeft',
100+
});
101+
await asyncExpect(() => {
102+
expect($$('.ant-notification-bottomLeft').length).toBe(1);
103+
});
104+
await asyncExpect(() => {});
105+
await asyncExpect(() => {});
41106
});
42-
await asyncExpect(() => {
107+
108+
it('change notification placement by `config` method', () => {
109+
let style;
110+
111+
// topLeft
112+
config({
113+
placement: 'topLeft',
114+
top: '50px',
115+
bottom: '50px',
116+
});
43117
style = getStyle($$('.ant-notification-topLeft')[0]);
44-
expect(style.top).toBe(defaultTop);
118+
expect(style.top).toBe('50px');
45119
expect(style.left).toBe('0px');
46120
expect(style.bottom).toBe('');
47-
});
48-
open({
49-
placement: 'topLeft',
50-
});
51-
await asyncExpect(() => {
52-
expect($$('.ant-notification-topLeft').length).toBe(1);
53-
});
54-
// topRight
55-
open({
56-
placement: 'topRight',
57-
});
58-
await asyncExpect(() => {
121+
122+
// topRight
123+
config({
124+
placement: 'topRight',
125+
top: '100px',
126+
bottom: '50px',
127+
});
59128
style = getStyle($$('.ant-notification-topRight')[0]);
60-
expect(style.top).toBe(defaultTop);
129+
expect(style.top).toBe('100px');
61130
expect(style.right).toBe('0px');
62131
expect(style.bottom).toBe('');
63-
});
64-
open({
65-
placement: 'topRight',
66-
});
67-
await asyncExpect(() => {
68-
expect($$('.ant-notification-topRight').length).toBe(1);
69-
});
70-
// bottomRight
71-
open({
72-
placement: 'bottomRight',
73-
});
74-
await asyncExpect(() => {
132+
133+
// bottomRight
134+
config({
135+
placement: 'bottomRight',
136+
top: '50px',
137+
bottom: '100px',
138+
});
75139
style = getStyle($$('.ant-notification-bottomRight')[0]);
76140
expect(style.top).toBe('');
77141
expect(style.right).toBe('0px');
78-
expect(style.bottom).toBe(defaultBottom);
79-
});
80-
open({
81-
placement: 'bottomRight',
82-
});
83-
await asyncExpect(() => {
84-
expect($$('.ant-notification-bottomRight').length).toBe(1);
85-
});
86-
// bottomLeft
87-
open({
88-
placement: 'bottomLeft',
89-
});
90-
await asyncExpect(() => {
142+
expect(style.bottom).toBe('100px');
143+
144+
// bottomLeft
145+
config({
146+
placement: 'bottomLeft',
147+
top: 100,
148+
bottom: 50,
149+
});
91150
style = getStyle($$('.ant-notification-bottomLeft')[0]);
92151
expect(style.top).toBe('');
93152
expect(style.left).toBe('0px');
94-
expect(style.bottom).toBe(defaultBottom);
95-
});
96-
open({
97-
placement: 'bottomLeft',
98-
});
99-
await asyncExpect(() => {
100-
expect($$('.ant-notification-bottomLeft').length).toBe(1);
101-
});
102-
await asyncExpect(() => {});
103-
await asyncExpect(() => {});
104-
});
105-
106-
it('change notification placement by `config` method', () => {
107-
let style;
108-
109-
// topLeft
110-
config({
111-
placement: 'topLeft',
112-
top: '50px',
113-
bottom: '50px',
114-
});
115-
style = getStyle($$('.ant-notification-topLeft')[0]);
116-
expect(style.top).toBe('50px');
117-
expect(style.left).toBe('0px');
118-
expect(style.bottom).toBe('');
119-
120-
// topRight
121-
config({
122-
placement: 'topRight',
123-
top: '100px',
124-
bottom: '50px',
125-
});
126-
style = getStyle($$('.ant-notification-topRight')[0]);
127-
expect(style.top).toBe('100px');
128-
expect(style.right).toBe('0px');
129-
expect(style.bottom).toBe('');
130-
131-
// bottomRight
132-
config({
133-
placement: 'bottomRight',
134-
top: '50px',
135-
bottom: '100px',
136-
});
137-
style = getStyle($$('.ant-notification-bottomRight')[0]);
138-
expect(style.top).toBe('');
139-
expect(style.right).toBe('0px');
140-
expect(style.bottom).toBe('100px');
141-
142-
// bottomLeft
143-
config({
144-
placement: 'bottomLeft',
145-
top: 100,
146-
bottom: 50,
153+
expect(style.bottom).toBe('50px');
147154
});
148-
style = getStyle($$('.ant-notification-bottomLeft')[0]);
149-
expect(style.top).toBe('');
150-
expect(style.left).toBe('0px');
151-
expect(style.bottom).toBe('50px');
152155
});
153156
it('change notification mountNode by `config` method', () => {
154157
const $container = document.createElement('div');

components/notification/demo/placement.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ A notification box can pop up from `topRight` or `bottomRight` or `bottomLeft` o
1111
```tpl
1212
<template>
1313
<div>
14-
<a-select v-model="selected" :style="{ width: '120px', marginRight: '10px' }">
15-
<a-select-option v-for="val in options" :key="val" :value="val">{{val}}</a-select-option>
16-
</a-select>
17-
<a-button type="primary" @click="openNotification">Open the notification box</a-button>
14+
<a-button type="primary" @click="openNotification('topLeft')">
15+
<a-icon type="radius-upleft" />
16+
topLeft
17+
</a-button>
18+
<a-button type="primary" @click="openNotification('topRight')">
19+
<a-icon type="radius-upright" />
20+
topRight
21+
</a-button>
22+
<a-divider />
23+
<a-button type="primary" @click="openNotification('bottomLeft')">
24+
<a-icon type="radius-bottomleft" />
25+
bottomLeft
26+
</a-button>
27+
<a-button type="primary" @click="openNotification('bottomRight')">
28+
<a-icon type="radius-bottomright" />
29+
bottomRight
30+
</a-button>
1831
</div>
1932
</template>
2033
<script>
21-
const options = ['topLeft', 'topRight', 'bottomLeft', 'bottomRight'];
2234
export default {
23-
data() {
24-
return {
25-
options,
26-
selected: 'topRight',
27-
};
28-
},
29-
watch: {
30-
selected(val) {
31-
this.$notification.config({
32-
placement: val,
33-
});
34-
},
35-
},
3635
methods: {
37-
openNotification(val) {
36+
openNotification(placement) {
3837
this.$notification.open({
39-
message: 'Notification Title',
38+
message: `Notification ${placement}`,
4039
description:
4140
'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
41+
placement,
4242
});
4343
},
4444
},

0 commit comments

Comments
 (0)