Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev Autor Línea Nro. Línea
2276 stevensc 1
import React from 'react'
2261 stevensc 2
import {
3
  Avatar,
4
  Card,
5
  CardActions,
6
  CardContent,
7
  CardHeader,
8
  CardMedia,
9
  styled
10
} from '@mui/material'
11
 
12
const WidgetContainer = styled(Card)(({ theme }) => ({
2275 stevensc 13
  borderRadius: 0,
2261 stevensc 14
  boxShadow: theme.shadows[1],
15
  height: 'fit-content',
16
  position: 'relative',
17
  width: '100%',
2688 stevensc 18
  transition: theme.transitions.easing.easeInOut,
2261 stevensc 19
  [theme.breakpoints.up('sm')]: {
20
    borderRadius: theme.shape.borderRadius
21
  }
22
}))
23
 
2268 stevensc 24
export function Widget({ children, styles, ...props }) {
25
  return (
2809 stevensc 26
    <WidgetContainer sx={styles} {...props}>
2268 stevensc 27
      {children}
28
    </WidgetContainer>
29
  )
2261 stevensc 30
}
31
 
32
export function WidgetHeader({
33
  title = '',
34
  subheader = '',
35
  avatar = '',
2809 stevensc 36
  styles = {},
2276 stevensc 37
  renderAction = () => null,
2809 stevensc 38
  onClick = () => {},
2261 stevensc 39
  ...props
40
}) {
41
  return (
42
    <CardHeader
2364 stevensc 43
      avatar={avatar ? <Avatar alt={title} src={avatar} /> : null}
2276 stevensc 44
      action={renderAction()}
2261 stevensc 45
      title={title}
46
      subheader={subheader}
2262 stevensc 47
      titleTypographyProps={{
2809 stevensc 48
        sx: { fontSize: '16px', fontWeight: 600, color: 'var(--title-color)' },
49
        onClick
2262 stevensc 50
      }}
51
      subheaderTypographyProps={{
2263 stevensc 52
        sx: { fontSize: '14px', color: 'var(--subtitle-color)' }
2262 stevensc 53
      }}
2275 stevensc 54
      sx={{ padding: 1, paddingBottom: 0, ...styles }}
2261 stevensc 55
      {...props}
56
    />
57
  )
58
}
59
 
2366 stevensc 60
export function WidgetBody({ children, styles = {}, ...props }) {
2270 stevensc 61
  return (
2276 stevensc 62
    <CardContent
63
      sx={{ padding: 1, '&:last-child': { paddingBottom: 1 }, ...styles }}
64
      {...props}
65
    >
2270 stevensc 66
      {children}
67
    </CardContent>
68
  )
2261 stevensc 69
}
70
 
2366 stevensc 71
export function WidgetActions({ children, styles = {}, ...props }) {
2261 stevensc 72
  return (
2275 stevensc 73
    <CardActions
2380 stevensc 74
      sx={{
75
        padding: 1,
76
        paddingTop: 0,
77
        justifyContent: 'space-around',
78
        gap: 1,
79
        '& > button': {
80
          flex: '1'
81
        },
82
        ...styles
83
      }}
2275 stevensc 84
      disableSpacing
85
      {...props}
86
    >
2261 stevensc 87
      {children}
88
    </CardActions>
89
  )
90
}
91
 
92
export function WidgetMedia({
93
  src = '',
94
  height = 200,
95
  width = 200,
96
  alt = '',
2562 stevensc 97
  type = 'image',
2366 stevensc 98
  styles = {},
2261 stevensc 99
  ...props
100
}) {
2562 stevensc 101
  const getMediaComponent = (type) => {
102
    const options = {
103
      image: 'img',
104
      video: 'video',
105
      audio: 'audio'
106
    }
107
 
108
    return options[type] ?? options.image
109
  }
110
 
2261 stevensc 111
  return (
112
    <CardMedia
113
      alt={alt}
2562 stevensc 114
      component={getMediaComponent(type)}
2261 stevensc 115
      height={height}
2562 stevensc 116
      src={src}
2261 stevensc 117
      width={width}
2393 stevensc 118
      sx={{
119
        objectFit: 'contain',
120
        ...styles
121
      }}
2261 stevensc 122
      {...props}
123
    />
124
  )
125
}
126
 
127
Widget.Header = WidgetHeader
128
Widget.Body = WidgetBody
129
Widget.Actions = WidgetActions
130
Widget.Media = WidgetMedia
131
 
132
export default Widget