import { ReactNode } from 'react'; import classnames from 'classnames'; import { TOKEN_COLOR_TEXT_DEFAULT } from '@swipebox/morphe-design-tokens'; import avatarStyles from './AvatarFoundation.css'; import getAvatarColorToken from './getAvatarColorToken'; import avatarGroupStyles from '../AvatarGroup.css'; import Box from '../Box'; import { useColorScheme } from '../contexts/ColorSchemeProvider'; import icons from '../icons/index'; import useExperimentalTheme from '../utils/useExperimentalTheme'; const ICON_SIZE_RATIO = (20 / 48) * 100; // For pixel perfect icon button, we use the icon (20px) to parent container (48px) size ratio type ResponsiveFitSizeBoxProps = { color?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; children: ReactNode; content: string; isCollaboratorCount?: boolean; isHovered?: boolean; isPressed?: boolean; outline: boolean; }; function ResponsiveFitSizeBox({ color, content, children, isCollaboratorCount, isHovered, isPressed, outline, }: ResponsiveFitSizeBoxProps) { const theme = useExperimentalTheme(); const { colorSchemeName } = useColorScheme(); const isDarkMode = colorSchemeName === 'darkMode'; const avatarBackgroundColor = content === 'icon' || isCollaboratorCount ? getAvatarColorToken('default', isHovered, isPressed, isDarkMode) : getAvatarColorToken(color || 'default', isHovered, isPressed, isDarkMode); return theme.MAIN ? (
{children}
) : ( {children} ); } type AvatarFoundationProps = { color?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; children?: string | number; isCollaboratorCount?: boolean; isHovered?: boolean; isPressed?: boolean; fontSize?: string; outline?: boolean; textAnchor?: 'start' | 'middle' | 'end'; title?: string; translate?: 'translateX10'; content?: 'text' | 'icon'; }; export default function AvatarFoundation({ color, children, fontSize, isCollaboratorCount, isHovered, isPressed, outline = false, textAnchor = 'middle', title, translate, content = 'text', }: AvatarFoundationProps) { const theme = useExperimentalTheme(); const { colorSchemeName } = useColorScheme(); const isDarkMode = colorSchemeName === 'darkMode'; return ( {content === 'text' ? ( {title ? {title} : null} {children} ) : null} {content === 'icon' ? ( Icon ) : null} ); }