puppy-lib-components
Version:
A modern TypeScript React component library with generic UI components and football pickem domain components
27 lines (26 loc) • 1.18 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { Avatar as MuiAvatar } from '@mui/material';
export const Avatar = ({ src, alt = 'Avatar', size = 'md', shape = 'circle', fallback, clickable = false, onClick, className = '', ...props }) => {
// Map custom sizes to MUI sizes
const muiSize = size === 'xs' ? 24 :
size === 'sm' ? 32 :
size === 'md' ? 40 :
size === 'lg' ? 56 :
size === 'xl' ? 80 : 40;
// Map custom shapes to MUI variants
const muiVariant = shape === 'square' ? 'square' : 'circular';
const getInitials = (text) => {
return text
.split(' ')
.map(word => word.charAt(0))
.join('')
.toUpperCase()
.slice(0, 2);
};
return (_jsx(MuiAvatar, { src: src, alt: alt, sx: {
width: muiSize,
height: muiSize,
cursor: clickable ? 'pointer' : 'default',
borderRadius: shape === 'rounded' ? '8px' : undefined,
}, variant: muiVariant, onClick: clickable ? onClick : undefined, className: className, ...props, children: fallback ? getInitials(fallback) : '?' }));
};