@@ -59,7 +59,7 @@ const Holder = defineComponent({
59
59
const getStyles = ( ) => ( {
60
60
left : '50%' ,
61
61
transform : 'translateX(-50%)' ,
62
- top : top ?? DEFAULT_OFFSET ,
62
+ top : ` ${ top ?? DEFAULT_OFFSET } px` ,
63
63
} ) ;
64
64
const getClassName = ( ) => classNames ( hashId . value , props . rtl ? `${ prefixCls . value } -rtl` : '' ) ;
65
65
@@ -113,114 +113,113 @@ export function useInternalMessage(
113
113
messageConfig ?: HolderProps ,
114
114
) : readonly [ MessageInstance , ( ) => VNode ] {
115
115
const holderRef = shallowRef < HolderRef > ( null ) ;
116
+ const holderKey = Symbol ( 'messageHolderKey' ) ;
116
117
// ================================ API ================================
117
- const wrapAPI = computed ( ( ) => {
118
- // Wrap with notification content
119
- // >>> close
120
- const close = ( key : Key ) => {
121
- holderRef . value ?. close ( key ) ;
122
- } ;
123
-
124
- // >>> Open
125
- const open = ( config : ArgsProps ) : MessageType => {
126
- if ( ! holderRef . value ) {
127
- const fakeResult : any = ( ) => { } ;
128
- fakeResult . then = ( ) => { } ;
129
- return fakeResult ;
130
- }
131
118
132
- const { open : originOpen , prefixCls, hashId } = holderRef . value ;
133
- const noticePrefixCls = `${ prefixCls } -notice` ;
134
- const { content, icon, type, key, className, onClose, ...restConfig } = config ;
135
-
136
- let mergedKey : Key = key ! ;
137
- if ( mergedKey === undefined || mergedKey === null ) {
138
- keyIndex += 1 ;
139
- mergedKey = `antd-message-${ keyIndex } ` ;
140
- }
141
-
142
- return wrapPromiseFn ( resolve => {
143
- originOpen ( {
144
- ...restConfig ,
145
- key : mergedKey ,
146
- content : (
147
- < PureContent prefixCls = { prefixCls } type = { type } icon = { icon } >
148
- { content }
149
- </ PureContent >
150
- ) ,
151
- placement : 'top' ,
152
- // @ts -ignore
153
- class : classNames ( type && `${ noticePrefixCls } -${ type } ` , hashId , className ) ,
154
- onClose : ( ) => {
155
- onClose ?.( ) ;
156
- resolve ( ) ;
157
- } ,
158
- } ) ;
159
-
160
- // Return close function
161
- return ( ) => {
162
- close ( mergedKey ) ;
163
- } ;
119
+ // Wrap with notification content
120
+ // >>> close
121
+ const close = ( key : Key ) => {
122
+ holderRef . value ?. close ( key ) ;
123
+ } ;
124
+
125
+ // >>> Open
126
+ const open = ( config : ArgsProps ) : MessageType => {
127
+ if ( ! holderRef . value ) {
128
+ const fakeResult : any = ( ) => { } ;
129
+ fakeResult . then = ( ) => { } ;
130
+ return fakeResult ;
131
+ }
132
+
133
+ const { open : originOpen , prefixCls, hashId } = holderRef . value ;
134
+ const noticePrefixCls = `${ prefixCls } -notice` ;
135
+ const { content, icon, type, key, class : className , onClose, ...restConfig } = config ;
136
+
137
+ let mergedKey : Key = key ! ;
138
+ if ( mergedKey === undefined || mergedKey === null ) {
139
+ keyIndex += 1 ;
140
+ mergedKey = `antd-message-${ keyIndex } ` ;
141
+ }
142
+
143
+ return wrapPromiseFn ( resolve => {
144
+ originOpen ( {
145
+ ...restConfig ,
146
+ key : mergedKey ,
147
+ content : ( ) => (
148
+ < PureContent
149
+ prefixCls = { prefixCls }
150
+ type = { type }
151
+ icon = { typeof icon === 'function' ? icon ( ) : icon }
152
+ >
153
+ { typeof content === 'function' ? content ( ) : content }
154
+ </ PureContent >
155
+ ) ,
156
+ placement : 'top' ,
157
+ // @ts -ignore
158
+ class : classNames ( type && `${ noticePrefixCls } -${ type } ` , hashId , className ) ,
159
+ onClose : ( ) => {
160
+ onClose ?.( ) ;
161
+ resolve ( ) ;
162
+ } ,
164
163
} ) ;
165
- } ;
166
164
167
- // >>> destroy
168
- const destroy = ( key ?: Key ) => {
169
- if ( key !== undefined ) {
170
- close ( key ) ;
165
+ // Return close function
166
+ return ( ) => {
167
+ close ( mergedKey ) ;
168
+ } ;
169
+ } ) ;
170
+ } ;
171
+
172
+ // >>> destroy
173
+ const destroy = ( key ?: Key ) => {
174
+ if ( key !== undefined ) {
175
+ close ( key ) ;
176
+ } else {
177
+ holderRef . value ?. destroy ( ) ;
178
+ }
179
+ } ;
180
+
181
+ const wrapAPI = {
182
+ open,
183
+ destroy,
184
+ } as MessageInstance ;
185
+
186
+ const keys : NoticeType [ ] = [ 'info' , 'success' , 'warning' , 'error' , 'loading' ] ;
187
+ keys . forEach ( type => {
188
+ const typeOpen : TypeOpen = ( jointContent , duration , onClose ) => {
189
+ let config : ArgsProps ;
190
+ if ( jointContent && typeof jointContent === 'object' && 'content' in jointContent ) {
191
+ config = jointContent ;
171
192
} else {
172
- holderRef . value ?. destroy ( ) ;
193
+ config = {
194
+ content : jointContent as VNode ,
195
+ } ;
173
196
}
174
- } ;
175
197
176
- const clone = {
177
- open,
178
- destroy,
179
- } as MessageInstance ;
180
-
181
- const keys : NoticeType [ ] = [ 'info' , 'success' , 'warning' , 'error' , 'loading' ] ;
182
- keys . forEach ( type => {
183
- const typeOpen : TypeOpen = ( jointContent , duration , onClose ) => {
184
- let config : ArgsProps ;
185
- if ( jointContent && typeof jointContent === 'object' && 'content' in jointContent ) {
186
- config = jointContent ;
187
- } else {
188
- config = {
189
- content : jointContent as VNode ,
190
- } ;
191
- }
192
-
193
- // Params
194
- let mergedDuration : number | undefined ;
195
- let mergedOnClose : VoidFunction | undefined ;
196
- if ( typeof duration === 'function' ) {
197
- mergedOnClose = duration ;
198
- } else {
199
- mergedDuration = duration ;
200
- mergedOnClose = onClose ;
201
- }
202
-
203
- const mergedConfig = {
204
- onClose : mergedOnClose ,
205
- duration : mergedDuration ,
206
- ...config ,
207
- type,
208
- } ;
198
+ // Params
199
+ let mergedDuration : number | undefined ;
200
+ let mergedOnClose : VoidFunction | undefined ;
201
+ if ( typeof duration === 'function' ) {
202
+ mergedOnClose = duration ;
203
+ } else {
204
+ mergedDuration = duration ;
205
+ mergedOnClose = onClose ;
206
+ }
209
207
210
- return open ( mergedConfig ) ;
208
+ const mergedConfig = {
209
+ onClose : mergedOnClose ,
210
+ duration : mergedDuration ,
211
+ ...config ,
212
+ type,
211
213
} ;
212
214
213
- clone [ type ] = typeOpen ;
214
- } ) ;
215
+ return open ( mergedConfig ) ;
216
+ } ;
215
217
216
- return clone ;
218
+ wrapAPI [ type ] = typeOpen ;
217
219
} ) ;
218
220
219
221
// ============================== Return ===============================
220
- return [
221
- wrapAPI . value ,
222
- ( ) => < Holder key = "message-holder" { ...messageConfig } ref = { holderRef } /> ,
223
- ] as const ;
222
+ return [ wrapAPI , ( ) => < Holder key = { holderKey } { ...messageConfig } ref = { holderRef } /> ] as const ;
224
223
}
225
224
226
225
export default function useMessage ( messageConfig ?: ConfigOptions ) {
0 commit comments