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 {
|
2023-02-02 21:15:26 +01:00
|
|
|
BorderColor,
|
|
|
|
Size,
|
2022-10-13 01:22:21 +02:00
|
|
|
DISPLAY,
|
2023-02-02 21:15:26 +01:00
|
|
|
AlignItems,
|
|
|
|
JustifyContent,
|
|
|
|
IconColor,
|
2022-10-13 01:22:21 +02:00
|
|
|
} 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 = ({
|
2023-02-02 21:15:26 +01:00
|
|
|
size = Size.MD,
|
2023-01-11 17:11:06 +01:00
|
|
|
src,
|
|
|
|
name = 'avatar-favicon',
|
2022-10-13 01:22:21 +02:00
|
|
|
className,
|
|
|
|
fallbackIconProps,
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor = BorderColor.transparent,
|
2022-10-13 01:22:21 +02:00
|
|
|
...props
|
|
|
|
}) => {
|
|
|
|
return (
|
2022-11-23 17:42:43 +01:00
|
|
|
<AvatarBase
|
2022-10-13 01:22:21 +02:00
|
|
|
size={size}
|
|
|
|
display={DISPLAY.FLEX}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.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
|
2023-01-24 18:39:46 +01:00
|
|
|
name={ICON_NAMES.GLOBAL}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={IconColor.iconDefault}
|
2022-10-13 01:22:21 +02:00
|
|
|
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-02-02 21:15:26 +01:00
|
|
|
* Possible values could be 'Size.XS' 16px, 'Size.SM' 24px, 'Size.MD' 32px, 'Size.LG' 40px, 'Size.XL' 48px
|
|
|
|
* Defaults to Size.MD
|
2022-10-13 01:22:21 +02:00
|
|
|
*/
|
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,
|
|
|
|
};
|