Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2809 | Rev 2819 | 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={{
2818 stevensc 48
        variant: 'h3',
2809 stevensc 49
        onClick
2262 stevensc 50
      }}
51
      subheaderTypographyProps={{
2818 stevensc 52
        variant: 'body2'
2262 stevensc 53
      }}
2818 stevensc 54
      sx={{ padding: 1, ...styles }}
2261 stevensc 55
      {...props}
56
    />
57
  )
58
}
59
 
2366 stevensc 60
export function WidgetBody({ children, styles = {}, ...props }) {
2270 stevensc 61
  return (
2818 stevensc 62
    <CardContent sx={{ paddingY: 0, paddingX: 1, ...styles }} {...props}>
2270 stevensc 63
      {children}
64
    </CardContent>
65
  )
2261 stevensc 66
}
67
 
2366 stevensc 68
export function WidgetActions({ children, styles = {}, ...props }) {
2261 stevensc 69
  return (
2275 stevensc 70
    <CardActions
2380 stevensc 71
      sx={{
72
        padding: 1,
73
        justifyContent: 'space-around',
74
        gap: 1,
75
        '& > button': {
76
          flex: '1'
77
        },
78
        ...styles
79
      }}
2275 stevensc 80
      disableSpacing
81
      {...props}
82
    >
2261 stevensc 83
      {children}
84
    </CardActions>
85
  )
86
}
87
 
88
export function WidgetMedia({
89
  src = '',
90
  height = 200,
91
  width = 200,
92
  alt = '',
2562 stevensc 93
  type = 'image',
2366 stevensc 94
  styles = {},
2261 stevensc 95
  ...props
96
}) {
2562 stevensc 97
  const getMediaComponent = (type) => {
98
    const options = {
99
      image: 'img',
100
      video: 'video',
101
      audio: 'audio'
102
    }
103
 
104
    return options[type] ?? options.image
105
  }
106
 
2261 stevensc 107
  return (
108
    <CardMedia
109
      alt={alt}
2562 stevensc 110
      component={getMediaComponent(type)}
2261 stevensc 111
      height={height}
2562 stevensc 112
      src={src}
2261 stevensc 113
      width={width}
2393 stevensc 114
      sx={{
115
        objectFit: 'contain',
116
        ...styles
117
      }}
2261 stevensc 118
      {...props}
119
    />
120
  )
121
}
122
 
123
Widget.Header = WidgetHeader
124
Widget.Body = WidgetBody
125
Widget.Actions = WidgetActions
126
Widget.Media = WidgetMedia
127
 
128
export default Widget