1- import { Theme , ThemeProvider , createTheme } from '@mui/material' ;
1+ import { Theme , ThemeProvider , createTheme , styled , useTheme } from '@mui/material' ;
22import MUIDataTable from 'mui-datatables' ;
33import React , { useCallback } from 'react' ;
4+ import { ListItemIcon , ListItemText , Menu , MenuItem } from '../base' ;
5+ import { EllipsisIcon } from '../icons/Ellipsis' ;
6+ import TooltipIcon from './TooltipIcon' ;
7+
8+ export const IconWrapper = styled ( 'div' ) < { disabled ?: boolean } > ( ( { disabled = false } ) => ( {
9+ cursor : disabled ? 'not-allowed' : 'pointer' ,
10+ opacity : disabled ? '0.5' : '1' ,
11+ display : 'flex' ,
12+ '& svg' : {
13+ cursor : disabled ? 'not-allowed' : 'pointer'
14+ }
15+ } ) ) ;
16+
17+ export const DataTableEllipsisMenu : React . FC < {
18+ actionsList : NonNullable < Column [ 'options' ] > [ 'actionsList' ] ;
19+ } > = ( { actionsList } ) => {
20+ const [ anchorEl , setAnchorEl ] = React . useState < null | HTMLElement > ( null ) ;
21+ const handleClick = ( event : React . MouseEvent < HTMLElement > ) => {
22+ setAnchorEl ( event . currentTarget ) ;
23+ } ;
24+ const handleClose = ( ) => {
25+ setAnchorEl ( null ) ;
26+ } ;
27+
28+ const theme = useTheme ( ) ;
29+
30+ return (
31+ < >
32+ < TooltipIcon title = "View Actions" onClick = { handleClick } icon = { < EllipsisIcon /> } arrow />
33+ < Menu
34+ id = "basic-menu"
35+ anchorEl = { anchorEl }
36+ open = { Boolean ( anchorEl ) }
37+ onClose = { handleClose }
38+ sx = { {
39+ ' .MuiPaper-root' : {
40+ background : theme . palette . background . surfaces
41+ }
42+ } }
43+ >
44+ { actionsList &&
45+ actionsList . map ( ( action , index ) => (
46+ < IconWrapper key = { index } disabled = { action . disabled } >
47+ < MenuItem
48+ sx = { { width : '-webkit-fill-available' } }
49+ key = { index }
50+ onClick = { action . onClick }
51+ disabled = { action . disabled }
52+ >
53+ < ListItemIcon > { action . icon } </ ListItemIcon >
54+ < ListItemText > { action . title } </ ListItemText >
55+ </ MenuItem >
56+ </ IconWrapper >
57+ ) ) }
58+ </ Menu >
59+ </ >
60+ ) ;
61+ } ;
462
563const dataTableTheme = ( theme : Theme ) =>
664 createTheme ( {
@@ -115,6 +173,15 @@ const dataTableTheme = (theme: Theme) =>
115173 }
116174 }
117175 }
176+ } ,
177+ MuiTableRow : {
178+ styleOverrides : {
179+ root : {
180+ '&.Mui-disabled' : {
181+ cursor : 'not-allowed'
182+ }
183+ }
184+ }
118185 }
119186 }
120187 } ) ;
@@ -129,6 +196,12 @@ export interface Column {
129196 display ?: boolean ;
130197 sortDescFirst ?: boolean ;
131198 customBodyRender ?: ( value : string | number | boolean | object ) => JSX . Element ;
199+ actionsList ?: {
200+ title : string ;
201+ icon : JSX . Element ;
202+ onClick : ( ) => void ;
203+ disabled ?: boolean ;
204+ } [ ] ;
132205 } ;
133206}
134207
0 commit comments