Skip to content

Commit cec1406

Browse files
authored
Merge pull request #699 from layer5io/dragon-slayer875/master
Add ellispis action menu and fix cursor styles
2 parents 09366aa + 330e3dc commit cec1406

File tree

6 files changed

+118
-5
lines changed

6 files changed

+118
-5
lines changed

src/custom/ResponsiveDataTable.tsx

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,64 @@
1-
import { Theme, ThemeProvider, createTheme } from '@mui/material';
1+
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';
5+
import { EllipsisIcon } from '../icons/Ellipsis';
6+
import TooltipIcon from './TooltipIcon';
7+
8+
export const IconWrapper = styled('div')<{ disabled?: boolean }>(({ disabled = false }) => ({
9+
cursor: disabled ? 'not-allowed' : 'pointer',
10+
opacity: disabled ? '0.5' : '1',
11+
display: 'flex',
12+
'& svg': {
13+
cursor: disabled ? 'not-allowed' : 'pointer'
14+
}
15+
}));
16+
17+
export const DataTableEllipsisMenu: React.FC<{
18+
actionsList: NonNullable<Column['options']>['actionsList'];
19+
}> = ({ actionsList }) => {
20+
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
21+
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
22+
setAnchorEl(event.currentTarget);
23+
};
24+
const handleClose = () => {
25+
setAnchorEl(null);
26+
};
27+
28+
const theme = useTheme();
29+
30+
return (
31+
<>
32+
<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+
>
44+
{actionsList &&
45+
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>
57+
))}
58+
</Menu>
59+
</>
60+
);
61+
};
462

563
const dataTableTheme = (theme: Theme) =>
664
createTheme({
@@ -115,6 +173,15 @@ const dataTableTheme = (theme: Theme) =>
115173
}
116174
}
117175
}
176+
},
177+
MuiTableRow: {
178+
styleOverrides: {
179+
root: {
180+
'&.Mui-disabled': {
181+
cursor: 'not-allowed'
182+
}
183+
}
184+
}
118185
}
119186
}
120187
});
@@ -129,6 +196,12 @@ export interface Column {
129196
display?: boolean;
130197
sortDescFirst?: boolean;
131198
customBodyRender?: (value: string | number | boolean | object) => JSX.Element;
199+
actionsList?: {
200+
title: string;
201+
icon: JSX.Element;
202+
onClick: () => void;
203+
disabled?: boolean;
204+
}[];
132205
};
133206
}
134207

src/custom/TooltipIcon.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SxProps } from '@mui/material/styles';
22
import React from 'react';
33
import { IconButton } from '../base/IconButton';
4-
import Tooltip from '../patches/Tooltip';
4+
import { CustomTooltip } from './CustomTooltip';
55

66
interface TooltipIconProps {
77
title: string;
@@ -19,7 +19,7 @@ export function TooltipIcon({
1919
arrow = false
2020
}: TooltipIconProps): JSX.Element {
2121
return (
22-
<Tooltip title={title} arrow={arrow}>
22+
<CustomTooltip title={title} arrow={arrow}>
2323
<IconButton
2424
onClick={onClick}
2525
sx={{
@@ -35,7 +35,7 @@ export function TooltipIcon({
3535
>
3636
{icon}
3737
</IconButton>
38-
</Tooltip>
38+
</CustomTooltip>
3939
);
4040
}
4141

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/icons/Ellipsis/Ellipsisicon.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { DEFAULT_HEIGHT, DEFAULT_WIDTH } from '../../constants/constants';
2+
import { IconProps } from '../types';
3+
4+
export const EllipsisIcon = ({
5+
width = DEFAULT_WIDTH,
6+
height = DEFAULT_HEIGHT,
7+
...props
8+
}: IconProps): JSX.Element => {
9+
return (
10+
<svg
11+
xmlns="http://www.w3.org/2000/svg"
12+
viewBox="0 -960 960 960"
13+
width={width}
14+
height={height}
15+
fill={props.fill || 'currentColor'}
16+
{...props}
17+
>
18+
<path d="M480-160q-33 0-56.5-23.5T400-240q0-33 23.5-56.5T480-320q33 0 56.5 23.5T560-240q0 33-23.5 56.5T480-160Zm0-240q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Zm0-240q-33 0-56.5-23.5T400-720q0-33 23.5-56.5T480-800q33 0 56.5 23.5T560-720q0 33-23.5 56.5T480-640Z" />
19+
</svg>
20+
);
21+
};
22+
23+
export default EllipsisIcon;

src/icons/Ellipsis/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as EllipsisIcon } from './Ellipsisicon';

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)