2022-08-01 11:44:33 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
2022-08-18 18:30:19 +02:00
|
|
|
|
2023-02-02 21:15:26 +01:00
|
|
|
import {
|
|
|
|
BackgroundColor,
|
|
|
|
BorderColor,
|
|
|
|
TextColor,
|
2023-04-19 23:16:49 +02:00
|
|
|
IconColor,
|
2023-03-17 18:06:59 +01:00
|
|
|
DISPLAY,
|
|
|
|
JustifyContent,
|
|
|
|
AlignItems,
|
|
|
|
BorderRadius,
|
|
|
|
TextVariant,
|
|
|
|
TEXT_TRANSFORM,
|
2023-02-02 21:15:26 +01:00
|
|
|
} from '../../../helpers/constants/design-system';
|
2023-03-17 18:06:59 +01:00
|
|
|
|
|
|
|
import { Text } from '../text';
|
|
|
|
|
2022-11-23 17:42:43 +01:00
|
|
|
import { AVATAR_BASE_SIZES } from './avatar-base.constants';
|
2022-08-01 11:44:33 +02:00
|
|
|
|
2022-11-23 17:42:43 +01:00
|
|
|
export const AvatarBase = ({
|
|
|
|
size = AVATAR_BASE_SIZES.MD,
|
2022-08-01 11:44:33 +02:00
|
|
|
children,
|
2023-02-02 21:15:26 +01:00
|
|
|
backgroundColor = BackgroundColor.backgroundAlternative,
|
|
|
|
borderColor = BorderColor.borderDefault,
|
|
|
|
color = TextColor.textDefault,
|
2022-08-18 18:30:19 +02:00
|
|
|
className,
|
2022-08-01 11:44:33 +02:00
|
|
|
...props
|
2023-03-17 18:06:59 +01:00
|
|
|
}) => {
|
|
|
|
let fallbackTextVariant;
|
2022-08-01 11:44:33 +02:00
|
|
|
|
2023-03-17 18:06:59 +01:00
|
|
|
if (size === AVATAR_BASE_SIZES.LG || size === AVATAR_BASE_SIZES.XL) {
|
|
|
|
fallbackTextVariant = TextVariant.bodyLgMedium;
|
|
|
|
} else if (size === AVATAR_BASE_SIZES.SM || size === AVATAR_BASE_SIZES.MD) {
|
|
|
|
fallbackTextVariant = TextVariant.bodySm;
|
|
|
|
} else {
|
|
|
|
fallbackTextVariant = TextVariant.bodyXs;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
className={classnames(
|
|
|
|
'mm-avatar-base',
|
|
|
|
`mm-avatar-base--size-${size}`,
|
|
|
|
className,
|
|
|
|
)}
|
|
|
|
as="div"
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
justifyContent={JustifyContent.center}
|
|
|
|
alignItems={AlignItems.center}
|
|
|
|
borderRadius={BorderRadius.full}
|
|
|
|
variant={fallbackTextVariant}
|
|
|
|
textTransform={TEXT_TRANSFORM.UPPERCASE}
|
|
|
|
{...{ backgroundColor, borderColor, color, ...props }}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
};
|
2022-11-23 17:42:43 +01:00
|
|
|
AvatarBase.propTypes = {
|
2022-08-01 11:44:33 +02:00
|
|
|
/**
|
2022-11-23 17:42:43 +01:00
|
|
|
* The size of the AvatarBase.
|
|
|
|
* Possible values could be 'AVATAR_BASE_SIZES.XS'(16px), 'AVATAR_BASE_SIZES.SM'(24px), 'AVATAR_BASE_SIZES.MD'(32px), 'AVATAR_BASE_SIZES.LG'(40px), 'AVATAR_BASE_SIZES.XL'(48px)
|
|
|
|
* Defaults to AVATAR_BASE_SIZES.MD
|
2022-08-01 11:44:33 +02:00
|
|
|
*/
|
2022-11-23 17:42:43 +01:00
|
|
|
size: PropTypes.oneOf(Object.values(AVATAR_BASE_SIZES)),
|
2022-08-01 11:44:33 +02:00
|
|
|
/**
|
2022-11-23 17:42:43 +01:00
|
|
|
* The children to be rendered inside the AvatarBase
|
2022-08-01 11:44:33 +02:00
|
|
|
*/
|
|
|
|
children: PropTypes.node,
|
|
|
|
/**
|
2022-11-23 17:42:43 +01:00
|
|
|
* The background color of the AvatarBase
|
2023-02-14 18:33:04 +01:00
|
|
|
* Defaults to Color.backgroundAlternative
|
2022-08-01 11:44:33 +02:00
|
|
|
*/
|
2023-03-16 21:18:00 +01:00
|
|
|
backgroundColor: PropTypes.oneOf(Object.values(BackgroundColor)),
|
2022-08-01 11:44:33 +02:00
|
|
|
/**
|
2022-11-23 17:42:43 +01:00
|
|
|
* The background color of the AvatarBase
|
2023-02-14 18:33:04 +01:00
|
|
|
* Defaults to Color.borderDefault
|
2022-08-01 11:44:33 +02:00
|
|
|
*/
|
2023-03-16 21:18:00 +01:00
|
|
|
borderColor: PropTypes.oneOf(Object.values(BorderColor)),
|
2022-08-01 11:44:33 +02:00
|
|
|
/**
|
2022-11-23 17:42:43 +01:00
|
|
|
* The color of the text inside the AvatarBase
|
2023-02-02 21:15:26 +01:00
|
|
|
* Defaults to TextColor.textDefault
|
2022-08-18 18:30:19 +02:00
|
|
|
*/
|
2023-04-19 23:16:49 +02:00
|
|
|
color: PropTypes.oneOf([
|
|
|
|
...Object.values(TextColor),
|
|
|
|
...Object.values(IconColor),
|
|
|
|
]),
|
2022-08-18 18:30:19 +02:00
|
|
|
/**
|
|
|
|
* Additional classNames to be added to the AvatarToken
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
2023-03-17 18:06:59 +01:00
|
|
|
* AvatarBase also accepts all Text props including variant and all Box props
|
2022-08-01 11:44:33 +02:00
|
|
|
*/
|
2023-03-17 18:06:59 +01:00
|
|
|
...Text.propTypes,
|
2022-08-01 11:44:33 +02:00
|
|
|
};
|