ente/packages/shared/components/OverflowMenu/option.tsx

65 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-06-26 09:54:46 +00:00
import { MenuItem, ButtonProps, Typography, Box } from '@mui/material';
2023-11-09 08:34:18 +00:00
import { FluidContainer } from '@ente/shared/components/Container';
import { OverflowMenuContext } from './context';
2022-06-27 01:08:37 +00:00
import React, { useContext } from 'react';
2022-06-21 08:22:31 +00:00
interface Iprops {
2022-06-21 09:04:24 +00:00
onClick: () => void;
color?: ButtonProps['color'];
startIcon?: React.ReactNode;
2022-06-26 09:54:46 +00:00
endIcon?: React.ReactNode;
2022-06-27 01:08:37 +00:00
keepOpenAfterClick?: boolean;
2022-06-21 09:13:52 +00:00
children?: any;
2022-06-21 08:22:31 +00:00
}
export function OverflowMenuOption({
2022-06-21 09:04:24 +00:00
onClick,
color = 'primary',
2022-06-21 08:22:31 +00:00
startIcon,
2022-06-26 09:54:46 +00:00
endIcon,
2022-06-27 01:08:37 +00:00
keepOpenAfterClick,
2022-06-21 09:13:52 +00:00
children,
2022-06-21 08:22:31 +00:00
}: Iprops) {
2022-06-27 01:08:37 +00:00
const menuContext = useContext(OverflowMenuContext);
const handleClick = () => {
onClick();
if (!keepOpenAfterClick) {
menuContext.close();
}
};
2022-06-21 08:22:31 +00:00
return (
<MenuItem
2022-06-27 01:08:37 +00:00
onClick={handleClick}
2022-06-21 08:22:31 +00:00
sx={{
2023-02-02 04:43:15 +00:00
minWidth: 220,
2022-06-21 08:22:31 +00:00
color: (theme) => theme.palette[color].main,
2022-06-26 09:54:46 +00:00
padding: 1.5,
'& .MuiSvgIcon-root': {
fontSize: '20px',
},
2022-06-21 08:22:31 +00:00
}}>
2022-06-26 09:54:46 +00:00
<FluidContainer>
{startIcon && (
<Box
sx={{
padding: 0,
marginRight: 1.5,
}}>
{startIcon}
</Box>
)}
2023-03-30 07:15:51 +00:00
<Typography fontWeight="bold">{children}</Typography>
2022-06-26 09:54:46 +00:00
</FluidContainer>
{endIcon && (
<Box
2022-06-21 09:04:24 +00:00
sx={{
2022-06-26 09:54:46 +00:00
padding: 0,
marginLeft: 1,
2022-06-21 09:04:24 +00:00
}}>
2022-06-26 09:54:46 +00:00
{endIcon}
</Box>
2022-06-21 09:04:24 +00:00
)}
2022-06-21 08:22:31 +00:00
</MenuItem>
);
}