Skip to content

Commit c841d04

Browse files
committed
Merge branch 'master' of https://github.com/sudhanshutech/sistent into custom/comp
Signed-off-by: Sudhanshu Dasgupta <dasguptashivam23@gmail.com>
2 parents 6d3f093 + ea716a4 commit c841d04

1 file changed

Lines changed: 59 additions & 25 deletions

File tree

src/custom/ResponsiveDataTable.tsx

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Theme, ThemeProvider, createTheme, styled, useTheme } from '@mui/material';
1+
import { Theme, ThemeProvider, createTheme, styled } from '@mui/material';
22
import MUIDataTable from 'mui-datatables';
33
import React, { useCallback } from 'react';
4-
import { Checkbox, ListItemIcon, ListItemText, Menu, MenuItem } from '../base';
4+
import { Checkbox, Collapse, ListItemIcon, ListItemText, Menu, MenuItem } from '../base';
5+
import { ShareIcon } from '../icons';
56
import { EllipsisIcon } from '../icons/Ellipsis';
67
import TooltipIcon from './TooltipIcon';
78

@@ -18,42 +19,73 @@ export const DataTableEllipsisMenu: React.FC<{
1819
actionsList: NonNullable<Column['options']>['actionsList'];
1920
}> = ({ actionsList }) => {
2021
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
22+
const [isSocialShareOpen, setIsSocialShareOpen] = React.useState(false);
23+
2124
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
2225
setAnchorEl(event.currentTarget);
2326
};
2427
const handleClose = () => {
2528
setAnchorEl(null);
29+
setIsSocialShareOpen(false);
2630
};
2731

28-
const theme = useTheme();
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+
};
2943

3044
return (
3145
<>
3246
<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-
>
47+
<Menu id="basic-menu" anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}>
4448
{actionsList &&
4549
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>
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>
5789
))}
5890
</Menu>
5991
</>
@@ -201,6 +233,8 @@ export interface Column {
201233
icon: JSX.Element;
202234
onClick: () => void;
203235
disabled?: boolean;
236+
customComponent?: JSX.Element;
237+
type?: string;
204238
}[];
205239
};
206240
}

0 commit comments

Comments
 (0)