1
1
import type { ExtractPropTypes , HTMLAttributes , PropType } from 'vue' ;
2
- import { computed , onMounted , ref , toRef , defineComponent } from 'vue' ;
3
- import Tooltip from '../tooltip ' ;
2
+ import { computed , ref , toRef , defineComponent } from 'vue' ;
3
+ import Popover from '../popover ' ;
4
4
import abstractTooltipProps from '../tooltip/abstractTooltipProps' ;
5
- import PropTypes from '../_util/vue-types' ;
6
5
import { initDefaultProps } from '../_util/props-util' ;
7
6
import type { ButtonProps , LegacyButtonType } from '../button/buttonTypes' ;
8
7
import { convertLegacyProps } from '../button/buttonTypes' ;
9
8
import ExclamationCircleFilled from '@ant-design/icons-vue/ExclamationCircleFilled' ;
10
9
import Button from '../button' ;
11
10
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver' ;
12
11
import defaultLocale from '../locale/en_US' ;
13
- import { withInstall } from '../_util/type' ;
12
+ import { anyType , objectType , stringType , withInstall } from '../_util/type' ;
14
13
import useMergedState from '../_util/hooks/useMergedState' ;
15
- import devWarning from '../vc-util/devWarning' ;
14
+
16
15
import KeyCode from '../_util/KeyCode' ;
17
16
import useConfigInject from '../config-provider/hooks/useConfigInject' ;
18
17
import classNames from '../_util/classNames' ;
@@ -21,28 +20,21 @@ import { cloneVNodes } from '../_util/vnode';
21
20
import omit from '../_util/omit' ;
22
21
import { tooltipDefaultProps } from '../tooltip/Tooltip' ;
23
22
import ActionButton from '../_util/ActionButton' ;
23
+ import usePopconfirmStyle from './style' ;
24
24
25
25
export const popconfirmProps = ( ) => ( {
26
26
...abstractTooltipProps ( ) ,
27
27
prefixCls : String ,
28
- content : PropTypes . any ,
29
- title : PropTypes . any ,
30
- okType : {
31
- type : String as PropType < LegacyButtonType > ,
32
- default : 'primary' ,
33
- } ,
28
+ content : anyType ( ) ,
29
+ title : anyType < string | number > ( ) ,
30
+ description : anyType < string | number > ( ) ,
31
+ okType : stringType < LegacyButtonType > ( 'primary' ) ,
34
32
disabled : { type : Boolean , default : false } ,
35
- okText : PropTypes . any ,
36
- cancelText : PropTypes . any ,
37
- icon : PropTypes . any ,
38
- okButtonProps : {
39
- type : Object as PropType < ButtonProps & HTMLAttributes > ,
40
- default : undefined as ButtonProps & HTMLAttributes ,
41
- } ,
42
- cancelButtonProps : {
43
- type : Object as PropType < ButtonProps & HTMLAttributes > ,
44
- default : undefined as ButtonProps & HTMLAttributes ,
45
- } ,
33
+ okText : anyType ( ) ,
34
+ cancelText : anyType ( ) ,
35
+ icon : anyType ( ) ,
36
+ okButtonProps : objectType < ButtonProps & HTMLAttributes > ( ) ,
37
+ cancelButtonProps : objectType < ButtonProps & HTMLAttributes > ( ) ,
46
38
showCancel : { type : Boolean , default : true } ,
47
39
onConfirm : Function as PropType < ( e : MouseEvent ) => void > ,
48
40
onCancel : Function as PropType < ( e : MouseEvent ) => void > ,
@@ -58,6 +50,7 @@ export interface PopconfirmLocale {
58
50
const Popconfirm = defineComponent ( {
59
51
compatConfig : { MODE : 3 } ,
60
52
name : 'APopconfirm' ,
53
+ inheritAttrs : false ,
61
54
props : initDefaultProps ( popconfirmProps ( ) , {
62
55
...tooltipDefaultProps ( ) ,
63
56
trigger : 'click' ,
@@ -71,75 +64,68 @@ const Popconfirm = defineComponent({
71
64
disabled : false ,
72
65
} ) ,
73
66
slots : [ 'title' , 'content' , 'okText' , 'icon' , 'cancelText' , 'cancelButton' , 'okButton' ] ,
74
- emits : [ 'update:visible' , 'visibleChange' ] ,
75
- setup ( props : PopconfirmProps , { slots, emit, expose } ) {
76
- onMounted ( ( ) => {
77
- devWarning (
78
- props . defaultVisible === undefined ,
79
- 'Popconfirm' ,
80
- `'defaultVisible' is deprecated, please use 'v-model:visible'` ,
81
- ) ;
82
- } ) ;
83
- const tooltipRef = ref ( ) ;
67
+ // emits: ['update:open', 'visibleChange'],
68
+ setup ( props : PopconfirmProps , { slots, emit, expose, attrs } ) {
69
+ const rootRef = ref ( ) ;
84
70
expose ( {
85
71
getPopupDomNode : ( ) => {
86
- return tooltipRef . value ?. getPopupDomNode ?.( ) ;
72
+ return rootRef . value ?. getPopupDomNode ?.( ) ;
87
73
} ,
88
74
} ) ;
89
- const [ visible , setVisible ] = useMergedState ( false , {
90
- value : toRef ( props , 'visible' ) ,
91
- defaultValue : props . defaultVisible ,
75
+ const [ open , setOpen ] = useMergedState ( false , {
76
+ value : toRef ( props , 'open' ) ,
92
77
} ) ;
93
78
94
- const settingVisible = ( value : boolean , e ?: MouseEvent | KeyboardEvent ) => {
95
- if ( props . visible === undefined ) {
96
- setVisible ( value ) ;
79
+ const settingOpen = ( value : boolean , e ?: MouseEvent | KeyboardEvent ) => {
80
+ if ( props . open === undefined ) {
81
+ setOpen ( value ) ;
97
82
}
98
83
99
- emit ( 'update:visible ' , value ) ;
100
- emit ( 'visibleChange ' , value , e ) ;
84
+ emit ( 'update:open ' , value ) ;
85
+ emit ( 'openChange ' , value , e ) ;
101
86
} ;
102
87
103
88
const close = ( e : MouseEvent ) => {
104
- settingVisible ( false , e ) ;
89
+ settingOpen ( false , e ) ;
105
90
} ;
106
91
107
92
const onConfirm = ( e : MouseEvent ) => {
108
93
return props . onConfirm ?.( e ) ;
109
94
} ;
110
95
111
96
const onCancel = ( e : MouseEvent ) => {
112
- settingVisible ( false , e ) ;
97
+ settingOpen ( false , e ) ;
113
98
props . onCancel ?.( e ) ;
114
99
} ;
115
100
116
101
const onKeyDown = ( e : KeyboardEvent ) => {
117
- if ( e . keyCode === KeyCode . ESC && visible ) {
118
- settingVisible ( false , e ) ;
102
+ if ( e . keyCode === KeyCode . ESC && open ) {
103
+ settingOpen ( false , e ) ;
119
104
}
120
105
} ;
121
106
122
- const onVisibleChange = ( value : boolean ) => {
107
+ const onOpenChange = ( value : boolean ) => {
123
108
const { disabled } = props ;
124
109
if ( disabled ) {
125
110
return ;
126
111
}
127
- settingVisible ( value ) ;
112
+ settingOpen ( value ) ;
128
113
} ;
129
114
const { prefixCls : prefixClsConfirm , getPrefixCls } = useConfigInject ( 'popconfirm' , props ) ;
130
115
const rootPrefixCls = computed ( ( ) => getPrefixCls ( ) ) ;
131
- const popoverPrefixCls = computed ( ( ) => getPrefixCls ( 'popover' ) ) ;
132
116
const btnPrefixCls = computed ( ( ) => getPrefixCls ( 'btn' ) ) ;
117
+ const [ wrapSSR ] = usePopconfirmStyle ( prefixClsConfirm ) ;
133
118
const [ popconfirmLocale ] = useLocaleReceiver ( 'Popconfirm' , defaultLocale . Popconfirm ) ;
134
119
const renderOverlay = ( ) => {
135
120
const {
136
121
okButtonProps,
137
122
cancelButtonProps,
138
123
title = slots . title ?.( ) ,
124
+ description = slots . description ?.( ) ,
139
125
cancelText = slots . cancel ?.( ) ,
140
126
okText = slots . okText ?.( ) ,
141
127
okType,
142
- icon = slots . icon ?.( ) ,
128
+ icon = slots . icon ?.( ) || < ExclamationCircleFilled /> ,
143
129
showCancel = true ,
144
130
} = props ;
145
131
const { cancelButton, okButton } = slots ;
@@ -155,12 +141,20 @@ const Popconfirm = defineComponent({
155
141
...okButtonProps ,
156
142
} ;
157
143
return (
158
- < div class = { `${ popoverPrefixCls . value } -inner-content` } >
159
- < div class = { `${ popoverPrefixCls . value } -message` } >
160
- { icon || < ExclamationCircleFilled /> }
161
- < div class = { `${ popoverPrefixCls . value } -message-title` } > { title } </ div >
144
+ < div class = { `${ prefixClsConfirm . value } -inner-content` } >
145
+ < div class = { `${ prefixClsConfirm . value } -message` } >
146
+ { icon && < span class = { `${ prefixClsConfirm . value } -message-icon` } > { icon } </ span > }
147
+ < div
148
+ class = { [
149
+ `${ prefixClsConfirm . value } -message-title` ,
150
+ { [ `${ prefixClsConfirm . value } -message-title-only` ] : ! ! description } ,
151
+ ] }
152
+ >
153
+ { title }
154
+ </ div >
162
155
</ div >
163
- < div class = { `${ popoverPrefixCls . value } -buttons` } >
156
+ { description && < div class = { `${ prefixClsConfirm . value } -description` } > { description } </ div > }
157
+ < div class = { `${ prefixClsConfirm . value } -buttons` } >
164
158
{ showCancel ? (
165
159
cancelButton ? (
166
160
cancelButton ( cancelProps )
@@ -188,28 +182,31 @@ const Popconfirm = defineComponent({
188
182
} ;
189
183
190
184
return ( ) => {
191
- const { placement, overlayClassName, ...restProps } = props ;
185
+ const { placement, overlayClassName, trigger = 'click' , ...restProps } = props ;
192
186
const otherProps = omit ( restProps , [
193
187
'title' ,
194
188
'content' ,
195
189
'cancelText' ,
196
190
'okText' ,
197
- 'onUpdate:visible ' ,
191
+ 'onUpdate:open ' ,
198
192
'onConfirm' ,
199
193
'onCancel' ,
194
+ 'prefixCls' ,
200
195
] ) ;
201
196
const overlayClassNames = classNames ( prefixClsConfirm . value , overlayClassName ) ;
202
- return (
203
- < Tooltip
197
+ return wrapSSR (
198
+ < Popover
204
199
{ ...otherProps }
205
- prefixCls = { popoverPrefixCls . value }
200
+ { ...attrs }
201
+ trigger = { trigger }
206
202
placement = { placement }
207
- onVisibleChange = { onVisibleChange }
208
- visible = { visible . value }
203
+ onOpenChange = { onOpenChange }
204
+ open = { open . value }
209
205
overlayClassName = { overlayClassNames }
210
206
transitionName = { getTransitionName ( rootPrefixCls . value , 'zoom-big' , props . transitionName ) }
211
- v-slots = { { title : renderOverlay } }
212
- ref = { tooltipRef }
207
+ v-slots = { { content : renderOverlay } }
208
+ ref = { rootRef }
209
+ data-popover-inject
213
210
>
214
211
{ cloneVNodes (
215
212
slots . default ?.( ) || [ ] ,
@@ -220,7 +217,7 @@ const Popconfirm = defineComponent({
220
217
} ,
221
218
false ,
222
219
) }
223
- </ Tooltip >
220
+ </ Popover > ,
224
221
) ;
225
222
} ;
226
223
} ,
0 commit comments