Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
2261 stevensc 1
import React, { useState } from 'react'
2
import {
3
  Avatar,
4
  Card,
5
  CardActions,
6
  CardContent,
7
  CardHeader,
8
  CardMedia,
9
  IconButton,
10
  Menu,
11
  MenuItem,
12
  styled
13
} from '@mui/material'
14
import { MoreVert } from '@mui/icons-material'
15
 
16
const WidgetContainer = styled(Card)(({ theme }) => ({
17
  backgroundColor: theme.palette.background.default,
18
  boxShadow: theme.shadows[1],
19
  height: 'fit-content',
20
  position: 'relative',
21
  width: '100%',
22
  [theme.breakpoints.up('sm')]: {
23
    borderRadius: theme.shape.borderRadius
24
  }
25
}))
26
 
27
export function Widget({ children, ...props }) {
28
  return <WidgetContainer {...props}>{children}</WidgetContainer>
29
}
30
 
31
export function WidgetHeader({
32
  title = '',
33
  subheader = '',
34
  avatar = '',
35
  options = [],
36
  ...props
37
}) {
38
  const [anchorEl, setAnchorEl] = useState(null)
39
  const open = Boolean(anchorEl)
40
 
41
  const handleClick = (event) => setAnchorEl(event.currentTarget)
42
 
43
  const handleClose = () => setAnchorEl(null)
44
 
45
  return (
46
    <CardHeader
2262 stevensc 47
      avatar={avatar ? <Avatar alt={avatar.alt} src={avatar.src} /> : null}
2261 stevensc 48
      action={
49
        <>
50
          <IconButton
51
            id='settings-button'
52
            aria-controls={open ? 'settings-menu' : undefined}
53
            aria-haspopup='true'
54
            aria-expanded={open ? 'true' : undefined}
55
            onClick={handleClick}
56
            sx={{
57
              display: options.length > 0 ? 'block' : 'none'
58
            }}
59
          >
60
            <MoreVert />
61
          </IconButton>
62
          <Menu
63
            id='settings-menu'
64
            aria-labelledby='settings-button'
65
            anchorEl={anchorEl}
66
            open={open}
67
            onClose={handleClose}
68
            anchorOrigin={{
69
              vertical: 'top',
70
              horizontal: 'left'
71
            }}
72
            transformOrigin={{
73
              vertical: 'top',
74
              horizontal: 'left'
75
            }}
76
          >
77
            {options.map((option, index) => (
78
              <MenuItem
79
                key={index}
80
                onClick={() => {
81
                  option.action()
82
                  handleClose()
83
                }}
84
              >
85
                {option.label}
86
              </MenuItem>
87
            ))}
88
          </Menu>
89
        </>
90
      }
91
      title={title}
92
      subheader={subheader}
2262 stevensc 93
      titleTypographyProps={{
2263 stevensc 94
        sx: { fontSize: '16px', fontWeight: 600, color: 'var(--title-color)' }
2262 stevensc 95
      }}
96
      subheaderTypographyProps={{
2263 stevensc 97
        sx: { fontSize: '14px', color: 'var(--subtitle-color)' }
2262 stevensc 98
      }}
2261 stevensc 99
      {...props}
100
    />
101
  )
102
}
103
 
104
export function WidgetBody({ children, ...props }) {
105
  return <CardContent {...props}>{children}</CardContent>
106
}
107
 
108
export function WidgetActions({ children, ...props }) {
109
  return (
110
    <CardActions disableSpacing {...props}>
111
      {children}
112
    </CardActions>
113
  )
114
}
115
 
116
export function WidgetMedia({
117
  src = '',
118
  height = 200,
119
  width = 200,
120
  alt = '',
121
  component = 'img',
122
  ...props
123
}) {
124
  return (
125
    <CardMedia
126
      alt={alt}
127
      component={component}
128
      height={height}
129
      image={src}
130
      width={width}
131
      {...props}
132
    />
133
  )
134
}
135
 
136
Widget.Header = WidgetHeader
137
Widget.Body = WidgetBody
138
Widget.Actions = WidgetActions
139
Widget.Media = WidgetMedia
140
 
141
export default Widget