2023-05-04 02:30:07 +02:00
|
|
|
import React, { forwardRef, Ref } from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
import {
|
|
|
|
BackgroundColor,
|
|
|
|
BorderColor,
|
|
|
|
TextColor,
|
2023-06-05 17:43:23 +02:00
|
|
|
Display,
|
2023-05-04 02:30:07 +02:00
|
|
|
JustifyContent,
|
|
|
|
AlignItems,
|
|
|
|
BorderRadius,
|
|
|
|
TextVariant,
|
|
|
|
TextTransform,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
|
2023-07-14 19:59:30 +02:00
|
|
|
import { Text } from '../text/deprecated';
|
2023-05-04 02:30:07 +02:00
|
|
|
|
|
|
|
import { AvatarBaseProps, AvatarBaseSize } from './avatar-base.types';
|
|
|
|
|
|
|
|
export const AvatarBase = forwardRef(
|
|
|
|
(
|
|
|
|
{
|
|
|
|
size = AvatarBaseSize.Md,
|
|
|
|
children,
|
|
|
|
backgroundColor = BackgroundColor.backgroundAlternative,
|
|
|
|
borderColor = BorderColor.borderDefault,
|
|
|
|
color = TextColor.textDefault,
|
|
|
|
className = '',
|
|
|
|
...props
|
|
|
|
}: AvatarBaseProps,
|
|
|
|
ref: Ref<HTMLElement>,
|
|
|
|
) => {
|
|
|
|
let fallbackTextVariant;
|
|
|
|
|
|
|
|
if (size === AvatarBaseSize.Lg || size === AvatarBaseSize.Xl) {
|
|
|
|
fallbackTextVariant = TextVariant.bodyLgMedium;
|
|
|
|
} else if (size === AvatarBaseSize.Sm || size === AvatarBaseSize.Md) {
|
|
|
|
fallbackTextVariant = TextVariant.bodySm;
|
|
|
|
} else {
|
|
|
|
fallbackTextVariant = TextVariant.bodyXs;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
className={classnames(
|
|
|
|
'mm-avatar-base',
|
|
|
|
`mm-avatar-base--size-${size}`,
|
|
|
|
className,
|
|
|
|
)}
|
|
|
|
ref={ref}
|
2023-07-14 19:59:30 +02:00
|
|
|
as="div"
|
2023-06-05 17:43:23 +02:00
|
|
|
display={Display.Flex}
|
2023-05-04 02:30:07 +02:00
|
|
|
justifyContent={JustifyContent.center}
|
|
|
|
alignItems={AlignItems.center}
|
|
|
|
borderRadius={BorderRadius.full}
|
|
|
|
variant={fallbackTextVariant}
|
|
|
|
textTransform={TextTransform.Uppercase}
|
|
|
|
{...{ backgroundColor, borderColor, color, ...props }}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|