From 717dacb21b76ef25b2bb4a09df2b8add2dde3364 Mon Sep 17 00:00:00 2001 From: Sudhanshu Dasgupta Date: Sun, 4 Aug 2024 02:37:27 +0530 Subject: [PATCH 1/2] feat(action): share Signed-off-by: Sudhanshu Dasgupta --- src/custom/ResponsiveDataTable.tsx | 69 ++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/src/custom/ResponsiveDataTable.tsx b/src/custom/ResponsiveDataTable.tsx index 8b79738e..aa7b6fcd 100644 --- a/src/custom/ResponsiveDataTable.tsx +++ b/src/custom/ResponsiveDataTable.tsx @@ -1,7 +1,8 @@ import { Theme, ThemeProvider, createTheme, styled, useTheme } from '@mui/material'; import MUIDataTable from 'mui-datatables'; import React, { useCallback } from 'react'; -import { ListItemIcon, ListItemText, Menu, MenuItem } from '../base'; +import { Collapse, ListItemIcon, ListItemText, Menu, MenuItem } from '../base'; +import { ShareIcon } from '../icons'; import { EllipsisIcon } from '../icons/Ellipsis'; import TooltipIcon from './TooltipIcon'; @@ -18,14 +19,28 @@ export const DataTableEllipsisMenu: React.FC<{ actionsList: NonNullable['actionsList']; }> = ({ actionsList }) => { const [anchorEl, setAnchorEl] = React.useState(null); + const [isSocialShareOpen, setIsSocialShareOpen] = React.useState(false); + const theme = useTheme(); + const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); + setIsSocialShareOpen(false); }; - const theme = useTheme(); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const handleActionClick = (action: any) => { + if (action.type === 'share-social') { + setIsSocialShareOpen(!isSocialShareOpen); + } else { + if (action.onClick) { + action.onClick(); + } + handleClose(); + } + }; return ( <> @@ -43,17 +58,43 @@ export const DataTableEllipsisMenu: React.FC<{ > {actionsList && actionsList.map((action, index) => ( - - - {action.icon} - {action.title} - - + + {action.type === 'share-social' ? ( + <> + handleActionClick(action)} + disabled={action.disabled} + > + + + + {action.title} + + {action.customComponent} + + ) : ( + <> + + handleActionClick(action)} + disabled={action.disabled} + > + {action.icon} + {action.title} + + + + )} + ))} @@ -201,6 +242,8 @@ export interface Column { icon: JSX.Element; onClick: () => void; disabled?: boolean; + customComponent?: JSX.Element; + type?: string; }[]; }; } From a966aa800037d4f76c29c72919fdbafd3d2c2f6b Mon Sep 17 00:00:00 2001 From: Sudhanshu Dasgupta Date: Sun, 4 Aug 2024 03:36:17 +0530 Subject: [PATCH 2/2] fix(styles): remove Signed-off-by: Sudhanshu Dasgupta --- src/custom/ResponsiveDataTable.tsx | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/custom/ResponsiveDataTable.tsx b/src/custom/ResponsiveDataTable.tsx index aa7b6fcd..b9d8bdd7 100644 --- a/src/custom/ResponsiveDataTable.tsx +++ b/src/custom/ResponsiveDataTable.tsx @@ -1,4 +1,4 @@ -import { Theme, ThemeProvider, createTheme, styled, useTheme } from '@mui/material'; +import { Theme, ThemeProvider, createTheme, styled } from '@mui/material'; import MUIDataTable from 'mui-datatables'; import React, { useCallback } from 'react'; import { Collapse, ListItemIcon, ListItemText, Menu, MenuItem } from '../base'; @@ -20,7 +20,6 @@ export const DataTableEllipsisMenu: React.FC<{ }> = ({ actionsList }) => { const [anchorEl, setAnchorEl] = React.useState(null); const [isSocialShareOpen, setIsSocialShareOpen] = React.useState(false); - const theme = useTheme(); const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); @@ -45,17 +44,7 @@ export const DataTableEllipsisMenu: React.FC<{ return ( <> } arrow /> - + {actionsList && actionsList.map((action, index) => ( @@ -63,8 +52,8 @@ export const DataTableEllipsisMenu: React.FC<{ <> handleActionClick(action)} disabled={action.disabled} @@ -74,15 +63,17 @@ export const DataTableEllipsisMenu: React.FC<{ {action.title} - {action.customComponent} + + {action.customComponent} + ) : ( <> handleActionClick(action)}