Skip to content

Commit 96a18bb

Browse files
authored
Merge pull request #667 from dottharun/fix/action-button
ench: ActionButton for new designs
2 parents 369d3ea + 35b0e9e commit 96a18bb

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/custom/ActionButton/ActionButton.tsx

+24-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Button,
44
ButtonGroup,
55
ClickAwayListener,
6+
Divider,
67
MenuItem,
78
MenuList,
89
Paper,
@@ -13,16 +14,20 @@ interface Option {
1314
icon: React.ReactNode;
1415
label: string;
1516
onClick: (event: React.MouseEvent<HTMLLIElement, MouseEvent>, index: number) => void;
17+
isDivider?: boolean;
18+
show?: boolean;
1619
}
1720

1821
interface ActionButtonProps {
1922
defaultActionClick: () => void;
23+
defaultActionDisabled?: boolean;
2024
options: Option[];
2125
label: string;
2226
}
2327

2428
export default function ActionButton({
2529
defaultActionClick,
30+
defaultActionDisabled = false,
2631
options,
2732
label
2833
}: ActionButtonProps): JSX.Element {
@@ -50,7 +55,7 @@ export default function ActionButton({
5055
style={{ boxShadow: 'none' }}
5156
aria-label="Button group with a nested menu"
5257
>
53-
<Button onClick={defaultActionClick} variant="contained">
58+
<Button onClick={defaultActionClick} variant="contained" disabled={defaultActionDisabled}>
5459
{label}
5560
</Button>
5661
<Button size="small" onClick={handleToggle} variant="contained">
@@ -68,18 +73,24 @@ export default function ActionButton({
6873
<Paper>
6974
<ClickAwayListener onClickAway={handleClose}>
7075
<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+
)}
8394
</MenuList>
8495
</ClickAwayListener>
8596
</Paper>

0 commit comments

Comments
 (0)