Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1659 | Rev 2853 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
import React, { useState } from 'react'
1659 stevensc 2
import { Menu, MenuItem, IconButton } from '@mui/material'
3
import { MoreVert } from '@mui/icons-material'
5 stevensc 4
 
1659 stevensc 5
const Options = ({ options = [], right = '.5rem', top = '.5rem' }) => {
5 stevensc 6
  const [anchorEl, setAnchorEl] = useState(null)
7
  const open = Boolean(anchorEl)
8
 
9
  const handleClick = (event) => {
10
    setAnchorEl(event.currentTarget)
11
  }
12
 
13
  const handleClose = () => {
14
    setAnchorEl(null)
15
  }
16
 
1659 stevensc 17
  if (!options.length) {
18
    return null
19
  }
20
 
5 stevensc 21
  return (
22
    <>
1659 stevensc 23
      <IconButton
24
        sx={{
25
          position: 'absolute',
26
          right,
27
          top,
28
          transform: top ? 'none' : 'translateY(-50%)'
29
        }}
5 stevensc 30
        right={right}
31
        top={top}
32
        onClick={handleClick}
1659 stevensc 33
        aria-controls={open ? 'account-menu' : ''}
677 stevensc 34
        aria-haspopup='true'
1659 stevensc 35
        aria-expanded={open ? 'true' : ''}
5 stevensc 36
      >
1659 stevensc 37
        <MoreVert />
38
      </IconButton>
5 stevensc 39
      <Menu
40
        anchorEl={anchorEl}
677 stevensc 41
        id='account-menu'
5 stevensc 42
        open={open}
43
        onClose={handleClose}
44
        onClick={handleClose}
45
        transformOrigin={{ horizontal: 'right', vertical: 'top' }}
46
        anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
47
      >
48
        {options.map((option, index) => (
49
          <MenuItem
50
            key={index}
51
            onClick={() => {
52
              option.action()
53
              handleClose()
54
            }}
55
          >
56
            {option.label}
57
          </MenuItem>
58
        ))}
59
      </Menu>
60
    </>
61
  )
62
}
63
 
64
export default Options