Proyectos de Subversion LeadersLinked - SPA

Rev

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