Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2263 | Rev 2270 | 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
 
2268 stevensc 27
export function Widget({ children, styles, ...props }) {
28
  return (
29
    <WidgetContainer sx={styles} {...props}>
30
      {children}
31
    </WidgetContainer>
32
  )
2261 stevensc 33
}
34
 
35
export function WidgetHeader({
36
  title = '',
37
  subheader = '',
38
  avatar = '',
39
  options = [],
40
  ...props
41
}) {
42
  const [anchorEl, setAnchorEl] = useState(null)
43
  const open = Boolean(anchorEl)
44
 
45
  const handleClick = (event) => setAnchorEl(event.currentTarget)
46
 
47
  const handleClose = () => setAnchorEl(null)
48
 
49
  return (
50
    <CardHeader
2262 stevensc 51
      avatar={avatar ? <Avatar alt={avatar.alt} src={avatar.src} /> : null}
2261 stevensc 52
      action={
53
        <>
54
          <IconButton
55
            id='settings-button'
56
            aria-controls={open ? 'settings-menu' : undefined}
57
            aria-haspopup='true'
58
            aria-expanded={open ? 'true' : undefined}
59
            onClick={handleClick}
60
            sx={{
61
              display: options.length > 0 ? 'block' : 'none'
62
            }}
63
          >
64
            <MoreVert />
65
          </IconButton>
66
          <Menu
67
            id='settings-menu'
68
            aria-labelledby='settings-button'
69
            anchorEl={anchorEl}
70
            open={open}
71
            onClose={handleClose}
72
            anchorOrigin={{
73
              vertical: 'top',
74
              horizontal: 'left'
75
            }}
76
            transformOrigin={{
77
              vertical: 'top',
78
              horizontal: 'left'
79
            }}
80
          >
81
            {options.map((option, index) => (
82
              <MenuItem
83
                key={index}
84
                onClick={() => {
85
                  option.action()
86
                  handleClose()
87
                }}
88
              >
89
                {option.label}
90
              </MenuItem>
91
            ))}
92
          </Menu>
93
        </>
94
      }
95
      title={title}
96
      subheader={subheader}
2262 stevensc 97
      titleTypographyProps={{
2263 stevensc 98
        sx: { fontSize: '16px', fontWeight: 600, color: 'var(--title-color)' }
2262 stevensc 99
      }}
100
      subheaderTypographyProps={{
2263 stevensc 101
        sx: { fontSize: '14px', color: 'var(--subtitle-color)' }
2262 stevensc 102
      }}
2261 stevensc 103
      {...props}
104
    />
105
  )
106
}
107
 
108
export function WidgetBody({ children, ...props }) {
109
  return <CardContent {...props}>{children}</CardContent>
110
}
111
 
112
export function WidgetActions({ children, ...props }) {
113
  return (
114
    <CardActions disableSpacing {...props}>
115
      {children}
116
    </CardActions>
117
  )
118
}
119
 
120
export function WidgetMedia({
121
  src = '',
122
  height = 200,
123
  width = 200,
124
  alt = '',
125
  component = 'img',
126
  ...props
127
}) {
128
  return (
129
    <CardMedia
130
      alt={alt}
131
      component={component}
132
      height={height}
133
      image={src}
134
      width={width}
135
      {...props}
136
    />
137
  )
138
}
139
 
140
Widget.Header = WidgetHeader
141
Widget.Body = WidgetBody
142
Widget.Actions = WidgetActions
143
Widget.Media = WidgetMedia
144
 
145
export default Widget