Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2606 | Rev 2809 | 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 (
2606 stevensc 26
    <WidgetContainer sx={styles} {...props} com>
2268 stevensc 27
      {children}
28
    </WidgetContainer>
29
  )
2261 stevensc 30
}
31
 
32
export function WidgetHeader({
33
  title = '',
34
  subheader = '',
35
  avatar = '',
2276 stevensc 36
  renderAction = () => null,
2366 stevensc 37
  styles = {},
2261 stevensc 38
  ...props
39
}) {
40
  return (
41
    <CardHeader
2364 stevensc 42
      avatar={avatar ? <Avatar alt={title} src={avatar} /> : null}
2276 stevensc 43
      action={renderAction()}
2261 stevensc 44
      title={title}
45
      subheader={subheader}
2262 stevensc 46
      titleTypographyProps={{
2263 stevensc 47
        sx: { fontSize: '16px', fontWeight: 600, color: 'var(--title-color)' }
2262 stevensc 48
      }}
49
      subheaderTypographyProps={{
2263 stevensc 50
        sx: { fontSize: '14px', color: 'var(--subtitle-color)' }
2262 stevensc 51
      }}
2275 stevensc 52
      sx={{ padding: 1, paddingBottom: 0, ...styles }}
2261 stevensc 53
      {...props}
54
    />
55
  )
56
}
57
 
2366 stevensc 58
export function WidgetBody({ children, styles = {}, ...props }) {
2270 stevensc 59
  return (
2276 stevensc 60
    <CardContent
61
      sx={{ padding: 1, '&:last-child': { paddingBottom: 1 }, ...styles }}
62
      {...props}
63
    >
2270 stevensc 64
      {children}
65
    </CardContent>
66
  )
2261 stevensc 67
}
68
 
2366 stevensc 69
export function WidgetActions({ children, styles = {}, ...props }) {
2261 stevensc 70
  return (
2275 stevensc 71
    <CardActions
2380 stevensc 72
      sx={{
73
        padding: 1,
74
        paddingTop: 0,
75
        justifyContent: 'space-around',
76
        gap: 1,
77
        '& > button': {
78
          flex: '1'
79
        },
80
        ...styles
81
      }}
2275 stevensc 82
      disableSpacing
83
      {...props}
84
    >
2261 stevensc 85
      {children}
86
    </CardActions>
87
  )
88
}
89
 
90
export function WidgetMedia({
91
  src = '',
92
  height = 200,
93
  width = 200,
94
  alt = '',
2562 stevensc 95
  type = 'image',
2366 stevensc 96
  styles = {},
2261 stevensc 97
  ...props
98
}) {
2562 stevensc 99
  const getMediaComponent = (type) => {
100
    const options = {
101
      image: 'img',
102
      video: 'video',
103
      audio: 'audio'
104
    }
105
 
106
    return options[type] ?? options.image
107
  }
108
 
2261 stevensc 109
  return (
110
    <CardMedia
111
      alt={alt}
2562 stevensc 112
      component={getMediaComponent(type)}
2261 stevensc 113
      height={height}
2562 stevensc 114
      src={src}
2261 stevensc 115
      width={width}
2393 stevensc 116
      sx={{
117
        objectFit: 'contain',
118
        ...styles
119
      }}
2261 stevensc 120
      {...props}
121
    />
122
  )
123
}
124
 
125
Widget.Header = WidgetHeader
126
Widget.Body = WidgetBody
127
Widget.Actions = WidgetActions
128
Widget.Media = WidgetMedia
129
 
130
export default Widget