Rev 2818 | Rev 2820 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'import {Avatar,Card,CardActions,CardContent,CardHeader,CardMedia,styled} from '@mui/material'const WidgetContainer = styled(Card)(({ theme }) => ({borderRadius: 0,boxShadow: theme.shadows[1],height: 'fit-content',position: 'relative',width: '100%',transition: theme.transitions.easing.easeInOut,[theme.breakpoints.up('sm')]: {borderRadius: theme.shape.borderRadius}}))export function Widget({ children, styles, ...props }) {return (<WidgetContainer sx={styles} {...props}>{children}</WidgetContainer>)}export function WidgetHeader({title = '',subheader = '',avatar = '',styles = {},renderAction = () => null,onClick = () => {},...props}) {return (<CardHeaderavatar={avatar ? <Avatar alt={title} src={avatar} /> : null}action={renderAction()}title={title}subheader={subheader}titleTypographyProps={{variant: 'h3',onClick}}subheaderTypographyProps={{variant: 'body2'}}sx={{ padding: 1, ...styles }}{...props}/>)}export function WidgetBody({ children, styles = {}, ...props }) {return (<CardContentsx={{paddingY: 1,paddingX: 1,'&:last-child': { paddingBottom: 1 },...styles}}{...props}>{children}</CardContent>)}export function WidgetActions({ children, styles = {}, ...props }) {return (<CardActionssx={{padding: 1,justifyContent: 'space-around',gap: 1,'& > button': {flex: '1'},...styles}}disableSpacing{...props}>{children}</CardActions>)}export function WidgetMedia({src = '',height = 200,width = 200,alt = '',type = 'image',styles = {},...props}) {const getMediaComponent = (type) => {const options = {image: 'img',video: 'video',audio: 'audio'}return options[type] ?? options.image}return (<CardMediaalt={alt}component={getMediaComponent(type)}height={height}src={src}width={width}sx={{objectFit: 'contain',...styles}}{...props}/>)}Widget.Header = WidgetHeaderWidget.Body = WidgetBodyWidget.Actions = WidgetActionsWidget.Media = WidgetMediaexport default Widget