import clsx from 'clsx'; import './rds-avatar.scss'; import { Avatar as MuiAvatar, type AvatarProps } from '@mui/material'; export interface RdsAvatarProps extends Omit { colorVariant?: 'primary' | 'success' | 'danger' | 'warning' | 'light' | 'info' | 'secondary' | 'dark'; title?: string; subText?: string; size?: 'smallest' | 'small' | 'medium' | 'large' | 'largest'; displayStyle?: 'with-name' | 'name-bottom' | 'stacking'; avatars?: Array<{ src?: string; title?: string; subText?: string; size?: 'smallest' | 'small' | 'medium' | 'large' | 'largest'; alt?: string; colorVariant?: string; }>; maxVisibleAvatars?: number; activityRing?: boolean; activeDotTop?: boolean; activeDotBottom?: boolean; showName?: boolean; showDesignation?: boolean; showRemainingCount?: boolean; } const sizeStyles = { smallest: { width: 24, height: 24, fontSize: '0.5625rem' }, // 9px small: { width: 32, height: 32, fontSize: '0.6875rem' }, // 11px medium: { width: 40, height: 40, fontSize: '0.875rem' }, // 14px large: { width: 48, height: 48, fontSize: '1.125rem' }, // 18px largest: { width: 64, height: 64, fontSize: '1.3125rem' }, // 21px }; /** Maps avatar size key to a rem font-size for the +N overflow badge */ const overflowFontSize: Record = { smallest: '0.5rem', small: '0.6875rem', medium: '0.875rem', large: '1rem', largest: '1.125rem', }; const overlapOffsets: Record = { smallest: -12, small: -14, medium: -16, large: -20, largest: -26, }; const RdsAvatar = ({ colorVariant = 'primary', title, subText, size = 'medium', displayStyle = 'with-name', avatars, maxVisibleAvatars = 3, children, sx, activityRing = false, activeDotTop = false, activeDotBottom = false, showName = true, showDesignation = true, showRemainingCount = true, ...props }: RdsAvatarProps) => { if (displayStyle === 'stacking' && avatars && avatars.length > 0) { const visibleAvatars = avatars.slice(0, maxVisibleAvatars); const remainingCount = Math.max(0, avatars.length - maxVisibleAvatars); const overlapOffset = overlapOffsets[size] ?? -22; const avatarSize = sizeStyles[size].width; const itemCount = visibleAvatars.length + (remainingCount > 0 && showRemainingCount ? 1 : 0); const stackWidth = itemCount > 0 ? avatarSize + Math.max(0, itemCount - 1) * (avatarSize + overlapOffset) : avatarSize; return (
{visibleAvatars.map((avatar, idx) => ( {avatar.title ? avatar.title.charAt(0).toUpperCase() : null} ))} {remainingCount > 0 && showRemainingCount && (
+{remainingCount}
)}
); } if (displayStyle === 'with-name') { return (
{activityRing &&
); } if (displayStyle === 'name-bottom') { return (
{activityRing &&
); } return ( {activityRing &&