@@ -10,16 +10,28 @@ interface DropdownButtonsProps {
10
10
items : MenuProps [ 'items' ] ;
11
11
size ?: 'small' | 'middle' | 'large' ;
12
12
trigger ?: Trigger [ ] ;
13
+ showText ?: boolean ;
14
+ disabled ?: boolean ;
15
+ variant ?: 'filled' | 'outlined' ;
16
+ color ?: string ;
17
+ extra ?: React . ReactNode ;
13
18
onSelect : ( val : any , item ?: any ) => void ;
14
19
}
15
20
16
21
const DropdownButtons : React . FC < DropdownButtonsProps > = ( {
17
22
items,
18
23
size = 'middle' ,
19
24
trigger = [ 'hover' ] ,
25
+ showText,
26
+ disabled,
27
+ variant,
28
+ color,
29
+ extra,
20
30
onSelect
21
31
} ) => {
32
+ const headItem = _ . head ( items ) ;
22
33
const intl = useIntl ( ) ;
34
+
23
35
const handleMenuClick = ( item : any ) => {
24
36
const selectItem = _ . find ( items , { key : item . key } ) ;
25
37
onSelect ( item . key , selectItem ) ;
@@ -37,19 +49,20 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
37
49
return (
38
50
< >
39
51
{ items ?. length === 1 ? (
40
- < Tooltip title = { intl . formatMessage ( { id : _ . head ( items ) ?. label } ) } >
52
+ < Tooltip title = { intl . formatMessage ( { id : headItem ?. label } ) } >
41
53
< Button
42
54
className = { classNames ( 'dropdown-button' , size ) }
43
- { ..._ . head ( items ) }
44
- icon = { _ . get ( items , '0.icon' ) }
55
+ icon = { headItem ?. icon }
45
56
size = { size }
46
- { ..._ . get ( items , '0. props' ) }
57
+ { ...headItem ?. props }
47
58
onClick = { handleButtonClick }
48
59
> </ Button >
49
60
</ Tooltip >
50
61
) : (
51
62
< Dropdown . Button
63
+ disabled = { disabled }
52
64
trigger = { trigger }
65
+ type = "primary"
53
66
dropdownRender = { ( menus : any ) => {
54
67
return (
55
68
< div
@@ -67,9 +80,10 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
67
80
< Button
68
81
{ ...item . props }
69
82
type = "text"
70
- size = "middle"
83
+ size = { size }
71
84
icon = { item . icon }
72
85
key = { item . key }
86
+ disabled = { item . disabled }
73
87
onClick = { ( ) => handleMenuClick ( item ) }
74
88
style = { { width : '100%' , justifyContent : 'flex-start' } }
75
89
>
@@ -81,21 +95,45 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
81
95
) ;
82
96
} }
83
97
buttonsRender = { ( [ leftButton , rightButton ] ) => [
84
- < Tooltip
85
- title = { intl . formatMessage ( { id : _ . head ( items ) ?. label } ) }
86
- key = "leftButton"
87
- >
88
- < Button
89
- className = { classNames ( 'dropdown-button' , size ) }
90
- onClick = { handleButtonClick }
91
- size = { size }
92
- icon = { _ . head ( items ) ?. icon }
93
- > </ Button >
94
- </ Tooltip > ,
98
+ < >
99
+ { showText ? (
100
+ < Button
101
+ { ...headItem ?. props }
102
+ disabled = { headItem ?. disabled || disabled }
103
+ className = { classNames ( 'dropdown-button' , size ) }
104
+ onClick = { handleButtonClick }
105
+ size = { size }
106
+ icon = { headItem ?. icon }
107
+ variant = { variant }
108
+ color = { color }
109
+ >
110
+ { intl . formatMessage ( {
111
+ id : headItem ?. label
112
+ } ) }
113
+ { extra }
114
+ </ Button >
115
+ ) : (
116
+ < Tooltip
117
+ title = { intl . formatMessage ( { id : headItem ?. label } ) }
118
+ key = "leftButton"
119
+ >
120
+ < Button
121
+ { ...headItem ?. props }
122
+ className = { classNames ( 'dropdown-button' , size ) }
123
+ onClick = { handleButtonClick }
124
+ size = { size }
125
+ icon = { headItem ?. icon }
126
+ disabled = { headItem ?. disabled }
127
+ > </ Button >
128
+ </ Tooltip >
129
+ ) }
130
+ </ > ,
95
131
< Button
96
132
icon = { < MoreOutlined /> }
97
133
size = { size }
98
134
key = "menu"
135
+ variant = { variant }
136
+ color = "default"
99
137
className = { classNames ( 'dropdown-button' , size ) }
100
138
> </ Button >
101
139
] }
0 commit comments