6
6
PlusOutlined ,
7
7
UpOutlined ,
8
8
} from '@ant-design/icons'
9
- import { AntdIconProps } from '@ant-design/icons/lib/components/AntdIcon'
10
9
import { ArrayField } from '@formily/core'
11
10
import {
12
11
ReactFC ,
@@ -16,7 +15,7 @@ import {
16
15
useField ,
17
16
useFieldSchema ,
18
17
} from '@formily/react'
19
- import { clone , isValid } from '@formily/shared'
18
+ import { clone , isUndef , isValid } from '@formily/shared'
20
19
import { Button , ButtonProps } from 'antd'
21
20
import cls from 'classnames'
22
21
import React , { createContext , forwardRef , useContext } from 'react'
@@ -40,7 +39,7 @@ export interface IArrayBaseItemProps {
40
39
record : ( ( index : number ) => Record < string , any > ) | Record < string , any >
41
40
}
42
41
43
- type CommonProps = AntdIconProps & {
42
+ type CommonProps = ButtonProps & {
44
43
index ?: number
45
44
}
46
45
@@ -198,8 +197,7 @@ const Addition: ReactFC<IArrayBaseAdditionProps> = (props) => {
198
197
</ Button >
199
198
)
200
199
}
201
-
202
- const Copy = forwardRef < HTMLSpanElement , CommonProps > ( ( props , ref ) => {
200
+ const Copy = forwardRef < HTMLButtonElement , CommonProps > ( ( props , ref ) => {
203
201
const self = useField ( )
204
202
const array = useArray ( )
205
203
const index = useIndex ( props . index ) || 0
@@ -208,8 +206,16 @@ const Copy = forwardRef<HTMLSpanElement, CommonProps>((props, ref) => {
208
206
if ( ! array ) return null
209
207
if ( array . field ?. pattern !== 'editable' ) return null
210
208
return wrapSSR (
211
- < CopyOutlined
209
+ < Button
210
+ type = "ghost"
212
211
{ ...props }
212
+ style = { {
213
+ padding : '0 0 0 6px' ,
214
+ width : 'auto' ,
215
+ height : 'auto' ,
216
+ ...props . style ,
217
+ } }
218
+ disabled = { self ?. disabled }
213
219
className = { cls (
214
220
`${ prefixCls } -copy` ,
215
221
hashId ,
@@ -221,29 +227,42 @@ const Copy = forwardRef<HTMLSpanElement, CommonProps>((props, ref) => {
221
227
if ( self ?. disabled ) return
222
228
e . stopPropagation ( )
223
229
if ( array . props ?. disabled ) return
230
+ if ( props . onClick ) {
231
+ props . onClick ( e )
232
+ if ( e . defaultPrevented ) return
233
+ }
224
234
const value = clone ( array ?. field ?. value [ index ] )
225
235
const distIndex = index + 1
226
236
array . field ?. insert ?.( distIndex , value )
227
237
array . props ?. onCopy ?.( distIndex )
228
- if ( props . onClick ) {
229
- props . onClick ( e )
230
- }
231
238
} }
232
- />
239
+ icon = { isUndef ( props . icon ) ? < CopyOutlined /> : props . icon }
240
+ >
241
+ { props . title || self . title }
242
+ </ Button >
233
243
)
234
244
} )
235
245
236
246
const Remove = forwardRef < HTMLSpanElement , CommonProps > ( ( props , ref ) => {
237
- const index = useIndex ( props . index ) || 0
247
+ const index = useIndex ( props . index )
238
248
const self = useField ( )
239
249
const array = useArray ( )
240
250
const prefixCls = usePrefixCls ( 'formily-array-base' )
241
251
const [ wrapSSR , hashId ] = useStyle ( prefixCls )
252
+
242
253
if ( ! array ) return null
243
254
if ( array . field ?. pattern !== 'editable' ) return null
244
255
return wrapSSR (
245
- < DeleteOutlined
256
+ < Button
257
+ type = "ghost"
246
258
{ ...props }
259
+ style = { {
260
+ padding : '0 0 0 6px' ,
261
+ width : 'auto' ,
262
+ height : 'auto' ,
263
+ ...props . style ,
264
+ } }
265
+ disabled = { self ?. disabled }
247
266
className = { cls (
248
267
`${ prefixCls } -remove` ,
249
268
hashId ,
@@ -254,44 +273,58 @@ const Remove = forwardRef<HTMLSpanElement, CommonProps>((props, ref) => {
254
273
onClick = { ( e ) => {
255
274
if ( self ?. disabled ) return
256
275
e . stopPropagation ( )
257
- array . field ?. remove ?.( index )
258
- array . props ?. onRemove ?.( index )
259
276
if ( props . onClick ) {
260
277
props . onClick ( e )
278
+ if ( e . defaultPrevented ) return
261
279
}
280
+ array . field ?. remove ?.( index )
281
+ array . props ?. onRemove ?.( index )
262
282
} }
263
- />
283
+ icon = { isUndef ( props . icon ) ? < DeleteOutlined /> : props . icon }
284
+ >
285
+ { props . title || self . title }
286
+ </ Button >
264
287
)
265
288
} )
266
289
267
290
const MoveDown = forwardRef < HTMLSpanElement , CommonProps > ( ( props , ref ) => {
268
- const index = useIndex ( props . index ) || 0
291
+ const index = useIndex ( props . index )
269
292
const self = useField ( )
270
293
const array = useArray ( )
271
294
const prefixCls = usePrefixCls ( 'formily-array-base' )
272
- const [ wrapSSR , hashId ] = useStyle ( prefixCls )
273
295
if ( ! array ) return null
274
296
if ( array . field ?. pattern !== 'editable' ) return null
275
- return wrapSSR (
276
- < DownOutlined
297
+ return (
298
+ < Button
299
+ type = "ghost"
277
300
{ ...props }
301
+ style = { {
302
+ padding : '0 0 0 6px' ,
303
+ width : 'auto' ,
304
+ height : 'auto' ,
305
+ ...props . style ,
306
+ } }
307
+ disabled = { self ?. disabled }
278
308
className = { cls (
279
309
`${ prefixCls } -move-down` ,
280
- hashId ,
281
310
self ?. disabled ? `${ prefixCls } -move-down-disabled` : '' ,
282
311
props . className
283
312
) }
284
313
ref = { ref }
285
314
onClick = { ( e ) => {
286
315
if ( self ?. disabled ) return
287
316
e . stopPropagation ( )
288
- array . field ?. moveDown ?.( index )
289
- array . props ?. onMoveDown ?.( index )
290
317
if ( props . onClick ) {
291
318
props . onClick ( e )
319
+ if ( e . defaultPrevented ) return
292
320
}
321
+ array . field ?. moveDown ?.( index )
322
+ array . props ?. onMoveDown ?.( index )
293
323
} }
294
- />
324
+ icon = { isUndef ( props . icon ) ? < DownOutlined /> : props . icon }
325
+ >
326
+ { props . title || self . title }
327
+ </ Button >
295
328
)
296
329
} )
297
330
@@ -300,29 +333,39 @@ const MoveUp = forwardRef<HTMLSpanElement, CommonProps>((props, ref) => {
300
333
const self = useField ( )
301
334
const array = useArray ( )
302
335
const prefixCls = usePrefixCls ( 'formily-array-base' )
303
- const [ wrapSSR , hashId ] = useStyle ( prefixCls )
304
336
if ( ! array ) return null
305
337
if ( array . field ?. pattern !== 'editable' ) return null
306
- return wrapSSR (
307
- < UpOutlined
338
+ return (
339
+ < Button
340
+ type = "ghost"
308
341
{ ...props }
342
+ style = { {
343
+ padding : '0 0 0 6px' ,
344
+ width : 'auto' ,
345
+ height : 'auto' ,
346
+ ...props . style ,
347
+ } }
348
+ disabled = { self ?. disabled }
309
349
className = { cls (
310
350
`${ prefixCls } -move-up` ,
311
- hashId ,
312
351
self ?. disabled ? `${ prefixCls } -move-up-disabled` : '' ,
313
352
props . className
314
353
) }
315
354
ref = { ref }
316
355
onClick = { ( e ) => {
317
356
if ( self ?. disabled ) return
318
357
e . stopPropagation ( )
319
- array ?. field ?. moveUp ( index )
320
- array ?. props ?. onMoveUp ?.( index )
321
358
if ( props . onClick ) {
322
359
props . onClick ( e )
360
+ if ( e . defaultPrevented ) return
323
361
}
362
+ array ?. field ?. moveUp ( index )
363
+ array ?. props ?. onMoveUp ?.( index )
324
364
} }
325
- />
365
+ icon = { isUndef ( props . icon ) ? < UpOutlined /> : props . icon }
366
+ >
367
+ { props . title || self . title }
368
+ </ Button >
326
369
)
327
370
} )
328
371
0 commit comments