2022-10-07 17:53:40 +02:00
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Jazzicon from '../../ui/jazzicon/jazzicon.component';
|
|
|
|
import BlockieIdenticon from '../../ui/identicon/blockieIdenticon/blockieIdenticon.component';
|
2023-03-10 21:12:55 +01:00
|
|
|
|
2023-01-10 01:38:43 +01:00
|
|
|
import Box from '../../ui/box/box';
|
|
|
|
|
2023-03-10 21:12:55 +01:00
|
|
|
import { AvatarBase } from '../avatar-base';
|
2023-01-10 01:38:43 +01:00
|
|
|
import {
|
2023-03-10 21:12:55 +01:00
|
|
|
AvatarAccountDiameter,
|
|
|
|
AvatarAccountVariant,
|
|
|
|
AvatarAccountSize,
|
|
|
|
} from './avatar-account.types';
|
2022-10-07 17:53:40 +02:00
|
|
|
|
2023-04-21 17:51:34 +02:00
|
|
|
export const AvatarAccount = React.forwardRef(
|
|
|
|
(
|
|
|
|
{
|
|
|
|
size = AvatarAccountSize.Md,
|
|
|
|
address,
|
|
|
|
className,
|
|
|
|
variant = AvatarAccountVariant.Jazzicon,
|
|
|
|
...props
|
|
|
|
},
|
|
|
|
ref,
|
|
|
|
) => (
|
|
|
|
<AvatarBase
|
|
|
|
ref={ref}
|
|
|
|
size={size}
|
|
|
|
className={classnames('mm-avatar-account', className)}
|
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
{variant === AvatarAccountVariant.Jazzicon ? (
|
|
|
|
<Jazzicon
|
|
|
|
className={classnames('mm-avatar-account__jazzicon')}
|
|
|
|
address={address}
|
|
|
|
diameter={AvatarAccountDiameter[size]}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<BlockieIdenticon
|
|
|
|
address={address}
|
|
|
|
diameter={AvatarAccountDiameter[size]}
|
|
|
|
borderRadius="50%"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</AvatarBase>
|
|
|
|
),
|
2023-03-10 21:12:55 +01:00
|
|
|
);
|
2022-10-07 17:53:40 +02:00
|
|
|
|
|
|
|
AvatarAccount.propTypes = {
|
|
|
|
/**
|
|
|
|
* The size of the AvatarAccount.
|
2023-03-10 21:12:55 +01:00
|
|
|
* Possible values could be 'AvatarAccountSize.Xs', 'AvatarAccountSize.Sm', 'AvatarAccountSize.Md', 'AvatarAccountSize.Lg', 'AvatarAccountSize.Xl'
|
|
|
|
* Defaults to AvatarAccountSize.Md
|
2022-10-07 17:53:40 +02:00
|
|
|
*/
|
2023-03-10 21:12:55 +01:00
|
|
|
size: PropTypes.oneOf(Object.values(AvatarAccountSize)),
|
2022-10-07 17:53:40 +02:00
|
|
|
/**
|
2023-03-10 21:12:55 +01:00
|
|
|
* The variant of the avatar to be rendered, it can render either a AvatarAccountVariant.Jazzicon or a AvatarAccountVariant.Blockie
|
2022-10-07 17:53:40 +02:00
|
|
|
*/
|
2023-03-10 21:12:55 +01:00
|
|
|
variant: PropTypes.oneOf(Object.values(AvatarAccountVariant)),
|
2022-10-07 17:53:40 +02:00
|
|
|
/**
|
|
|
|
* Address used for generating random image
|
|
|
|
*/
|
2023-01-10 01:38:43 +01:00
|
|
|
address: PropTypes.string.isRequired,
|
2022-10-07 17:53:40 +02:00
|
|
|
/**
|
|
|
|
* Add custom css class
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
2023-01-10 01:38:43 +01:00
|
|
|
/**
|
|
|
|
* AvatarAccount also accepts all Box props including but not limited to
|
|
|
|
* className, as(change root element of HTML element) and margin props
|
|
|
|
*/
|
|
|
|
...Box.propTypes,
|
2022-10-07 17:53:40 +02:00
|
|
|
};
|
2023-04-21 17:51:34 +02:00
|
|
|
|
|
|
|
AvatarAccount.displayName = 'AvatarAccount';
|