1
- import type { VNodeTypes , CSSProperties } from 'vue' ;
1
+ import type { CSSProperties } from 'vue' ;
2
2
import Notification from '../vc-notification' ;
3
3
import CheckCircleOutlined from '@ant-design/icons-vue/CheckCircleOutlined' ;
4
4
import InfoCircleOutlined from '@ant-design/icons-vue/InfoCircleOutlined' ;
5
5
import CloseCircleOutlined from '@ant-design/icons-vue/CloseCircleOutlined' ;
6
6
import ExclamationCircleOutlined from '@ant-design/icons-vue/ExclamationCircleOutlined' ;
7
7
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined' ;
8
+ import type { VueNode } from '../_util/type' ;
9
+ import { renderHelper } from '../_util/util' ;
10
+ import { globalConfig } from '../config-provider' ;
8
11
9
12
export type NotificationPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' ;
10
13
@@ -14,21 +17,26 @@ export interface ConfigProps {
14
17
top ?: string | number ;
15
18
bottom ?: string | number ;
16
19
duration ?: number ;
20
+ prefixCls ?: string ;
17
21
placement ?: NotificationPlacement ;
18
22
getContainer ?: ( ) => HTMLElement ;
19
- closeIcon ?: VNodeTypes ;
23
+ closeIcon ?: VueNode | ( ( ) => VueNode ) ;
20
24
}
21
25
22
26
const notificationInstance : { [ key : string ] : any } = { } ;
23
27
let defaultDuration = 4.5 ;
24
28
let defaultTop = '24px' ;
25
29
let defaultBottom = '24px' ;
30
+ let defaultPrefixCls = '' ;
26
31
let defaultPlacement : NotificationPlacement = 'topRight' ;
27
32
let defaultGetContainer = ( ) => document . body ;
28
33
let defaultCloseIcon = null ;
29
34
30
35
function setNotificationConfig ( options : ConfigProps ) {
31
- const { duration, placement, bottom, top, getContainer, closeIcon } = options ;
36
+ const { duration, placement, bottom, top, getContainer, closeIcon, prefixCls } = options ;
37
+ if ( prefixCls !== undefined ) {
38
+ defaultPrefixCls = prefixCls ;
39
+ }
32
40
if ( duration !== undefined ) {
33
41
defaultDuration = duration ;
34
42
}
@@ -88,41 +96,37 @@ function getPlacementStyle(
88
96
return style ;
89
97
}
90
98
91
- type NotificationInstanceProps = {
92
- prefixCls : string ;
93
- placement ?: NotificationPlacement ;
94
- getContainer ?: ( ) => HTMLElement ;
95
- top ?: string ;
96
- bottom ?: string ;
97
- closeIcon ?: VNodeTypes ;
98
- } ;
99
-
100
99
function getNotificationInstance (
101
100
{
102
- prefixCls,
101
+ prefixCls : customizePrefixCls ,
103
102
placement = defaultPlacement ,
104
103
getContainer = defaultGetContainer ,
105
104
top,
106
105
bottom,
107
106
closeIcon = defaultCloseIcon ,
108
- } : NotificationInstanceProps ,
107
+ appContext,
108
+ } : NotificationArgsProps ,
109
109
callback : ( n : any ) => void ,
110
110
) {
111
+ const { getPrefixCls } = globalConfig ( ) ;
112
+ const prefixCls = getPrefixCls ( 'notification' , customizePrefixCls || defaultPrefixCls ) ;
111
113
const cacheKey = `${ prefixCls } -${ placement } ` ;
112
114
if ( notificationInstance [ cacheKey ] ) {
113
115
callback ( notificationInstance [ cacheKey ] ) ;
114
116
return ;
115
117
}
116
118
Notification . newInstance (
117
119
{
118
- prefixCls,
120
+ name : 'notification' ,
121
+ prefixCls : customizePrefixCls || defaultPrefixCls ,
119
122
class : `${ prefixCls } -${ placement } ` ,
120
123
style : getPlacementStyle ( placement , top , bottom ) ,
124
+ appContext,
121
125
getContainer,
122
- closeIcon : ( ) => {
126
+ closeIcon : ( { prefixCls } ) => {
123
127
const closeIconToRender = (
124
128
< span class = { `${ prefixCls } -close-x` } >
125
- { closeIcon || < CloseOutlined class = { `${ prefixCls } -close-icon` } /> }
129
+ { renderHelper ( closeIcon , { } , < CloseOutlined class = { `${ prefixCls } -close-icon` } /> ) }
126
130
</ span >
127
131
) ;
128
132
return closeIconToRender ;
@@ -143,13 +147,13 @@ const typeToIcon = {
143
147
} ;
144
148
145
149
export interface NotificationArgsProps {
146
- message : VNodeTypes ;
147
- description ?: VNodeTypes ;
148
- btn ?: VNodeTypes ;
150
+ message : VueNode | ( ( ) => VueNode ) ;
151
+ description ?: VueNode | ( ( ) => VueNode ) ;
152
+ btn ?: VueNode | ( ( ) => VueNode ) ;
149
153
key ?: string ;
150
154
onClose ?: ( ) => void ;
151
155
duration ?: number | null ;
152
- icon ?: VNodeTypes ;
156
+ icon ?: VueNode | ( ( ) => VueNode ) ;
153
157
placement ?: NotificationPlacement ;
154
158
style ?: CSSProperties ;
155
159
prefixCls ?: string ;
@@ -159,57 +163,46 @@ export interface NotificationArgsProps {
159
163
top ?: string ;
160
164
bottom ?: string ;
161
165
getContainer ?: ( ) => HTMLElement ;
162
- closeIcon ?: VNodeTypes ;
166
+ closeIcon ?: VueNode | ( ( ) => VueNode ) ;
167
+ appContext ?: any ;
163
168
}
164
169
165
170
function notice ( args : NotificationArgsProps ) {
166
171
const { icon, type, description, message, btn } = args ;
167
- const outerPrefixCls = args . prefixCls || 'ant-notification' ;
168
- const prefixCls = `${ outerPrefixCls } -notice` ;
169
172
const duration = args . duration === undefined ? defaultDuration : args . duration ;
170
-
171
- let iconNode = null ;
172
- if ( icon ) {
173
- iconNode = ( ) => < span class = { `${ prefixCls } -icon` } > { icon } </ span > ;
174
- } else if ( type ) {
175
- const Icon = typeToIcon [ type ] ;
176
- iconNode = ( ) => < Icon class = { `${ prefixCls } -icon ${ prefixCls } -icon-${ type } ` } /> ;
177
- }
178
- const { placement, top, bottom, getContainer, closeIcon } = args ;
179
- getNotificationInstance (
180
- {
181
- prefixCls : outerPrefixCls ,
182
- placement,
183
- top,
184
- bottom,
185
- getContainer,
186
- closeIcon,
187
- } ,
188
- notification => {
189
- notification . notice ( {
190
- content : ( ) => (
173
+ getNotificationInstance ( args , notification => {
174
+ notification . notice ( {
175
+ content : ( { prefixCls } ) => {
176
+ let iconNode = null ;
177
+ if ( icon ) {
178
+ iconNode = ( ) => < span class = { `${ prefixCls } -icon` } > { renderHelper ( icon ) } </ span > ;
179
+ } else if ( type ) {
180
+ const Icon = typeToIcon [ type ] ;
181
+ iconNode = ( ) => < Icon class = { `${ prefixCls } -icon ${ prefixCls } -icon-${ type } ` } /> ;
182
+ }
183
+ return (
191
184
< div class = { iconNode ? `${ prefixCls } -with-icon` : '' } >
192
185
{ iconNode && iconNode ( ) }
193
186
< div class = { `${ prefixCls } -message` } >
194
187
{ ! description && iconNode ? (
195
188
< span class = { `${ prefixCls } -message-single-line-auto-margin` } />
196
189
) : null }
197
- { message }
190
+ { renderHelper ( message ) }
198
191
</ div >
199
- < div class = { `${ prefixCls } -description` } > { description } </ div >
200
- { btn ? < span class = { `${ prefixCls } -btn` } > { btn } </ span > : null }
192
+ < div class = { `${ prefixCls } -description` } > { renderHelper ( description ) } </ div >
193
+ { btn ? < span class = { `${ prefixCls } -btn` } > { renderHelper ( btn ) } </ span > : null }
201
194
</ div >
202
- ) ,
203
- duration ,
204
- closable : true ,
205
- onClose : args . onClose ,
206
- onClick : args . onClick ,
207
- key : args . key ,
208
- style : args . style || { } ,
209
- class : args . class ,
210
- } ) ;
211
- } ,
212
- ) ;
195
+ ) ;
196
+ } ,
197
+ duration ,
198
+ closable : true ,
199
+ onClose : args . onClose ,
200
+ onClick : args . onClick ,
201
+ key : args . key ,
202
+ style : args . style || { } ,
203
+ class : args . class ,
204
+ } ) ;
205
+ } ) ;
213
206
}
214
207
215
208
const apiBase = {
0 commit comments