Skip to content

Commit 717dacb

Browse files
committed
feat(action): share
Signed-off-by: Sudhanshu Dasgupta <dasguptashivam23@gmail.com>
1 parent cec1406 commit 717dacb

1 file changed

Lines changed: 56 additions & 13 deletions

File tree

src/custom/ResponsiveDataTable.tsx

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Theme, ThemeProvider, createTheme, styled, useTheme } from '@mui/material';
22
import MUIDataTable from 'mui-datatables';
33
import React, { useCallback } from 'react';
4-
import { ListItemIcon, ListItemText, Menu, MenuItem } from '../base';
4+
import { 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,14 +19,28 @@ 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+
const theme = useTheme();
24+
2125
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
2226
setAnchorEl(event.currentTarget);
2327
};
2428
const handleClose = () => {
2529
setAnchorEl(null);
30+
setIsSocialShareOpen(false);
2631
};
2732

28-
const theme = useTheme();
33+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34+
const handleActionClick = (action: any) => {
35+
if (action.type === 'share-social') {
36+
setIsSocialShareOpen(!isSocialShareOpen);
37+
} else {
38+
if (action.onClick) {
39+
action.onClick();
40+
}
41+
handleClose();
42+
}
43+
};
2944

3045
return (
3146
<>
@@ -43,17 +58,43 @@ export const DataTableEllipsisMenu: React.FC<{
4358
>
4459
{actionsList &&
4560
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>
61+
<React.Fragment key={index}>
62+
{action.type === 'share-social' ? (
63+
<>
64+
<MenuItem
65+
sx={{
66+
width: '-webkit-fill-available',
67+
background: theme.palette.background.surfaces
68+
}}
69+
onClick={() => handleActionClick(action)}
70+
disabled={action.disabled}
71+
>
72+
<ListItemIcon>
73+
<ShareIcon width={24} height={24} />
74+
</ListItemIcon>
75+
<ListItemText>{action.title}</ListItemText>
76+
</MenuItem>
77+
<Collapse in={isSocialShareOpen}>{action.customComponent}</Collapse>
78+
</>
79+
) : (
80+
<>
81+
<IconWrapper key={index} disabled={action.disabled}>
82+
<MenuItem
83+
sx={{
84+
width: '-webkit-fill-available',
85+
background: theme.palette.background.surfaces
86+
}}
87+
key={index}
88+
onClick={() => handleActionClick(action)}
89+
disabled={action.disabled}
90+
>
91+
<ListItemIcon>{action.icon}</ListItemIcon>
92+
<ListItemText>{action.title}</ListItemText>
93+
</MenuItem>
94+
</IconWrapper>
95+
</>
96+
)}
97+
</React.Fragment>
5798
))}
5899
</Menu>
59100
</>
@@ -201,6 +242,8 @@ export interface Column {
201242
icon: JSX.Element;
202243
onClick: () => void;
203244
disabled?: boolean;
245+
customComponent?: JSX.Element;
246+
type?: string;
204247
}[];
205248
};
206249
}

0 commit comments

Comments
 (0)