Proyectos de Subversion LeadersLinked - SPA

Rev

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