1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00
metamask-extension/ui/components/component-library/avatar-account/avatar-account.js
George Marshall d2779c9ef1
Updating Avatar components to forward refs (#18678)
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2023-04-21 08:51:34 -07:00

77 lines
2.1 KiB
JavaScript

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';
import Box from '../../ui/box/box';
import { AvatarBase } from '../avatar-base';
import {
AvatarAccountDiameter,
AvatarAccountVariant,
AvatarAccountSize,
} from './avatar-account.types';
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>
),
);
AvatarAccount.propTypes = {
/**
* The size of the AvatarAccount.
* Possible values could be 'AvatarAccountSize.Xs', 'AvatarAccountSize.Sm', 'AvatarAccountSize.Md', 'AvatarAccountSize.Lg', 'AvatarAccountSize.Xl'
* Defaults to AvatarAccountSize.Md
*/
size: PropTypes.oneOf(Object.values(AvatarAccountSize)),
/**
* The variant of the avatar to be rendered, it can render either a AvatarAccountVariant.Jazzicon or a AvatarAccountVariant.Blockie
*/
variant: PropTypes.oneOf(Object.values(AvatarAccountVariant)),
/**
* Address used for generating random image
*/
address: PropTypes.string.isRequired,
/**
* Add custom css class
*/
className: PropTypes.string,
/**
* AvatarAccount also accepts all Box props including but not limited to
* className, as(change root element of HTML element) and margin props
*/
...Box.propTypes,
};
AvatarAccount.displayName = 'AvatarAccount';