-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom components to
CrudMoreActionsMenu
(#3275)
Co-authored-by: Ricky James Smith <[email protected]>
- Loading branch information
1 parent
5c06e4b
commit b918c81
Showing
4 changed files
with
141 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
"@comet/admin": minor | ||
--- | ||
|
||
Add support for custom components to `CrudMoreActionsMenu` | ||
|
||
**Example** | ||
|
||
```tsx | ||
const CustomAction = () => ( | ||
<CrudMoreActionsMenuItem | ||
onClick={() => { | ||
// Perform action | ||
}} | ||
> | ||
<ListItemIcon> | ||
<Favorite /> | ||
</ListItemIcon> | ||
Custom Action | ||
</CrudMoreActionsMenuItem> | ||
); | ||
|
||
<CrudMoreActionsMenu overallActions={[<CustomAction key="custom-action" />]} />; | ||
``` | ||
|
||
**Note:** Use the `CrudMoreActionsMenuItem` component or `CrudMoreActionsMenuContext` to close the menu after clicking an item. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
storybook/src/admin/data-grid/CrudMoreActionsMenu.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { CrudMoreActionsMenu, CrudMoreActionsMenuItem } from "@comet/admin"; | ||
import { Delete, Download, Excel, Favorite, Move } from "@comet/admin-icons"; | ||
import { ListItemIcon } from "@mui/material"; | ||
|
||
export default { | ||
title: "@comet/admin/data-grid/CrudMoreActionsMenu", | ||
}; | ||
|
||
export const Basic = () => { | ||
return ( | ||
<CrudMoreActionsMenu | ||
selectionSize={2} | ||
overallActions={[ | ||
{ | ||
label: "Export to Excel", | ||
onClick: () => {}, | ||
icon: <Excel />, | ||
}, | ||
]} | ||
selectiveActions={[ | ||
{ | ||
label: "Move", | ||
onClick: () => {}, | ||
icon: <Move />, | ||
}, | ||
{ | ||
label: "Delete", | ||
onClick: () => {}, | ||
icon: <Delete />, | ||
divider: true, | ||
}, | ||
{ | ||
label: "Download", | ||
onClick: () => {}, | ||
icon: <Download />, | ||
}, | ||
]} | ||
/> | ||
); | ||
}; | ||
|
||
export const CustomComponent = () => { | ||
const CustomAction = () => { | ||
return ( | ||
<CrudMoreActionsMenuItem | ||
onClick={() => { | ||
window.alert("Hello from custom action"); | ||
}} | ||
> | ||
<ListItemIcon | ||
// TODO Remove once https://github.com/vivid-planet/comet/pull/2919 has been merged into main | ||
sx={{ minWidth: "unset !important" }} | ||
> | ||
<Favorite /> | ||
</ListItemIcon> | ||
Custom Action | ||
</CrudMoreActionsMenuItem> | ||
); | ||
}; | ||
|
||
return ( | ||
<CrudMoreActionsMenu | ||
overallActions={[ | ||
{ | ||
label: "Export to Excel", | ||
onClick: () => {}, | ||
icon: <Excel />, | ||
}, | ||
<CustomAction key="custom-action" />, | ||
]} | ||
/> | ||
); | ||
}; |