1- import { Theme , ThemeProvider , createTheme } from '@mui/material' ;
1+ import { Theme , ThemeProvider , createTheme , styled } from '@mui/material' ;
22import MUIDataTable from 'mui-datatables' ;
33import React , { useCallback } from 'react' ;
4+ import { Checkbox , Collapse , ListItemIcon , ListItemText , Menu , MenuItem } from '../base' ;
5+ import { ShareIcon } from '../icons' ;
6+ import { EllipsisIcon } from '../icons/Ellipsis' ;
7+ import TooltipIcon from './TooltipIcon' ;
8+
9+ export const IconWrapper = styled ( 'div' ) < { disabled ?: boolean } > ( ( { disabled = false } ) => ( {
10+ cursor : disabled ? 'not-allowed' : 'pointer' ,
11+ opacity : disabled ? '0.5' : '1' ,
12+ display : 'flex' ,
13+ '& svg' : {
14+ cursor : disabled ? 'not-allowed' : 'pointer'
15+ }
16+ } ) ) ;
17+
18+ export const DataTableEllipsisMenu : React . FC < {
19+ actionsList : NonNullable < Column [ 'options' ] > [ 'actionsList' ] ;
20+ } > = ( { actionsList } ) => {
21+ const [ anchorEl , setAnchorEl ] = React . useState < null | HTMLElement > ( null ) ;
22+ const [ isSocialShareOpen , setIsSocialShareOpen ] = React . useState ( false ) ;
23+
24+ const handleClick = ( event : React . MouseEvent < HTMLElement > ) => {
25+ setAnchorEl ( event . currentTarget ) ;
26+ } ;
27+ const handleClose = ( ) => {
28+ setAnchorEl ( null ) ;
29+ setIsSocialShareOpen ( false ) ;
30+ } ;
31+
32+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33+ const handleActionClick = ( action : any ) => {
34+ if ( action . type === 'share-social' ) {
35+ setIsSocialShareOpen ( ! isSocialShareOpen ) ;
36+ } else {
37+ if ( action . onClick ) {
38+ action . onClick ( ) ;
39+ }
40+ handleClose ( ) ;
41+ }
42+ } ;
43+
44+ return (
45+ < >
46+ < TooltipIcon title = "View Actions" onClick = { handleClick } icon = { < EllipsisIcon /> } arrow />
47+ < Menu id = "basic-menu" anchorEl = { anchorEl } open = { Boolean ( anchorEl ) } onClose = { handleClose } >
48+ { actionsList &&
49+ actionsList . map ( ( action , index ) => (
50+ < React . Fragment key = { index } >
51+ { action . type === 'share-social' ? (
52+ < >
53+ < MenuItem
54+ sx = { {
55+ width : '-webkit-fill-available'
56+ // background: theme.palette.background.surfaces
57+ } }
58+ onClick = { ( ) => handleActionClick ( action ) }
59+ disabled = { action . disabled }
60+ >
61+ < ListItemIcon >
62+ < ShareIcon width = { 24 } height = { 24 } />
63+ </ ListItemIcon >
64+ < ListItemText > { action . title } </ ListItemText >
65+ </ MenuItem >
66+ < Collapse variant = "submenu" in = { isSocialShareOpen } unmountOnExit >
67+ { action . customComponent }
68+ </ Collapse >
69+ </ >
70+ ) : (
71+ < >
72+ < IconWrapper key = { index } disabled = { action . disabled } >
73+ < MenuItem
74+ sx = { {
75+ width : '-webkit-fill-available'
76+ // background: theme.palette.background.surfaces
77+ } }
78+ key = { index }
79+ onClick = { ( ) => handleActionClick ( action ) }
80+ disabled = { action . disabled }
81+ >
82+ < ListItemIcon > { action . icon } </ ListItemIcon >
83+ < ListItemText > { action . title } </ ListItemText >
84+ </ MenuItem >
85+ </ IconWrapper >
86+ </ >
87+ ) }
88+ </ React . Fragment >
89+ ) ) }
90+ </ Menu >
91+ </ >
92+ ) ;
93+ } ;
494
595const dataTableTheme = ( theme : Theme ) =>
696 createTheme ( {
@@ -115,6 +205,15 @@ const dataTableTheme = (theme: Theme) =>
115205 }
116206 }
117207 }
208+ } ,
209+ MuiTableRow : {
210+ styleOverrides : {
211+ root : {
212+ '&.Mui-disabled' : {
213+ cursor : 'not-allowed'
214+ }
215+ }
216+ }
118217 }
119218 }
120219 } ) ;
@@ -129,6 +228,14 @@ export interface Column {
129228 display ?: boolean ;
130229 sortDescFirst ?: boolean ;
131230 customBodyRender ?: ( value : string | number | boolean | object ) => JSX . Element ;
231+ actionsList ?: {
232+ title : string ;
233+ icon : JSX . Element ;
234+ onClick : ( ) => void ;
235+ disabled ?: boolean ;
236+ customComponent ?: JSX . Element ;
237+ type ?: string ;
238+ } [ ] ;
132239 } ;
133240}
134241
@@ -167,6 +274,11 @@ const ResponsiveDataTable = ({
167274
168275 const updatedOptions = {
169276 ...options ,
277+ print : false ,
278+ download : false ,
279+ search : false ,
280+ filter : false ,
281+ viewColumns : false ,
170282 rowsPerPageOptions : rowsPerPageOptions ,
171283 onViewColumnsChange : ( column : string , action : string ) => {
172284 switch ( action ) {
@@ -244,7 +356,8 @@ const ResponsiveDataTable = ({
244356 } , [ updateColumnsEffect ] ) ;
245357
246358 const components = {
247- ExpandButton : ( ) => ''
359+ ExpandButton : ( ) => '' ,
360+ Checkbox : Checkbox
248361 } ;
249362
250363 return (
0 commit comments