Submenu.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // styling
  2. import styled from 'styled-components/macro';
  3. // components
  4. import Menu from '@mui/material/Menu';
  5. import MenuItem from '@mui/material/MenuItem';
  6. // hooks
  7. import {useThemeProvider} from '@contexts/themeContext';
  8. // utils
  9. import PropTypes from 'prop-types';
  10. const StyledMenuItem = styled(MenuItem)`
  11. display: flex;
  12. align-items: center;
  13. gap: 14px;
  14. font-size: 0.875rem !important;
  15. color: var(--text) !important;
  16. height: 40px;
  17. padding: 0 16px;
  18. width: 100%;
  19. &:hover .icon {
  20. color: var(--highlight);
  21. }
  22. .icon {
  23. color: var(--header);
  24. font-size: 12px;
  25. width: 12px;
  26. height: 12px;
  27. transition: color var(--transition);
  28. }
  29. `;
  30. const Submenu = ({open, onClose, anchorEl, actions}) => {
  31. const {direction} = useThemeProvider();
  32. return (
  33. <Menu
  34. open={open}
  35. onClose={onClose}
  36. anchorEl={anchorEl}
  37. elevation={0}
  38. anchorOrigin={{
  39. vertical: 'bottom',
  40. horizontal: direction === 'ltr' ? 'left' : 'right',
  41. }}
  42. transformOrigin={{
  43. vertical: 'top',
  44. horizontal: direction === 'ltr' ? 'left' : 'right',
  45. }}
  46. sx={{
  47. '& .MuiPaper-root': {
  48. backgroundColor: 'var(--tooltip-bg)',
  49. borderRadius: '4px',
  50. boxShadow: 'var(--widget-shadow)',
  51. marginTop: '6px',
  52. },
  53. '& .MuiMenu-list': {
  54. padding: 0,
  55. },
  56. '& .MuiButtonBase-root': {
  57. padding: '0 16px',
  58. width: '100%',
  59. '&:not(:last-child)': {
  60. borderBottom: '1px solid var(--divider)'
  61. },
  62. '&:hover': {
  63. backgroundColor: 'transparent'
  64. }
  65. }
  66. }}
  67. >
  68. {
  69. actions.map((action, index) => (
  70. <StyledMenuItem
  71. key={index}
  72. onClick={() => {
  73. action.onClick && action.onClick();
  74. onClose();
  75. }}>
  76. <i className={`icon icon-${action.icon}`}/>
  77. {action.label}
  78. </StyledMenuItem>
  79. ))
  80. }
  81. </Menu>
  82. )
  83. }
  84. Submenu.propTypes = {
  85. open: PropTypes.bool.isRequired,
  86. onClose: PropTypes.func.isRequired,
  87. anchorEl: PropTypes.any,
  88. actions: PropTypes.array.isRequired
  89. }
  90. export default Submenu