Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2917 | Rev 3093 | 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}
3054 stevensc 46
      action={typeof renderAction === 'function' ? renderAction() : null}
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={{
2917 stevensc 54
        variant: 'overline'
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,
67
        '&:last-child': { paddingBottom: 1 },
2824 stevensc 68
        '.MuiCardHeader-root + &': { paddingTop: 0 },
2819 stevensc 69
        ...styles
70
      }}
71
      {...props}
72
    >
2270 stevensc 73
      {children}
74
    </CardContent>
75
  )
2261 stevensc 76
}
77
 
2366 stevensc 78
export function WidgetActions({ children, styles = {}, ...props }) {
2261 stevensc 79
  return (
2275 stevensc 80
    <CardActions
2380 stevensc 81
      sx={{
2829 stevensc 82
        padding: 0.5,
2380 stevensc 83
        justifyContent: 'space-around',
84
        gap: 1,
85
        '& > button': {
86
          flex: '1'
87
        },
2830 stevensc 88
        borderTop: `1px solid ${colors.border.primary}`,
2380 stevensc 89
        ...styles
90
      }}
2275 stevensc 91
      disableSpacing
92
      {...props}
93
    >
2261 stevensc 94
      {children}
95
    </CardActions>
96
  )
97
}
98
 
99
export function WidgetMedia({
100
  src = '',
2840 stevensc 101
  height,
102
  width,
2261 stevensc 103
  alt = '',
2562 stevensc 104
  type = 'image',
2366 stevensc 105
  styles = {},
2261 stevensc 106
  ...props
107
}) {
2562 stevensc 108
  const getMediaComponent = (type) => {
109
    const options = {
110
      image: 'img',
111
      video: 'video',
112
      audio: 'audio'
113
    }
114
 
115
    return options[type] ?? options.image
116
  }
117
 
2261 stevensc 118
  return (
119
    <CardMedia
120
      alt={alt}
2562 stevensc 121
      component={getMediaComponent(type)}
2261 stevensc 122
      height={height}
2562 stevensc 123
      src={src}
2261 stevensc 124
      width={width}
2393 stevensc 125
      sx={{
2889 stevensc 126
        objectFit: 'contain',
2393 stevensc 127
        ...styles
128
      }}
2261 stevensc 129
      {...props}
130
    />
131
  )
132
}
133
 
134
Widget.Header = WidgetHeader
135
Widget.Body = WidgetBody
136
Widget.Actions = WidgetActions
137
Widget.Media = WidgetMedia
138
 
139
export default Widget