Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2850 | Rev 2861 | 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
 
2827 stevensc 12
import colors from '@styles/colors'
13
 
2261 stevensc 14
const WidgetContainer = styled(Card)(({ theme }) => ({
2275 stevensc 15
  borderRadius: 0,
2850 stevensc 16
  border: `1px solid ${colors.border.primary}`,
2261 stevensc 17
  height: 'fit-content',
18
  position: 'relative',
2851 stevensc 19
  boxShadow: 'none',
2688 stevensc 20
  transition: theme.transitions.easing.easeInOut,
2261 stevensc 21
  [theme.breakpoints.up('sm')]: {
22
    borderRadius: theme.shape.borderRadius
23
  }
24
}))
25
 
2268 stevensc 26
export function Widget({ children, styles, ...props }) {
27
  return (
2809 stevensc 28
    <WidgetContainer sx={styles} {...props}>
2268 stevensc 29
      {children}
30
    </WidgetContainer>
31
  )
2261 stevensc 32
}
33
 
34
export function WidgetHeader({
35
  title = '',
36
  subheader = '',
37
  avatar = '',
2809 stevensc 38
  styles = {},
2276 stevensc 39
  renderAction = () => null,
2809 stevensc 40
  onClick = () => {},
2261 stevensc 41
  ...props
42
}) {
43
  return (
44
    <CardHeader
2830 stevensc 45
      avatar={avatar ? <Avatar alt={title} src={avatar} /> : null}
2276 stevensc 46
      action={renderAction()}
2261 stevensc 47
      title={title}
48
      subheader={subheader}
2262 stevensc 49
      titleTypographyProps={{
2818 stevensc 50
        variant: 'h3',
2809 stevensc 51
        onClick
2262 stevensc 52
      }}
53
      subheaderTypographyProps={{
2818 stevensc 54
        variant: 'body2'
2262 stevensc 55
      }}
2818 stevensc 56
      sx={{ padding: 1, ...styles }}
2261 stevensc 57
      {...props}
58
    />
59
  )
60
}
61
 
2366 stevensc 62
export function WidgetBody({ children, styles = {}, ...props }) {
2270 stevensc 63
  return (
2819 stevensc 64
    <CardContent
65
      sx={{
2821 stevensc 66
        padding: 1,
2843 stevensc 67
        paddingBottom: 0,
2821 stevensc 68
        '&:last-child': { paddingBottom: 1 },
2824 stevensc 69
        '.MuiCardHeader-root + &': { paddingTop: 0 },
2819 stevensc 70
        ...styles
71
      }}
72
      {...props}
73
    >
2270 stevensc 74
      {children}
75
    </CardContent>
76
  )
2261 stevensc 77
}
78
 
2366 stevensc 79
export function WidgetActions({ children, styles = {}, ...props }) {
2261 stevensc 80
  return (
2275 stevensc 81
    <CardActions
2380 stevensc 82
      sx={{
2829 stevensc 83
        padding: 0.5,
2380 stevensc 84
        justifyContent: 'space-around',
85
        gap: 1,
86
        '& > button': {
87
          flex: '1'
88
        },
2830 stevensc 89
        borderTop: `1px solid ${colors.border.primary}`,
2380 stevensc 90
        ...styles
91
      }}
2275 stevensc 92
      disableSpacing
93
      {...props}
94
    >
2261 stevensc 95
      {children}
96
    </CardActions>
97
  )
98
}
99
 
100
export function WidgetMedia({
101
  src = '',
2840 stevensc 102
  height,
103
  width,
2261 stevensc 104
  alt = '',
2562 stevensc 105
  type = 'image',
2366 stevensc 106
  styles = {},
2261 stevensc 107
  ...props
108
}) {
2562 stevensc 109
  const getMediaComponent = (type) => {
110
    const options = {
111
      image: 'img',
112
      video: 'video',
113
      audio: 'audio'
114
    }
115
 
116
    return options[type] ?? options.image
117
  }
118
 
2261 stevensc 119
  return (
120
    <CardMedia
121
      alt={alt}
2562 stevensc 122
      component={getMediaComponent(type)}
2261 stevensc 123
      height={height}
2562 stevensc 124
      src={src}
2261 stevensc 125
      width={width}
2393 stevensc 126
      sx={{
127
        objectFit: 'contain',
128
        ...styles
129
      }}
2261 stevensc 130
      {...props}
131
    />
132
  )
133
}
134
 
135
Widget.Header = WidgetHeader
136
Widget.Body = WidgetBody
137
Widget.Actions = WidgetActions
138
Widget.Media = WidgetMedia
139
 
140
export default Widget