avatar base component housekeeping (#16583)

* replace base avatar with avatar base component

* updated tests

* updated description for props

* updated docs and background colors

* updated snapshot

* replaced size with avatar size constant

* added tests and fixed indentation

* fixed indentation in readme
feature/default_network_editable
Nidhi Kumari 2 years ago committed by GitHub
parent 1bdfb952bd
commit 67bfd446fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      ui/components/component-library/avatar-account/avatar-account.js
  2. 97
      ui/components/component-library/avatar-base/README.mdx
  3. 10
      ui/components/component-library/avatar-base/__snapshots__/avatar-base.test.js.snap
  4. 9
      ui/components/component-library/avatar-base/avatar-base.constants.js
  5. 31
      ui/components/component-library/avatar-base/avatar-base.js
  6. 2
      ui/components/component-library/avatar-base/avatar-base.scss
  7. 56
      ui/components/component-library/avatar-base/avatar-base.stories.js
  8. 124
      ui/components/component-library/avatar-base/avatar-base.test.js
  9. 2
      ui/components/component-library/avatar-base/index.js
  10. 6
      ui/components/component-library/avatar-favicon/avatar-favicon.js
  11. 6
      ui/components/component-library/avatar-network/avatar-network.js
  12. 4
      ui/components/component-library/avatar-network/avatar-network.stories.js
  13. 6
      ui/components/component-library/avatar-token/avatar-token.js
  14. 4
      ui/components/component-library/avatar-token/avatar-token.stories.js
  15. 53
      ui/components/component-library/base-avatar/README.mdx
  16. 28
      ui/components/component-library/base-avatar/base-avatar.test.js
  17. 1
      ui/components/component-library/base-avatar/index.js
  18. 2
      ui/components/component-library/component-library-components.scss
  19. 2
      ui/components/component-library/index.js
  20. 2
      ui/components/component-library/picker-network/__snapshots__/picker-network.test.js.snap
  21. 2
      ui/components/component-library/tag-url/__snapshots__/tag-url.test.js.snap

@ -3,14 +3,14 @@ import classnames from 'classnames';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Jazzicon from '../../ui/jazzicon/jazzicon.component'; import Jazzicon from '../../ui/jazzicon/jazzicon.component';
import BlockieIdenticon from '../../ui/identicon/blockieIdenticon/blockieIdenticon.component'; import BlockieIdenticon from '../../ui/identicon/blockieIdenticon/blockieIdenticon.component';
import { BaseAvatar } from '../base-avatar'; import { AvatarBase } from '../avatar-base';
import { SIZES } from '../../../helpers/constants/design-system'; import { SIZES } from '../../../helpers/constants/design-system';
import { DIAMETERS, TYPES } from './avatar-account.constants'; import { DIAMETERS, TYPES } from './avatar-account.constants';
export const AvatarAccount = ({ size, address, className, type, ...props }) => { export const AvatarAccount = ({ size, address, className, type, ...props }) => {
return ( return (
<BaseAvatar <AvatarBase
size={size} size={size}
className={classnames('avatar-account', className)} className={classnames('avatar-account', className)}
{...props} {...props}
@ -28,7 +28,7 @@ export const AvatarAccount = ({ size, address, className, type, ...props }) => {
borderRadius="50%" borderRadius="50%"
/> />
)} )}
</BaseAvatar> </AvatarBase>
); );
}; };

@ -0,0 +1,97 @@
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { AvatarBase } from './avatar-base';
### This is a base component. It should not be used in your feature code directly but as a "base" for other UI components
# AvatarBase
The `AvatarBase` is a wrapper component responsible for enforcing dimensions and border radius for Avatar components
<Canvas>
<Story id="ui-components-component-library-avatar-base-avatar-base-stories-js--default-story" />
</Canvas>
## Props
The `AvatarBase` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props) component props.
<ArgsTable of={AvatarBase} />
### Size
Use the `size` prop to set the size of the `AvatarBase`.
Possible sizes include:
- `xs` 16px
- `sm` 24px
- `md` 32px
- `lg` 40px
- `xl` 48px
Defaults to `md`
<Canvas>
<Story id="ui-components-component-library-avatar-base-avatar-base-stories-js--size" />
</Canvas>
```jsx
import { AVATAR_BASE_SIZES } from '../ui/component-library/avatar-base';
import { AvatarBase } from '../../component-library';
<AvatarBase size={AVATAR_BASE_SIZES.XS} />
<AvatarBase size={AVATAR_BASE_SIZES.SM} />
<AvatarBase size={AVATAR_BASE_SIZES.MD} />
<AvatarBase size={AVATAR_BASE_SIZES.LG} />
<AvatarBase size={AVATAR_BASE_SIZES.XL} />
```
### Children
The `AvatarBase` component can contain images, icons or text
<Canvas>
<Story id="ui-components-component-library-avatar-base-avatar-base-stories-js--children" />
</Canvas>
```jsx
import { AvatarBase } from '../../component-library';
<AvatarBase>
<img src="./images/eth_logo.svg" />
</AvatarBase>
<AvatarBase>
<img width="100%" src="./images/arbitrum.svg" />
</AvatarBase>
<AvatarBase>
<img width="100%" src="./images/avax-token.png" />
</AvatarBase>
<AvatarBase>A</AvatarBase>
```
### Color, Background Color And Border Color
Use the `color`, `backgroundColor` and `borderColor` props to set the text color, background-color and border-color of the `AvatarBase`.
<Canvas>
<Story id="ui-components-component-library-avatar-base-avatar-base-stories-js--color-background-color-and-border-color" />
</Canvas>
```jsx
import { COLORS } from '../../../helpers/constants/design-system';
import { AvatarBase } from '../../component-library';
<AvatarBase>B</AvatarBase>
<AvatarBase
backgroundColor={COLORS.GOERLI}
borderColor={COLORS.GOERLI}
color={COLORS.PRIMARY_INVERSE}
>
G
</AvatarBase>
<AvatarBase
backgroundColor={COLORS.SEPOLIA}
borderColor={COLORS.SEPOLIA}
color={COLORS.PRIMARY_INVERSE}
>
S
</AvatarBase>
```

@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`AvatarBase should render correctly 1`] = `
<div>
<div
class="box mm-avatar-base mm-avatar-base--size-md box--flex-direction-row box--color-text-default box--background-color-background-alternative box--border-color-border-default box--border-style-solid box--border-width-1"
data-testid="avatar-base"
/>
</div>
`;

@ -0,0 +1,9 @@
import { SIZES } from '../../../helpers/constants/design-system';
export const AVATAR_BASE_SIZES = {
XS: SIZES.XS,
SM: SIZES.SM,
MD: SIZES.MD,
LG: SIZES.LG,
XL: SIZES.XL,
};

@ -3,10 +3,11 @@ import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import Box from '../../ui/box/box'; import Box from '../../ui/box/box';
import { COLORS, SIZES } from '../../../helpers/constants/design-system'; import { COLORS } from '../../../helpers/constants/design-system';
import { AVATAR_BASE_SIZES } from './avatar-base.constants';
export const BaseAvatar = ({ export const AvatarBase = ({
size = SIZES.MD, size = AVATAR_BASE_SIZES.MD,
children, children,
backgroundColor = COLORS.BACKGROUND_ALTERNATIVE, backgroundColor = COLORS.BACKGROUND_ALTERNATIVE,
borderColor = COLORS.BORDER_DEFAULT, borderColor = COLORS.BORDER_DEFAULT,
@ -16,8 +17,8 @@ export const BaseAvatar = ({
}) => ( }) => (
<Box <Box
className={classnames( className={classnames(
'base-avatar', 'mm-avatar-base',
`base-avatar--size-${size}`, `mm-avatar-base--size-${size}`,
className, className,
)} )}
{...{ backgroundColor, borderColor, color, ...props }} {...{ backgroundColor, borderColor, color, ...props }}
@ -26,29 +27,29 @@ export const BaseAvatar = ({
</Box> </Box>
); );
BaseAvatar.propTypes = { AvatarBase.propTypes = {
/** /**
* The size of the BaseAvatar. * The size of the AvatarBase.
* Possible values could be 'SIZES.XS', 'SIZES.SM', 'SIZES.MD', 'SIZES.LG', 'SIZES.XL' * Possible values could be 'AVATAR_BASE_SIZES.XS'(16px), 'AVATAR_BASE_SIZES.SM'(24px), 'AVATAR_BASE_SIZES.MD'(32px), 'AVATAR_BASE_SIZES.LG'(40px), 'AVATAR_BASE_SIZES.XL'(48px)
* Defaults to SIZES.MD * Defaults to AVATAR_BASE_SIZES.MD
*/ */
size: PropTypes.oneOf(Object.values(SIZES)), size: PropTypes.oneOf(Object.values(AVATAR_BASE_SIZES)),
/** /**
* The children to be rendered inside the BaseAvatar * The children to be rendered inside the AvatarBase
*/ */
children: PropTypes.node, children: PropTypes.node,
/** /**
* The background color of the BaseAvatar * The background color of the AvatarBase
* Defaults to COLORS.BACKGROUND_ALTERNATIVE * Defaults to COLORS.BACKGROUND_ALTERNATIVE
*/ */
backgroundColor: Box.propTypes.backgroundColor, backgroundColor: Box.propTypes.backgroundColor,
/** /**
* The background color of the BaseAvatar * The background color of the AvatarBase
* Defaults to COLORS.BORDER_DEFAULT * Defaults to COLORS.BORDER_DEFAULT
*/ */
borderColor: Box.propTypes.borderColor, borderColor: Box.propTypes.borderColor,
/** /**
* The color of the text inside the BaseAvatar * The color of the text inside the AvatarBase
* Defaults to COLORS.TEXT_DEFAULT * Defaults to COLORS.TEXT_DEFAULT
*/ */
color: Box.propTypes.color, color: Box.propTypes.color,
@ -57,7 +58,7 @@ BaseAvatar.propTypes = {
*/ */
className: PropTypes.string, className: PropTypes.string,
/** /**
* BaseAvatar also accepts all Box props including but not limited to * AvatarBase also accepts all Box props including but not limited to
* className, as(change root element of HTML element) and margin props * className, as(change root element of HTML element) and margin props
*/ */
...Box.propTypes, ...Box.propTypes,

@ -1,4 +1,4 @@
.base-avatar { .mm-avatar-base {
--avatar-size: var(--size, 16px); --avatar-size: var(--size, 16px);
&--size-xs { &--size-xs {

@ -3,7 +3,6 @@ import {
ALIGN_ITEMS, ALIGN_ITEMS,
COLORS, COLORS,
DISPLAY, DISPLAY,
SIZES,
TEXT_COLORS, TEXT_COLORS,
BACKGROUND_COLORS, BACKGROUND_COLORS,
BORDER_COLORS, BORDER_COLORS,
@ -12,7 +11,8 @@ import {
import Box from '../../ui/box/box'; import Box from '../../ui/box/box';
import README from './README.mdx'; import README from './README.mdx';
import { BaseAvatar } from './base-avatar'; import { AvatarBase } from './avatar-base';
import { AVATAR_BASE_SIZES } from './avatar-base.constants';
const marginSizeKnobOptions = [ const marginSizeKnobOptions = [
0, 0,
@ -32,9 +32,9 @@ const marginSizeKnobOptions = [
]; ];
export default { export default {
title: 'Components/ComponentLibrary/BaseAvatar', title: 'Components/ComponentLibrary/AvatarBase',
id: __filename, id: __filename,
component: BaseAvatar, component: AvatarBase,
parameters: { parameters: {
docs: { docs: {
page: README, page: README,
@ -43,7 +43,7 @@ export default {
argTypes: { argTypes: {
size: { size: {
control: 'select', control: 'select',
options: Object.values(SIZES), options: Object.values(AVATAR_BASE_SIZES),
}, },
color: { color: {
options: Object.values(TEXT_COLORS), options: Object.values(TEXT_COLORS),
@ -85,40 +85,40 @@ export default {
}, },
}, },
args: { args: {
size: SIZES.MD, size: AVATAR_BASE_SIZES.MD,
color: COLORS.TEXT_DEFAULT, color: COLORS.TEXT_DEFAULT,
backgroundColor: COLORS.BACKGROUND_ALTERNATIVE, backgroundColor: COLORS.BACKGROUND_ALTERNATIVE,
borderColor: COLORS.BORDER_DEFAULT, borderColor: COLORS.BORDER_DEFAULT,
}, },
}; };
export const DefaultStory = (args) => <BaseAvatar {...args}>B</BaseAvatar>; export const DefaultStory = (args) => <AvatarBase {...args}>B</AvatarBase>;
DefaultStory.storyName = 'Default'; DefaultStory.storyName = 'Default';
export const Size = (args) => ( export const Size = (args) => (
<Box display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.BASELINE} gap={1}> <Box display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.BASELINE} gap={1}>
<BaseAvatar {...args} size={SIZES.XS} /> <AvatarBase {...args} size={AVATAR_BASE_SIZES.XS} />
<BaseAvatar {...args} size={SIZES.SM} /> <AvatarBase {...args} size={AVATAR_BASE_SIZES.SM} />
<BaseAvatar {...args} size={SIZES.MD} /> <AvatarBase {...args} size={AVATAR_BASE_SIZES.MD} />
<BaseAvatar {...args} size={SIZES.LG} /> <AvatarBase {...args} size={AVATAR_BASE_SIZES.LG} />
<BaseAvatar {...args} size={SIZES.XL} /> <AvatarBase {...args} size={AVATAR_BASE_SIZES.XL} />
</Box> </Box>
); );
export const Children = (args) => ( export const Children = (args) => (
<Box display={DISPLAY.FLEX} gap={1}> <Box display={DISPLAY.FLEX} gap={1}>
<BaseAvatar {...args}> <AvatarBase {...args}>
<img src="./images/eth_logo.svg" /> <img src="./images/eth_logo.svg" />
</BaseAvatar> </AvatarBase>
<BaseAvatar {...args}> <AvatarBase {...args}>
<img width="100%" src="./images/arbitrum.svg" /> <img width="100%" src="./images/arbitrum.svg" />
</BaseAvatar> </AvatarBase>
<BaseAvatar {...args}> <AvatarBase {...args}>
<img width="100%" src="./images/avax-token.png" /> <img width="100%" src="./images/avax-token.png" />
</BaseAvatar> </AvatarBase>
<BaseAvatar {...args}>A</BaseAvatar> <AvatarBase {...args}>A</AvatarBase>
<BaseAvatar <AvatarBase
{...args} {...args}
backgroundColor={COLORS.INFO_MUTED} backgroundColor={COLORS.INFO_MUTED}
borderColor={COLORS.INFO_MUTED} borderColor={COLORS.INFO_MUTED}
@ -127,28 +127,28 @@ export const Children = (args) => (
className="fa fa-user" className="fa fa-user"
style={{ color: 'var(--color-info-default)' }} style={{ color: 'var(--color-info-default)' }}
/> />
</BaseAvatar> </AvatarBase>
</Box> </Box>
); );
export const ColorBackgroundColorAndBorderColor = (args) => ( export const ColorBackgroundColorAndBorderColor = (args) => (
<Box display={DISPLAY.FLEX} gap={1}> <Box display={DISPLAY.FLEX} gap={1}>
<BaseAvatar {...args}>B</BaseAvatar> <AvatarBase {...args}>B</AvatarBase>
<BaseAvatar <AvatarBase
{...args} {...args}
backgroundColor={COLORS.GOERLI} backgroundColor={COLORS.GOERLI}
borderColor={COLORS.GOERLI} borderColor={COLORS.GOERLI}
color={COLORS.PRIMARY_INVERSE} // TO DO: Update once test network colors have been added to design tokens color={COLORS.PRIMARY_INVERSE}
> >
G G
</BaseAvatar> </AvatarBase>
<BaseAvatar <AvatarBase
{...args} {...args}
backgroundColor={COLORS.SEPOLIA} backgroundColor={COLORS.SEPOLIA}
borderColor={COLORS.SEPOLIA} borderColor={COLORS.SEPOLIA}
color={COLORS.PRIMARY_INVERSE} // TO DO: Update once test network colors have been added to design tokens color={COLORS.PRIMARY_INVERSE}
> >
S S
</BaseAvatar> </AvatarBase>
</Box> </Box>
); );

@ -0,0 +1,124 @@
/* eslint-disable jest/require-top-level-describe */
import { render, screen } from '@testing-library/react';
import React from 'react';
import { COLORS } from '../../../helpers/constants/design-system';
import { AvatarBase } from './avatar-base';
describe('AvatarBase', () => {
it('should render correctly', () => {
const { getByTestId, container } = render(
<AvatarBase data-testid="avatar-base" />,
);
expect(getByTestId('avatar-base')).toBeDefined();
expect(container).toMatchSnapshot();
});
it('should render with different size classes', () => {
const { getByTestId } = render(
<>
<AvatarBase size="xs" data-testid="avatar-base-xs" />
<AvatarBase size="sm" data-testid="avatar-base-sm" />
<AvatarBase size="md" data-testid="avatar-base-md" />
<AvatarBase size="lg" data-testid="avatar-base-lg" />
<AvatarBase size="xl" data-testid="avatar-base-xl" />
</>,
);
expect(getByTestId('avatar-base-xs')).toHaveClass(
'mm-avatar-base--size-xs',
);
expect(getByTestId('avatar-base-sm')).toHaveClass(
'mm-avatar-base--size-sm',
);
expect(getByTestId('avatar-base-md')).toHaveClass(
'mm-avatar-base--size-md',
);
expect(getByTestId('avatar-base-lg')).toHaveClass(
'mm-avatar-base--size-lg',
);
expect(getByTestId('avatar-base-xl')).toHaveClass(
'mm-avatar-base--size-xl',
);
});
// className
it('should render with custom className', () => {
const { getByTestId } = render(
<AvatarBase data-testid="avatar-base" className="test-class" />,
);
expect(getByTestId('avatar-base')).toHaveClass('test-class');
});
// children
it('should render children', () => {
render(
<AvatarBase data-testid="avatar-base">
<img width="100%" src="./images/arbitrum.svg" />
</AvatarBase>,
);
const image = screen.getByRole('img');
expect(image).toBeDefined();
expect(image).toHaveAttribute('src', './images/arbitrum.svg');
});
// color
it('should render with different colors', () => {
const { getByTestId } = render(
<>
<AvatarBase
color={COLORS.SUCCESS_DEFAULT}
data-testid={COLORS.SUCCESS_DEFAULT}
/>
<AvatarBase
color={COLORS.ERROR_DEFAULT}
data-testid={COLORS.ERROR_DEFAULT}
/>
</>,
);
expect(getByTestId(COLORS.SUCCESS_DEFAULT)).toHaveClass(
`box--color-${COLORS.SUCCESS_DEFAULT}`,
);
expect(getByTestId(COLORS.ERROR_DEFAULT)).toHaveClass(
`box--color-${COLORS.ERROR_DEFAULT}`,
);
});
// background color
it('should render with different background colors', () => {
const { getByTestId } = render(
<>
<AvatarBase
backgroundColor={COLORS.SUCCESS_DEFAULT}
data-testid={COLORS.SUCCESS_DEFAULT}
/>
<AvatarBase
backgroundColor={COLORS.ERROR_DEFAULT}
data-testid={COLORS.ERROR_DEFAULT}
/>
</>,
);
expect(getByTestId(COLORS.SUCCESS_DEFAULT)).toHaveClass(
`box--background-color-${COLORS.SUCCESS_DEFAULT}`,
);
expect(getByTestId(COLORS.ERROR_DEFAULT)).toHaveClass(
`box--background-color-${COLORS.ERROR_DEFAULT}`,
);
});
// border color
it('should render with different border colors', () => {
const { getByTestId } = render(
<>
<AvatarBase
borderColor={COLORS.SUCCESS_DEFAULT}
data-testid={COLORS.SUCCESS_DEFAULT}
/>
<AvatarBase
borderColor={COLORS.ERROR_DEFAULT}
data-testid={COLORS.ERROR_DEFAULT}
/>
</>,
);
expect(getByTestId(COLORS.SUCCESS_DEFAULT)).toHaveClass(
`box--border-color-${COLORS.SUCCESS_DEFAULT}`,
);
expect(getByTestId(COLORS.ERROR_DEFAULT)).toHaveClass(
`box--border-color-${COLORS.ERROR_DEFAULT}`,
);
});
});

@ -0,0 +1,2 @@
export { AvatarBase } from './avatar-base';
export { AVATAR_BASE_SIZES } from './avatar-base.constants';

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import { BaseAvatar } from '../base-avatar'; import { AvatarBase } from '../avatar-base';
import Box from '../../ui/box/box'; import Box from '../../ui/box/box';
import { ICON_NAMES, Icon } from '../icon'; import { ICON_NAMES, Icon } from '../icon';
import { import {
@ -23,7 +23,7 @@ export const AvatarFavicon = ({
...props ...props
}) => { }) => {
return ( return (
<BaseAvatar <AvatarBase
size={size} size={size}
display={DISPLAY.FLEX} display={DISPLAY.FLEX}
alignItems={ALIGN_ITEMS.CENTER} alignItems={ALIGN_ITEMS.CENTER}
@ -42,7 +42,7 @@ export const AvatarFavicon = ({
{...fallbackIconProps} {...fallbackIconProps}
/> />
)} )}
</BaseAvatar> </AvatarBase>
); );
}; };

@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import { BaseAvatar } from '../base-avatar'; import { AvatarBase } from '../avatar-base';
import Box from '../../ui/box/box'; import Box from '../../ui/box/box';
import { import {
@ -36,7 +36,7 @@ export const AvatarNetwork = ({
}; };
return ( return (
<BaseAvatar <AvatarBase
size={size} size={size}
display={DISPLAY.FLEX} display={DISPLAY.FLEX}
alignItems={ALIGN_ITEMS.CENTER} alignItems={ALIGN_ITEMS.CENTER}
@ -73,7 +73,7 @@ export const AvatarNetwork = ({
/> />
</> </>
)} )}
</BaseAvatar> </AvatarBase>
); );
}; };

@ -94,14 +94,14 @@ export const ColorBackgroundColorAndBorderColor = (args) => (
backgroundColor={COLORS.GOERLI} backgroundColor={COLORS.GOERLI}
borderColor={COLORS.GOERLI} borderColor={COLORS.GOERLI}
networkName="G" networkName="G"
color={COLORS.PRIMARY_INVERSE} // This will have to be added to the BaseAvatar component as a prop so we can change the color of the text and to the base avatar color={COLORS.PRIMARY_INVERSE} // This will have to be added to the AvatarBase component as a prop so we can change the color of the text and to the base avatar
/> />
<AvatarNetwork <AvatarNetwork
{...args} {...args}
backgroundColor={COLORS.SEPOLIA} backgroundColor={COLORS.SEPOLIA}
borderColor={COLORS.SEPOLIA} borderColor={COLORS.SEPOLIA}
networkName="G" networkName="G"
color={COLORS.PRIMARY_INVERSE} // This will have to be added to the BaseAvatar component as a prop so we can change the color of the text and to the base avatar color={COLORS.PRIMARY_INVERSE} // This will have to be added to the AvatarBase component as a prop so we can change the color of the text and to the base avatar
/> />
</Box> </Box>
); );

@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Box from '../../ui/box/box'; import Box from '../../ui/box/box';
import { BaseAvatar } from '../base-avatar'; import { AvatarBase } from '../avatar-base';
import { import {
COLORS, COLORS,
@ -36,7 +36,7 @@ export const AvatarToken = ({
const fallbackString = tokenName && tokenName[0] ? tokenName[0] : '?'; const fallbackString = tokenName && tokenName[0] ? tokenName[0] : '?';
return ( return (
<BaseAvatar <AvatarBase
size={size} size={size}
display={DISPLAY.FLEX} display={DISPLAY.FLEX}
alignItems={ALIGN_ITEMS.CENTER} alignItems={ALIGN_ITEMS.CENTER}
@ -71,7 +71,7 @@ export const AvatarToken = ({
/> />
</> </>
)} )}
</BaseAvatar> </AvatarBase>
); );
}; };

@ -94,14 +94,14 @@ export const ColorBackgroundColorAndBorderColor = (args) => (
backgroundColor={COLORS.GOERLI} backgroundColor={COLORS.GOERLI}
borderColor={COLORS.GOERLI} borderColor={COLORS.GOERLI}
tokenName="G" tokenName="G"
color={COLORS.PRIMARY_INVERSE} // TODO: This will have to be added to the BaseAvatar component as a prop so we can change the color of the text and to the base avatar color={COLORS.PRIMARY_INVERSE} // TODO: This will have to be added to the AvatarBase component as a prop so we can change the color of the text and to the base avatar
/> />
<AvatarToken <AvatarToken
{...args} {...args}
backgroundColor={COLORS.SEPOLIA} backgroundColor={COLORS.SEPOLIA}
borderColor={COLORS.SEPOLIA} borderColor={COLORS.SEPOLIA}
tokenName="G" tokenName="G"
color={COLORS.PRIMARY_INVERSE} // TODO: This will have to be added to the BaseAvatar component as a prop so we can change the color of the text and to the base avatar color={COLORS.PRIMARY_INVERSE} // TODO: This will have to be added to the AvatarBase component as a prop so we can change the color of the text and to the base avatar
/> />
</Box> </Box>
); );

@ -1,53 +0,0 @@
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { BaseAvatar } from './base-avatar';
### This is a base component. It should not be used in your feature code directly but as a "base" for other UI components
# BaseAvatar
The `BaseAvatar` is a wrapper component responsible for enforcing dimensions and border radius for Avatar components
<Canvas>
<Story id="ui-components-component-library-base-avatar-base-avatar-stories-js--default-story" />
</Canvas>
## Props
The `BaseAvatar` accepts all props below as well as all [Box](/ui-components-ui-box-box-stories-js--default-story) component props.
<ArgsTable of={BaseAvatar} />
### Size
Use the `size` prop to set the size of the `BaseAvatar`.
Possible sizes include:
- `xs` 16px
- `sm` 24px
- `md` 32px
- `lg` 40px
- `xl` 48px
Defaults to `md`
<Canvas>
<Story id="ui-components-component-library-base-avatar-base-avatar-stories-js--size" />
</Canvas>
### Children
The `BaseAvatar` component can contain images, icons or text
<Canvas>
<Story id="ui-components-component-library-base-avatar-base-avatar-stories-js--children" />
</Canvas>
### Color, Background Color And Border Color
Use the `color`, `backgroundColor` and `borderColor` props to set the text color, background-color and border-color of the s of the `BaseAvatar`.
<Canvas>
<Story id="ui-components-component-library-base-avatar-base-avatar-stories-js--color-background-color-and-border-color" />
</Canvas>

@ -1,28 +0,0 @@
/* eslint-disable jest/require-top-level-describe */
import { render } from '@testing-library/react';
import React from 'react';
import { BaseAvatar } from './base-avatar';
describe('BaseAvatar', () => {
it('should render correctly', () => {
const { getByTestId } = render(<BaseAvatar data-testid="base-avatar" />);
expect(getByTestId('base-avatar')).toBeDefined();
});
it('should render with different size classes', () => {
const { getByTestId } = render(
<>
<BaseAvatar size="xs" data-testid="base-avatar-xs" />
<BaseAvatar size="sm" data-testid="base-avatar-sm" />
<BaseAvatar size="md" data-testid="base-avatar-md" />
<BaseAvatar size="lg" data-testid="base-avatar-lg" />
<BaseAvatar size="xl" data-testid="base-avatar-xl" />
</>,
);
expect(getByTestId('base-avatar-xs')).toHaveClass('base-avatar--size-xs');
expect(getByTestId('base-avatar-sm')).toHaveClass('base-avatar--size-sm');
expect(getByTestId('base-avatar-md')).toHaveClass('base-avatar--size-md');
expect(getByTestId('base-avatar-lg')).toHaveClass('base-avatar--size-lg');
expect(getByTestId('base-avatar-xl')).toHaveClass('base-avatar--size-xl');
});
});

@ -1 +0,0 @@
export { BaseAvatar } from './base-avatar';

@ -9,7 +9,7 @@
@import 'icon/icon'; @import 'icon/icon';
@import 'label/label'; @import 'label/label';
@import 'tag/tag'; @import 'tag/tag';
@import 'base-avatar/base-avatar'; @import 'avatar-base/avatar-base';
@import 'avatar-account/avatar-account'; @import 'avatar-account/avatar-account';
@import 'avatar-favicon/avatar-favicon'; @import 'avatar-favicon/avatar-favicon';
@import 'avatar-network/avatar-network'; @import 'avatar-network/avatar-network';

@ -3,7 +3,7 @@ export { AvatarFavicon } from './avatar-favicon';
export { AvatarNetwork } from './avatar-network'; export { AvatarNetwork } from './avatar-network';
export { AvatarToken } from './avatar-token'; export { AvatarToken } from './avatar-token';
export { AvatarWithBadge } from './avatar-with-badge'; export { AvatarWithBadge } from './avatar-with-badge';
export { BaseAvatar } from './base-avatar'; export { AvatarBase } from './avatar-base';
export { Button } from './button'; export { Button } from './button';
export { ButtonBase } from './button-base'; export { ButtonBase } from './button-base';
export { ButtonIcon } from './button-icon'; export { ButtonIcon } from './button-icon';

@ -7,7 +7,7 @@ exports[`PickerNetwork should render the label inside the PickerNetwork 1`] = `
data-testid="picker-network" data-testid="picker-network"
> >
<div <div
class="box base-avatar base-avatar--size-xs avatar-network mm-picker-network__avatar-network box--display-flex box--flex-direction-row box--justify-content-center box--align-items-center box--color-text-default box--background-color-background-alternative box--border-color-transparent box--border-style-solid box--border-width-1" class="box mm-avatar-base mm-avatar-base--size-xs avatar-network mm-picker-network__avatar-network box--display-flex box--flex-direction-row box--justify-content-center box--align-items-center box--color-text-default box--background-color-background-alternative box--border-color-transparent box--border-style-solid box--border-width-1"
> >
I I
</div> </div>

@ -7,7 +7,7 @@ exports[`TagUrl should render the label inside the TagUrl 1`] = `
data-testid="tag-url" data-testid="tag-url"
> >
<div <div
class="box base-avatar base-avatar--size-md avatar-favicon box--display-flex box--flex-direction-row box--justify-content-center box--align-items-center box--color-text-default box--background-color-background-alternative box--border-color-transparent box--border-style-solid box--border-width-1" class="box mm-avatar-base mm-avatar-base--size-md avatar-favicon box--display-flex box--flex-direction-row box--justify-content-center box--align-items-center box--color-text-default box--background-color-background-alternative box--border-color-transparent box--border-style-solid box--border-width-1"
> >
<div <div
aria-label="avatar-favicon" aria-label="avatar-favicon"

Loading…
Cancel
Save