Skip to content

Commit a0284a6

Browse files
committed
fix(action): columns
Signed-off-by: Sudhanshu Dasgupta <dasguptashivam23@gmail.com>
1 parent 2898032 commit a0284a6

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

src/custom/ResponsiveDataTable.tsx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
import { Theme, ThemeProvider, createTheme } from '@mui/material';
1+
import { Theme, ThemeProvider, createTheme, styled } from '@mui/material';
22
import MUIDataTable from 'mui-datatables';
33
import React, { useCallback } from 'react';
44
import { IconButton, Menu, MenuItem } from '../base';
55
import { DropDownIcon } from '../icons';
66

7-
const DataTableEllipsisMenu: React.FC<{
7+
export const IconWrapper = styled('div')<{ disabled?: boolean }>(({ disabled = false }) => ({
8+
cursor: disabled ? 'not-allowed' : 'pointer',
9+
opacity: disabled ? '0.5' : '1',
10+
display: 'flex',
11+
'& svg': {
12+
cursor: disabled ? 'not-allowed' : 'pointer'
13+
}
14+
}));
15+
16+
const CustomMenuItem = styled(MenuItem)(() => ({
17+
paddingLeft: '0px',
18+
padding: '10px'
19+
}));
20+
21+
export const DataTableEllipsisMenu: React.FC<{
822
actionsList: NonNullable<Column['options']>['actionsList'];
923
}> = ({ actionsList }) => {
1024
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
@@ -14,6 +28,7 @@ const DataTableEllipsisMenu: React.FC<{
1428
const handleClose = () => {
1529
setAnchorEl(null);
1630
};
31+
1732
return (
1833
<>
1934
<IconButton onClick={handleClick}>
@@ -25,17 +40,18 @@ const DataTableEllipsisMenu: React.FC<{
2540
onClose={handleClose}
2641
PaperProps={{
2742
style: {
28-
maxHeight: 48 * 4.5,
29-
width: '20ch'
43+
maxHeight: 48 * 4.5
3044
}
3145
}}
3246
>
3347
{actionsList &&
3448
actionsList.map((action, index) => (
35-
<MenuItem key={index} onClick={action.onClick} disabled={action.disabled}>
36-
{action.icon}
37-
{action.title}
38-
</MenuItem>
49+
<IconWrapper key={index} disabled={action.disabled}>
50+
<CustomMenuItem key={index} onClick={action.onClick} disabled={action.disabled}>
51+
{action.icon}
52+
{action.title}
53+
</CustomMenuItem>
54+
</IconWrapper>
3955
))}
4056
</Menu>
4157
</>
@@ -211,16 +227,6 @@ const ResponsiveDataTable = ({
211227
return new Intl.DateTimeFormat('un-US', dateOptions).format(date);
212228
};
213229

214-
columns.forEach((col) => {
215-
console.log('col', col);
216-
if (col.options?.actionsList) {
217-
console.log('col.options.actionsList', col.options.actionsList);
218-
col.options.customBodyRender = function CustomBody() {
219-
return <DataTableEllipsisMenu actionsList={col.options?.actionsList} />;
220-
};
221-
}
222-
});
223-
224230
const updatedOptions = {
225231
...options,
226232
print: false,

src/custom/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import { LearningCard } from './LearningCard';
3333
import { RenderMarkdown } from './Markdown';
3434
import { ModalCard } from './ModalCard';
3535
import PopperListener, { IPopperListener } from './PopperListener';
36-
import ResponsiveDataTable, { ResponsiveDataTableProps } from './ResponsiveDataTable';
36+
import ResponsiveDataTable, {
37+
DataTableEllipsisMenu,
38+
ResponsiveDataTableProps
39+
} from './ResponsiveDataTable';
3740
import SearchBar, { SearchBarProps } from './SearchBar';
3841
import { TransferList } from './TransferModal/TransferList';
3942
import { TransferListProps } from './TransferModal/TransferList/TransferList';
@@ -58,6 +61,7 @@ export {
5861
CustomDialog,
5962
CustomImage,
6063
CustomTooltip,
64+
DataTableEllipsisMenu,
6165
EmptyState,
6266
ErrorBoundary,
6367
Fallback,

src/theme/components/iconbutton.modifier.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ export const MuiIconButton: Components<Theme>['MuiIconButton'] = {
55
root: {
66
'@media (max-width: 400px)': {
77
padding: '2px'
8+
},
9+
'&.Mui-disabled': {
10+
'&:hover': {
11+
cursor: 'not-allowed'
12+
}
13+
},
14+
'& .MuiSvgIcon-root': {
15+
'&.Mui-disabled': {
16+
'&:hover': {
17+
cursor: 'not-allowed'
18+
}
19+
}
820
}
921
}
1022
}

0 commit comments

Comments
 (0)