1
+ import { inject } from 'vue' ;
1
2
import classNames from 'classnames' ;
2
3
import Dialog from '../vc-dialog' ;
3
4
import PropTypes from '../_util/vue-types' ;
@@ -8,14 +9,7 @@ import Button from '../button';
8
9
import buttonTypes from '../button/buttonTypes' ;
9
10
const ButtonType = buttonTypes ( ) . type ;
10
11
import LocaleReceiver from '../locale-provider/LocaleReceiver' ;
11
- import {
12
- initDefaultProps ,
13
- getComponentFromProp ,
14
- getClass ,
15
- getStyle ,
16
- mergeProps ,
17
- getListeners ,
18
- } from '../_util/props-util' ;
12
+ import { initDefaultProps , getComponent , getSlot } from '../_util/props-util' ;
19
13
import { ConfigConsumerProps } from '../config-provider' ;
20
14
21
15
let mousePosition = null ;
@@ -116,8 +110,10 @@ export default {
116
110
this . sVisible = val ;
117
111
} ,
118
112
} ,
119
- inject : {
120
- configProvider : { default : ( ) => ConfigConsumerProps } ,
113
+ setup ( ) {
114
+ return {
115
+ configProvider : inject ( 'configProvider' , ConfigConsumerProps ) ,
116
+ } ;
121
117
} ,
122
118
// static info: ModalFunc;
123
119
// static success: ModalFunc;
@@ -128,6 +124,7 @@ export default {
128
124
methods : {
129
125
handleCancel ( e ) {
130
126
this . $emit ( 'cancel' , e ) ;
127
+ this . $emit ( 'update:visible' , false ) ;
131
128
this . $emit ( 'change' , false ) ;
132
129
} ,
133
130
@@ -136,26 +133,19 @@ export default {
136
133
} ,
137
134
renderFooter ( locale ) {
138
135
const { okType, confirmLoading } = this ;
139
- const cancelBtnProps = mergeProps (
140
- { on : { click : this . handleCancel } } ,
141
- this . cancelButtonProps || { } ,
142
- ) ;
143
- const okBtnProps = mergeProps (
144
- {
145
- on : { click : this . handleOk } ,
146
- props : {
147
- type : okType ,
148
- loading : confirmLoading ,
149
- } ,
150
- } ,
151
- this . okButtonProps || { } ,
152
- ) ;
136
+ const cancelBtnProps = { onClick : this . handleCancel , ...( this . cancelButtonProps || { } ) } ;
137
+ const okBtnProps = {
138
+ onClick : this . handleOk ,
139
+ type : okType ,
140
+ loading : confirmLoading ,
141
+ ...( this . okButtonProps || { } ) ,
142
+ } ;
153
143
return (
154
144
< div >
155
145
< Button { ...cancelBtnProps } >
156
- { getComponentFromProp ( this , 'cancelText' ) || locale . cancelText }
146
+ { getComponent ( this , 'cancelText' ) || locale . cancelText }
157
147
</ Button >
158
- < Button { ...okBtnProps } > { getComponentFromProp ( this , 'okText' ) || locale . okText } </ Button >
148
+ < Button { ...okBtnProps } > { getComponent ( this , 'okText' ) || locale . okText } </ Button >
159
149
</ div >
160
150
) ;
161
151
} ,
@@ -168,48 +158,39 @@ export default {
168
158
wrapClassName,
169
159
centered,
170
160
getContainer,
171
- $slots,
172
- $scopedSlots,
173
161
$attrs,
174
162
} = this ;
175
- const children = $scopedSlots . default ? $scopedSlots . default ( ) : $slots . default ;
163
+ const children = getSlot ( this ) ;
176
164
const { getPrefixCls, getPopupContainer : getContextPopupContainer } = this . configProvider ;
177
165
const prefixCls = getPrefixCls ( 'modal' , customizePrefixCls ) ;
178
166
179
167
const defaultFooter = (
180
168
< LocaleReceiver
181
169
componentName = "Modal"
182
170
defaultLocale = { getConfirmLocale ( ) }
183
- scopedSlots = { { default : this . renderFooter } }
171
+ children = { this . renderFooter }
184
172
/>
185
173
) ;
186
- const closeIcon = getComponentFromProp ( this , 'closeIcon' ) ;
174
+ const closeIcon = getComponent ( this , 'closeIcon' ) ;
187
175
const closeIconToRender = (
188
176
< span class = { `${ prefixCls } -close-x` } >
189
177
{ closeIcon || < CloseOutlined class = { `${ prefixCls } -close-icon` } /> }
190
178
</ span >
191
179
) ;
192
- const footer = getComponentFromProp ( this , 'footer' ) ;
193
- const title = getComponentFromProp ( this , 'title' ) ;
180
+ const footer = getComponent ( this , 'footer' ) ;
181
+ const title = getComponent ( this , 'title' ) ;
194
182
const dialogProps = {
195
- props : {
196
- ...this . $props ,
197
- getContainer : getContainer === undefined ? getContextPopupContainer : getContainer ,
198
- prefixCls,
199
- wrapClassName : classNames ( { [ `${ prefixCls } -centered` ] : ! ! centered } , wrapClassName ) ,
200
- title,
201
- footer : footer === undefined ? defaultFooter : footer ,
202
- visible,
203
- mousePosition,
204
- closeIcon : closeIconToRender ,
205
- } ,
206
- on : {
207
- ...getListeners ( this ) ,
208
- close : this . handleCancel ,
209
- } ,
210
- class : getClass ( this ) ,
211
- style : getStyle ( this ) ,
212
- attrs : $attrs ,
183
+ ...this . $props ,
184
+ ...$attrs ,
185
+ getContainer : getContainer === undefined ? getContextPopupContainer : getContainer ,
186
+ prefixCls,
187
+ wrapClassName : classNames ( { [ `${ prefixCls } -centered` ] : ! ! centered } , wrapClassName ) ,
188
+ title,
189
+ footer : footer === undefined ? defaultFooter : footer ,
190
+ visible,
191
+ mousePosition,
192
+ closeIcon : closeIconToRender ,
193
+ onClose : this . handleCancel ,
213
194
} ;
214
195
return < Dialog { ...dialogProps } > { children } </ Dialog > ;
215
196
} ,
0 commit comments