2022-10-13 01:22:21 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
2022-11-23 17:42:43 +01:00
|
|
|
import { AvatarBase } from '../avatar-base';
|
2022-10-13 01:22:21 +02:00
|
|
|
import Box from '../../ui/box/box';
|
|
|
|
import { ICON_NAMES, Icon } from '../icon';
|
|
|
|
import {
|
|
|
|
COLORS,
|
|
|
|
BORDER_COLORS,
|
|
|
|
SIZES,
|
|
|
|
DISPLAY,
|
|
|
|
ALIGN_ITEMS,
|
|
|
|
JUSTIFY_CONTENT,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2023-01-11 17:11:06 +01:00
|
|
|
import { AVATAR_FAVICON_SIZES } from './avatar-favicon.constants';
|
2022-10-13 01:22:21 +02:00
|
|
|
|
|
|
|
export const AvatarFavicon = ({
|
|
|
|
size = SIZES.MD,
|
2023-01-11 17:11:06 +01:00
|
|
|
src,
|
|
|
|
name = 'avatar-favicon',
|
2022-10-13 01:22:21 +02:00
|
|
|
className,
|
|
|
|
fallbackIconProps,
|
|
|
|
borderColor = BORDER_COLORS.TRANSPARENT,
|
|
|
|
...props
|
|
|
|
}) => {
|
|
|
|
return (
|
2022-11-23 17:42:43 +01:00
|
|
|
<AvatarBase
|
2022-10-13 01:22:21 +02:00
|
|
|
size={size}
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
alignItems={ALIGN_ITEMS.CENTER}
|
|
|
|
justifyContent={JUSTIFY_CONTENT.CENTER}
|
2023-01-11 17:11:06 +01:00
|
|
|
className={classnames('mm-avatar-favicon', className)}
|
2022-10-13 01:22:21 +02:00
|
|
|
{...{ borderColor, ...props }}
|
|
|
|
>
|
2023-01-11 17:11:06 +01:00
|
|
|
{src ? (
|
|
|
|
<img
|
|
|
|
className="mm-avatar-favicon__image"
|
|
|
|
src={src}
|
|
|
|
alt={`${name} logo`}
|
|
|
|
/>
|
2022-10-13 01:22:21 +02:00
|
|
|
) : (
|
|
|
|
<Icon
|
|
|
|
name={ICON_NAMES.GLOBAL_FILLED}
|
|
|
|
color={COLORS.ICON_DEFAULT}
|
|
|
|
size={size}
|
|
|
|
{...fallbackIconProps}
|
|
|
|
/>
|
|
|
|
)}
|
2022-11-23 17:42:43 +01:00
|
|
|
</AvatarBase>
|
2022-10-13 01:22:21 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
AvatarFavicon.propTypes = {
|
|
|
|
/**
|
2023-01-11 17:11:06 +01:00
|
|
|
* The src accepts the string of the image to be rendered
|
2022-10-13 01:22:21 +02:00
|
|
|
*/
|
2023-01-11 17:11:06 +01:00
|
|
|
src: PropTypes.string,
|
2022-10-13 01:22:21 +02:00
|
|
|
/**
|
|
|
|
* The alt text for the favicon avatar to be rendered
|
|
|
|
*/
|
2023-01-11 17:11:06 +01:00
|
|
|
name: PropTypes.string.isRequired,
|
2022-10-13 01:22:21 +02:00
|
|
|
/**
|
|
|
|
* Props for the fallback icon. All Icon props can be used
|
|
|
|
*/
|
|
|
|
fallbackIconProps: PropTypes.shape(Icon.PropTypes),
|
|
|
|
/**
|
|
|
|
* The size of the AvatarFavicon
|
2023-01-11 17:11:06 +01:00
|
|
|
* Possible values could be 'SIZES.XS' 16px, 'SIZES.SM' 24px, 'SIZES.MD' 32px, 'SIZES.LG' 40px, 'SIZES.XL' 48px
|
2022-10-13 01:22:21 +02:00
|
|
|
* Defaults to SIZES.MD
|
|
|
|
*/
|
2023-01-11 17:11:06 +01:00
|
|
|
size: PropTypes.oneOf(Object.values(AVATAR_FAVICON_SIZES)),
|
2022-10-13 01:22:21 +02:00
|
|
|
/**
|
|
|
|
* The border color of the AvatarFavicon
|
|
|
|
* Defaults to COLORS.TRANSPARENT
|
|
|
|
*/
|
|
|
|
borderColor: Box.propTypes.borderColor,
|
|
|
|
/**
|
|
|
|
* Additional classNames to be added to the AvatarFavicon
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* AvatarFavicon also accepts all Box props including but not limited to
|
|
|
|
* className, as(change root element of HTML element) and margin props
|
|
|
|
*/
|
|
|
|
...Box.propTypes,
|
|
|
|
};
|