3
3
Button ,
4
4
ButtonGroup ,
5
5
ClickAwayListener ,
6
+ Divider ,
6
7
MenuItem ,
7
8
MenuList ,
8
9
Paper ,
@@ -13,16 +14,20 @@ interface Option {
13
14
icon : React . ReactNode ;
14
15
label : string ;
15
16
onClick : ( event : React . MouseEvent < HTMLLIElement , MouseEvent > , index : number ) => void ;
17
+ isDivider ?: boolean ;
18
+ show ?: boolean ;
16
19
}
17
20
18
21
interface ActionButtonProps {
19
22
defaultActionClick : ( ) => void ;
23
+ defaultActionDisabled ?: boolean ;
20
24
options : Option [ ] ;
21
25
label : string ;
22
26
}
23
27
24
28
export default function ActionButton ( {
25
29
defaultActionClick,
30
+ defaultActionDisabled = false ,
26
31
options,
27
32
label
28
33
} : ActionButtonProps ) : JSX . Element {
@@ -50,7 +55,7 @@ export default function ActionButton({
50
55
style = { { boxShadow : 'none' } }
51
56
aria-label = "Button group with a nested menu"
52
57
>
53
- < Button onClick = { defaultActionClick } variant = "contained" >
58
+ < Button onClick = { defaultActionClick } variant = "contained" disabled = { defaultActionDisabled } >
54
59
{ label }
55
60
</ Button >
56
61
< Button size = "small" onClick = { handleToggle } variant = "contained" >
@@ -68,18 +73,24 @@ export default function ActionButton({
68
73
< Paper >
69
74
< ClickAwayListener onClickAway = { handleClose } >
70
75
< MenuList id = "split-button-menu" autoFocusItem >
71
- { options . map ( ( option , index ) => (
72
- < MenuItem
73
- key = { index }
74
- onClick = { ( event ) => {
75
- handleMenuItemClick ( ) ;
76
- option . onClick ( event , index ) ;
77
- } }
78
- >
79
- < div style = { { marginRight : '1rem' } } > { option . icon } </ div >
80
- { option . label }
81
- </ MenuItem >
82
- ) ) }
76
+ { options
77
+ . filter ( ( option ) => option ?. show !== false )
78
+ . map ( ( option , index ) =>
79
+ option . isDivider ? (
80
+ < Divider />
81
+ ) : (
82
+ < MenuItem
83
+ key = { index }
84
+ onClick = { ( event ) => {
85
+ handleMenuItemClick ( ) ;
86
+ option . onClick ( event , index ) ;
87
+ } }
88
+ >
89
+ < div style = { { marginRight : '1rem' } } > { option . icon } </ div >
90
+ { option . label }
91
+ </ MenuItem >
92
+ )
93
+ ) }
83
94
</ MenuList >
84
95
</ ClickAwayListener >
85
96
</ Paper >
0 commit comments