diff --git a/ui/components/component-library/avatar-account/README.mdx b/ui/components/component-library/avatar-account/README.mdx
index da8be813c..9e21ca81c 100644
--- a/ui/components/component-library/avatar-account/README.mdx
+++ b/ui/components/component-library/avatar-account/README.mdx
@@ -1,6 +1,7 @@
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { AvatarAccount } from './avatar-account';
+import { AvatarBase } from '../';
# AvatarAccount
@@ -12,32 +13,74 @@ The `AvatarAccount` is a type of avatar reserved for representing accounts.
## Props
-The `AvatarAccount` accepts all props below
+The `AvatarAccount` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story) component props
+`AvatarAccount` accepts all [AvatarBase](/docs/ui-components-component-library-avatar-base-avatar-base-stories-js--default-story#props)
+component props
+
+
+
### Size
-Use the `size` prop to set the size of the `AvatarAccount`.
+Use the `size` prop and the `SIZES` object from `./ui/helpers/constants/design-system.js` to change the size of `AvatarAccount`
+
+Optional: `AVATAR_ACCOUNT_SIZES` from `./ui/components/component-library` object can be used instead of `SIZES`
Possible sizes include:
-- `xs` 16px
-- `sm` 24px
-- `md` 32px
-- `lg` 40px
-- `xl` 48px
+- `SIZES.XS` 16px
+- `SIZES.SM` 24px
+- `SIZES.MD` 32px
+- `SIZES.LG` 40px
+- `SIZES.XL` 48px
-Defaults to `md`
+Defaults to `SIZES.MD`
-### type
+```jsx
+import { SIZES } from '../../../helpers/constants/design-system';
+import { AvatarAccount } from '../ui/component-library';
+
+
+
+
+
+
+```
+
+### Type
Use the `type` prop for the avatar to be rendered, it can either be a Jazzicon or a Blockie
\ No newline at end of file
+
+
+```jsx
+import { TYPES } from './avatar-account.constants';
+import { AvatarAccount } from '../ui/component-library';
+
+
+
+```
+
+### Address
+
+Use the required `address` for generating images
+
+
+
+```jsx
+import { TYPES } from './avatar-account.constants';
+import { AvatarAccount } from '../ui/component-library';
+
+
+
+```
diff --git a/ui/components/component-library/avatar-account/__snapshots__/avatar-account.test.js.snap b/ui/components/component-library/avatar-account/__snapshots__/avatar-account.test.js.snap
new file mode 100644
index 000000000..4fb7ecbbe
--- /dev/null
+++ b/ui/components/component-library/avatar-account/__snapshots__/avatar-account.test.js.snap
@@ -0,0 +1,50 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`AvatarAccount should render correctly 1`] = `
+
+`;
diff --git a/ui/components/component-library/avatar-account/avatar-account.constants.js b/ui/components/component-library/avatar-account/avatar-account.constants.js
index fd4e7e7cd..4028d89f9 100644
--- a/ui/components/component-library/avatar-account/avatar-account.constants.js
+++ b/ui/components/component-library/avatar-account/avatar-account.constants.js
@@ -1,4 +1,6 @@
-export const DIAMETERS = {
+import { SIZES } from '../../../helpers/constants/design-system';
+
+export const AVATAR_ACCOUNT_DIAMETERS = {
xs: '16',
sm: '24',
md: '32',
@@ -6,7 +8,15 @@ export const DIAMETERS = {
xl: '48',
};
-export const TYPES = {
+export const AVATAR_ACCOUNT_TYPES = {
JAZZICON: 'Jazzicon',
BLOCKIES: 'Blockie',
};
+
+export const AVATAR_ACCOUNT_SIZES = {
+ XS: SIZES.XS,
+ SM: SIZES.SM,
+ MD: SIZES.MD,
+ LG: SIZES.LG,
+ XL: SIZES.XL,
+};
diff --git a/ui/components/component-library/avatar-account/avatar-account.js b/ui/components/component-library/avatar-account/avatar-account.js
index 516aec919..e263a9bfa 100644
--- a/ui/components/component-library/avatar-account/avatar-account.js
+++ b/ui/components/component-library/avatar-account/avatar-account.js
@@ -4,27 +4,39 @@ import PropTypes from 'prop-types';
import Jazzicon from '../../ui/jazzicon/jazzicon.component';
import BlockieIdenticon from '../../ui/identicon/blockieIdenticon/blockieIdenticon.component';
import { AvatarBase } from '../avatar-base';
-
import { SIZES } from '../../../helpers/constants/design-system';
-import { DIAMETERS, TYPES } from './avatar-account.constants';
+import Box from '../../ui/box/box';
-export const AvatarAccount = ({ size, address, className, type, ...props }) => {
+import {
+ AVATAR_ACCOUNT_DIAMETERS,
+ AVATAR_ACCOUNT_TYPES,
+ AVATAR_ACCOUNT_SIZES,
+} from './avatar-account.constants';
+
+export const AvatarAccount = ({
+ size = SIZES.MD,
+ address,
+ className,
+ type,
+ ...props
+}) => {
return (
{type === 'Jazzicon' ? (
) : (
)}
@@ -38,17 +50,22 @@ AvatarAccount.propTypes = {
* Possible values could be 'SIZES.XS', 'SIZES.SM', 'SIZES.MD', 'SIZES.LG', 'SIZES.XL'
* Defaults to SIZES.MD
*/
- size: PropTypes.oneOf(Object.values(SIZES)),
+ size: PropTypes.oneOf(Object.values(AVATAR_ACCOUNT_SIZES)),
/**
* The type of the avatar to be rendered, it can render either a Jazzicon or a Blockie
*/
- type: PropTypes.oneOf(Object.values(TYPES)),
+ type: PropTypes.oneOf(Object.values(AVATAR_ACCOUNT_TYPES)),
/**
* Address used for generating random image
*/
- address: PropTypes.string,
+ 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,
};
diff --git a/ui/components/component-library/avatar-account/avatar-account.scss b/ui/components/component-library/avatar-account/avatar-account.scss
index 72d32de8a..3f6923436 100644
--- a/ui/components/component-library/avatar-account/avatar-account.scss
+++ b/ui/components/component-library/avatar-account/avatar-account.scss
@@ -1,4 +1,4 @@
-.avatar-account {
+.mm-avatar-account {
&__jazzicon {
display: flex;
}
diff --git a/ui/components/component-library/avatar-account/avatar-account.stories.js b/ui/components/component-library/avatar-account/avatar-account.stories.js
index f3fb9ce31..a3e410518 100644
--- a/ui/components/component-library/avatar-account/avatar-account.stories.js
+++ b/ui/components/component-library/avatar-account/avatar-account.stories.js
@@ -6,7 +6,10 @@ import {
SIZES,
} from '../../../helpers/constants/design-system';
import { AvatarAccount } from './avatar-account';
-import { TYPES } from './avatar-account.constants';
+import {
+ AVATAR_ACCOUNT_TYPES,
+ AVATAR_ACCOUNT_SIZES,
+} from './avatar-account.constants';
import README from './README.mdx';
@@ -22,18 +25,18 @@ export default {
argTypes: {
size: {
control: 'select',
- options: Object.values(SIZES),
+ options: Object.values(AVATAR_ACCOUNT_SIZES),
},
address: { control: 'text' },
type: {
control: 'select',
- options: Object.values(TYPES),
+ options: Object.values(AVATAR_ACCOUNT_TYPES),
},
},
args: {
address: '0x5CfE73b6021E818B776b421B1c4Db2474086a7e1',
size: SIZES.MD,
- type: TYPES.JAZZICON,
+ type: AVATAR_ACCOUNT_TYPES.JAZZICON,
},
};
@@ -53,7 +56,22 @@ export const Size = (args) => (
export const Type = (args) => (
-
-
+
+
+
+);
+
+export const Address = (args) => (
+
+
+
);
diff --git a/ui/components/component-library/avatar-account/avatar-account.test.js b/ui/components/component-library/avatar-account/avatar-account.test.js
index 94cf2783d..770d6e4e6 100644
--- a/ui/components/component-library/avatar-account/avatar-account.test.js
+++ b/ui/components/component-library/avatar-account/avatar-account.test.js
@@ -1,23 +1,103 @@
/* eslint-disable jest/require-top-level-describe */
import { render } from '@testing-library/react';
import React from 'react';
-import { AvatarAccount } from './avatar-account';
+import { AvatarAccount, AVATAR_ACCOUNT_SIZES } from '.';
import 'jest-canvas-mock';
describe('AvatarAccount', () => {
const args = {
address: '0x5CfE73b6021E818B776b421B1c4Db2474086a7e1',
+ type: 'Jazzicon',
};
- it('should render Jazzicon correctly', () => {
- const { getByTestId } = render(
- ,
+ it('should render correctly', () => {
+ const { getByTestId, container } = render(
+ ,
);
expect(getByTestId('avatar-account')).toBeDefined();
+ expect(container).toMatchSnapshot();
});
- it('should render Blockie correctly', () => {
- const { getByTestId } = render(
- ,
+
+ it('should render Jazzicon correctly', () => {
+ const container = (
+
+ );
+ expect(container.props.type).toStrictEqual('Jazzicon');
+ });
+
+ it('should render Blockie correctly', () => {
+ const container = (
+
+ );
+ expect(container.props.type).toStrictEqual('Blockie');
+ });
+
+ it('should render with custom classname', () => {
+ const { getByTestId } = render(
+ ,
+ );
+ expect(getByTestId('classname')).toHaveClass('mm-avatar-account--test');
+ });
+
+ it('should render with address', () => {
+ const container = (
+
+ );
+ expect(container.props.address).toStrictEqual('0x0');
+ });
+
+ it('should render with different size classes', () => {
+ const { getByTestId } = render(
+ <>
+
+
+
+
+
+ >,
+ );
+ expect(getByTestId(AVATAR_ACCOUNT_SIZES.XS)).toHaveClass(
+ `mm-avatar-base--size-${AVATAR_ACCOUNT_SIZES.XS}`,
+ );
+ expect(getByTestId(AVATAR_ACCOUNT_SIZES.SM)).toHaveClass(
+ `mm-avatar-base--size-${AVATAR_ACCOUNT_SIZES.SM}`,
+ );
+ expect(getByTestId(AVATAR_ACCOUNT_SIZES.MD)).toHaveClass(
+ `mm-avatar-base--size-${AVATAR_ACCOUNT_SIZES.MD}`,
+ );
+ expect(getByTestId(AVATAR_ACCOUNT_SIZES.LG)).toHaveClass(
+ `mm-avatar-base--size-${AVATAR_ACCOUNT_SIZES.LG}`,
+ );
+ expect(getByTestId(AVATAR_ACCOUNT_SIZES.XL)).toHaveClass(
+ `mm-avatar-base--size-${AVATAR_ACCOUNT_SIZES.XL}`,
);
- expect(getByTestId('avatar-account')).toBeDefined();
});
});
diff --git a/ui/components/component-library/avatar-account/index.js b/ui/components/component-library/avatar-account/index.js
index f314e744d..819be4061 100644
--- a/ui/components/component-library/avatar-account/index.js
+++ b/ui/components/component-library/avatar-account/index.js
@@ -1 +1,6 @@
export { AvatarAccount } from './avatar-account';
+export {
+ AVATAR_ACCOUNT_SIZES,
+ AVATAR_ACCOUNT_TYPES,
+ AVATAR_ACCOUNT_DIAMETERS,
+} from './avatar-account.constants';
diff --git a/ui/components/component-library/avatar-with-badge/avatar-with-badge.stories.js b/ui/components/component-library/avatar-with-badge/avatar-with-badge.stories.js
index 39ce64fab..af5fa76b2 100644
--- a/ui/components/component-library/avatar-with-badge/avatar-with-badge.stories.js
+++ b/ui/components/component-library/avatar-with-badge/avatar-with-badge.stories.js
@@ -1,6 +1,6 @@
import React from 'react';
import { AvatarAccount } from '../avatar-account';
-import { TYPES } from '../avatar-account/avatar-account.constants';
+import { AVATAR_ACCOUNT_TYPES } from '../avatar-account/avatar-account.constants';
import { AvatarNetwork } from '../avatar-network';
import Box from '../../ui/box/box';
import {
@@ -46,7 +46,7 @@ export const DefaultStory = (args) => (
);
@@ -67,7 +67,7 @@ export const BadgePosition = () => (
@@ -84,7 +84,7 @@ export const BadgePosition = () => (
diff --git a/ui/components/component-library/index.js b/ui/components/component-library/index.js
index 56c8d221f..003349da8 100644
--- a/ui/components/component-library/index.js
+++ b/ui/components/component-library/index.js
@@ -1,4 +1,9 @@
-export { AvatarAccount } from './avatar-account';
+export {
+ AvatarAccount,
+ AVATAR_ACCOUNT_SIZES,
+ AVATAR_ACCOUNT_TYPES,
+ AVATAR_ACCOUNT_DIAMETERS,
+} from './avatar-account';
export { AvatarFavicon } from './avatar-favicon';
export { AvatarIcon, AVATAR_ICON_SIZES } from './avatar-icon';
export { AvatarNetwork, AVATAR_NETWORK_SIZES } from './avatar-network';