mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
add avatar icon component (#16755)
* add avatar icon component * add avatar icon severities * avatar icon docs * update tests and remove stylesheet * aria label * remove aria label * update test * remove aria label * iconName prop type string * Update ui/components/component-library/avatar-icon/README.mdx Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/components/component-library/avatar-icon/README.mdx Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/components/component-library/avatar-icon/avatar-icon.js Co-authored-by: George Marshall <george.marshall@consensys.net> * Update ui/components/component-library/avatar-icon/avatar-icon.stories.js Co-authored-by: George Marshall <george.marshall@consensys.net> * marginSizeControlOptions Co-authored-by: George Marshall <george.marshall@consensys.net>
This commit is contained in:
parent
7d3b1d08da
commit
c9560b75f2
97
ui/components/component-library/avatar-icon/README.mdx
Normal file
97
ui/components/component-library/avatar-icon/README.mdx
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
|
||||||
|
|
||||||
|
import { AvatarBase } from '../';
|
||||||
|
import { AvatarIcon } from './avatar-icon';
|
||||||
|
|
||||||
|
# AvatarIcon
|
||||||
|
|
||||||
|
The `AvatarIcon` is an avatar component that renders only an icon inside and is built off the [AvatarBase](/docs/ui-components-component-library-avatar-base-avatar-base-stories-js--default-story#props) component
|
||||||
|
|
||||||
|
<Canvas>
|
||||||
|
<Story id="ui-components-component-library-avatar-icon-avatar-icon-stories-js--default-story" />
|
||||||
|
</Canvas>
|
||||||
|
|
||||||
|
## Props
|
||||||
|
|
||||||
|
The `AvatarIcon` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story) component props
|
||||||
|
|
||||||
|
<ArgsTable of={AvatarIcon} />
|
||||||
|
|
||||||
|
`AvatarIcon` accepts all [AvatarBase](/docs/ui-components-component-library-avatar-base-avatar-base-stories-js--default-story#props)
|
||||||
|
component props
|
||||||
|
|
||||||
|
<ArgsTable of={AvatarBase} />
|
||||||
|
|
||||||
|
### Size
|
||||||
|
|
||||||
|
Use the `size` prop and the `SIZES` object from `./ui/helpers/constants/design-system.js` to change the size of `AvatarIcon`
|
||||||
|
|
||||||
|
Optional: `AVATAR_ICON_SIZES` from `./ui/components/component-library` object can be used instead of `SIZES`
|
||||||
|
|
||||||
|
Possible sizes include:
|
||||||
|
|
||||||
|
- `SIZES.XS` 16px
|
||||||
|
- `SIZES.SM` 24px
|
||||||
|
- `SIZES.MD` 32px
|
||||||
|
- `SIZES.LG` 40px
|
||||||
|
- `SIZES.XL` 48px
|
||||||
|
|
||||||
|
Defaults to `SIZES.MD`
|
||||||
|
|
||||||
|
<Canvas>
|
||||||
|
<Story id="ui-components-component-library-avatar-icon-avatar-icon-stories-js--size" />
|
||||||
|
</Canvas>
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import { SIZES } from '../../../helpers/constants/design-system';
|
||||||
|
import { AvatarIcon, ICON_NAMES } from '../ui/component-library';
|
||||||
|
|
||||||
|
<AvatarIcon size={SIZES.XS} />
|
||||||
|
<AvatarIcon size={SIZES.SM} />
|
||||||
|
<AvatarIcon size={SIZES.MD} />
|
||||||
|
<AvatarIcon size={SIZES.LG} />
|
||||||
|
<AvatarIcon size={SIZES.XL} />
|
||||||
|
```
|
||||||
|
|
||||||
|
### Icon Name<span style={{ color: 'red' }}>\*</span>
|
||||||
|
|
||||||
|
Use the required `iconName` prop with `ICON_NAMES` object from `./ui/components/component-library` to select icon
|
||||||
|
|
||||||
|
Use the [IconSearch](/story/ui-components-component-library-icon-icon-stories-js--default-story) story to find the icon you want to use.
|
||||||
|
|
||||||
|
<Canvas>
|
||||||
|
<Story id="ui-components-component-library-avatar-icon-avatar-icon-stories-js--icon-name" />
|
||||||
|
</Canvas>
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import { AvatarIcon, ICON_NAMES } from '../ui/component-library';
|
||||||
|
|
||||||
|
<AvatarIcon iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE} />
|
||||||
|
<AvatarIcon iconName={ICON_NAMES.CHECK_CIRCLE_ON_FILLED} />
|
||||||
|
<AvatarIcon iconName={ICON_NAMES.INFO_FILLED} />
|
||||||
|
<AvatarIcon iconName={ICON_NAMES.WARNING_FILLED} />
|
||||||
|
<AvatarIcon iconName={ICON_NAMES.DANGER_FILLED} />
|
||||||
|
```
|
||||||
|
|
||||||
|
### Color and Background Color
|
||||||
|
|
||||||
|
Use the `color` and `backgroundColor` props with the `COLORS` object from `./ui/helpers/constants/design-system.js` to change the icon color and background color of `AvatarIcon`
|
||||||
|
|
||||||
|
`color` default: `COLORS.COLORS.PRIMARY_DEFAULT`
|
||||||
|
`backgroundColor` default: `COLORS.COLORS.PRIMARY_MUTED`
|
||||||
|
|
||||||
|
<Canvas>
|
||||||
|
<Story id="ui-components-component-library-avatar-icon-avatar-icon-stories-js--color-and-background-color" />
|
||||||
|
</Canvas>
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import { COLORS } from '../../../helpers/constants/design-system';
|
||||||
|
import { AvatarIcon } from '../ui/component-library';
|
||||||
|
|
||||||
|
<AvatarIcon color={COLORS.PRIMARY_DEFAULT} backgroundColor={BACKGROUND_COLORS.PRIMARY_MUTED} />
|
||||||
|
<AvatarIcon color={COLORS.PRIMARY_INVERSE} backgroundColor={BACKGROUND_COLORS.PRIMARY_DEFAULT} />
|
||||||
|
<AvatarIcon color={COLORS.SUCCESS_DEFAULT} backgroundColor={BACKGROUND_COLORS.SUCCESS_MUTED} />
|
||||||
|
<AvatarIcon color={COLORS.INFO_DEFAULT} backgroundColor={BACKGROUND_COLORS.INFO_MUTED} />
|
||||||
|
<AvatarIcon color={COLORS.WARNING_DEFAULT} backgroundColor={BACKGROUND_COLORS.WARNING_MUTED} />
|
||||||
|
<AvatarIcon color={COLORS.ERROR_DEFAULT} backgroundColor={BACKGROUND_COLORS.ERROR_MUTED} />
|
||||||
|
```
|
@ -0,0 +1,15 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`AvatarIcon should render correctly 1`] = `
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="box mm-avatar-base mm-avatar-base--size-md mm-avatar-icon box--display-flex box--flex-direction-row box--justify-content-center box--align-items-center box--color-primary-default box--background-color-primary-muted box--border-color-transparent box--border-style-solid box--border-width-1"
|
||||||
|
data-testid="avatar-icon"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="box mm-icon mm-icon--size-md box--flex-direction-row box--color-inherit"
|
||||||
|
style="mask-image: url('./images/icons/icon-swap-horizontal-outline.svg');"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
@ -0,0 +1,9 @@
|
|||||||
|
import { SIZES } from '../../../helpers/constants/design-system';
|
||||||
|
|
||||||
|
export const AVATAR_ICON_SIZES = {
|
||||||
|
XS: SIZES.XS,
|
||||||
|
SM: SIZES.SM,
|
||||||
|
MD: SIZES.MD,
|
||||||
|
LG: SIZES.LG,
|
||||||
|
XL: SIZES.XL,
|
||||||
|
};
|
81
ui/components/component-library/avatar-icon/avatar-icon.js
Normal file
81
ui/components/component-library/avatar-icon/avatar-icon.js
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
import {
|
||||||
|
COLORS,
|
||||||
|
BORDER_COLORS,
|
||||||
|
SIZES,
|
||||||
|
DISPLAY,
|
||||||
|
ALIGN_ITEMS,
|
||||||
|
JUSTIFY_CONTENT,
|
||||||
|
} from '../../../helpers/constants/design-system';
|
||||||
|
|
||||||
|
import Box from '../../ui/box/box';
|
||||||
|
|
||||||
|
import { Icon } from '../icon';
|
||||||
|
import { AvatarBase } from '../avatar-base';
|
||||||
|
|
||||||
|
import { AVATAR_ICON_SIZES } from './avatar-icon.constants';
|
||||||
|
|
||||||
|
export const AvatarIcon = ({
|
||||||
|
size = SIZES.MD,
|
||||||
|
color = COLORS.PRIMARY_DEFAULT,
|
||||||
|
backgroundColor = COLORS.PRIMARY_MUTED,
|
||||||
|
className,
|
||||||
|
iconProps,
|
||||||
|
iconName,
|
||||||
|
...props
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<AvatarBase
|
||||||
|
size={size}
|
||||||
|
display={DISPLAY.FLEX}
|
||||||
|
alignItems={ALIGN_ITEMS.CENTER}
|
||||||
|
justifyContent={JUSTIFY_CONTENT.CENTER}
|
||||||
|
color={color}
|
||||||
|
backgroundColor={backgroundColor}
|
||||||
|
borderColor={BORDER_COLORS.TRANSPARENT}
|
||||||
|
className={classnames('mm-avatar-icon', className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<Icon color={COLORS.INHERIT} name={iconName} size={size} {...iconProps} />
|
||||||
|
</AvatarBase>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
AvatarIcon.propTypes = {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* The name of the icon to display. Should be one of ICON_NAMES
|
||||||
|
*/
|
||||||
|
iconName: PropTypes.string.isRequired, // Can't set PropTypes.oneOf(ICON_NAMES) because ICON_NAMES is an environment variable
|
||||||
|
/**
|
||||||
|
* Props for the icon inside AvatarIcon. All Icon props can be used
|
||||||
|
*/
|
||||||
|
iconProps: PropTypes.shape(Icon.PropTypes),
|
||||||
|
/**
|
||||||
|
* The size of the AvatarIcon
|
||||||
|
* Possible values could be 'SIZES.XS' 16px, 'SIZES.SM' 24px, 'SIZES.MD' 32px, 'SIZES.LG' 40px, 'SIZES.XL' 48px
|
||||||
|
* Defaults to SIZES.MD
|
||||||
|
*/
|
||||||
|
size: PropTypes.oneOf(Object.values(AVATAR_ICON_SIZES)),
|
||||||
|
/**
|
||||||
|
* The background color of the AvatarIcon
|
||||||
|
* Defaults to COLORS.PRIMARY_MUTED
|
||||||
|
*/
|
||||||
|
backgroundColor: Box.propTypes.backgroundColor,
|
||||||
|
/**
|
||||||
|
* The color of the text inside the AvatarIcon
|
||||||
|
* Defaults to COLORS.PRIMARY_DEFAULT
|
||||||
|
*/
|
||||||
|
color: Box.propTypes.color,
|
||||||
|
/**
|
||||||
|
* Additional classNames to be added to the AvatarIcon
|
||||||
|
*/
|
||||||
|
className: PropTypes.string,
|
||||||
|
/**
|
||||||
|
* AvatarIcon also accepts all Box props including but not limited to
|
||||||
|
* className, as(change root element of HTML element) and margin props
|
||||||
|
*/
|
||||||
|
...Box.propTypes,
|
||||||
|
};
|
@ -0,0 +1,185 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
SIZES,
|
||||||
|
DISPLAY,
|
||||||
|
ALIGN_ITEMS,
|
||||||
|
COLORS,
|
||||||
|
BACKGROUND_COLORS,
|
||||||
|
} from '../../../helpers/constants/design-system';
|
||||||
|
|
||||||
|
import Box from '../../ui/box/box';
|
||||||
|
|
||||||
|
import { ICON_NAMES } from '..';
|
||||||
|
|
||||||
|
import README from './README.mdx';
|
||||||
|
import { AvatarIcon, AVATAR_ICON_SIZES } from '.';
|
||||||
|
|
||||||
|
const marginSizeControlOptions = [
|
||||||
|
undefined,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
8,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
11,
|
||||||
|
12,
|
||||||
|
'auto',
|
||||||
|
];
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Components/ComponentLibrary/AvatarIcon',
|
||||||
|
id: __filename,
|
||||||
|
component: AvatarIcon,
|
||||||
|
parameters: {
|
||||||
|
docs: {
|
||||||
|
page: README,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
argTypes: {
|
||||||
|
iconName: {
|
||||||
|
options: Object.values(ICON_NAMES),
|
||||||
|
control: 'select',
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
control: 'select',
|
||||||
|
options: Object.values(AVATAR_ICON_SIZES),
|
||||||
|
},
|
||||||
|
backgroundColor: {
|
||||||
|
control: 'select',
|
||||||
|
options: Object.values(BACKGROUND_COLORS),
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
control: 'select',
|
||||||
|
options: Object.values(COLORS),
|
||||||
|
},
|
||||||
|
className: {
|
||||||
|
control: 'text',
|
||||||
|
},
|
||||||
|
marginTop: {
|
||||||
|
options: marginSizeControlOptions,
|
||||||
|
control: 'select',
|
||||||
|
table: { category: 'box props' },
|
||||||
|
},
|
||||||
|
marginRight: {
|
||||||
|
options: marginSizeControlOptions,
|
||||||
|
control: 'select',
|
||||||
|
table: { category: 'box props' },
|
||||||
|
},
|
||||||
|
marginBottom: {
|
||||||
|
options: marginSizeControlOptions,
|
||||||
|
control: 'select',
|
||||||
|
table: { category: 'box props' },
|
||||||
|
},
|
||||||
|
marginLeft: {
|
||||||
|
options: marginSizeControlOptions,
|
||||||
|
control: 'select',
|
||||||
|
table: { category: 'box props' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
args: {
|
||||||
|
size: SIZES.MD,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const Template = (args) => {
|
||||||
|
return <AvatarIcon iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE} {...args} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DefaultStory = Template.bind({});
|
||||||
|
DefaultStory.storyName = 'Default';
|
||||||
|
|
||||||
|
export const Size = (args) => (
|
||||||
|
<Box display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.BASELINE} gap={1}>
|
||||||
|
<AvatarIcon {...args} size={SIZES.XS} />
|
||||||
|
<AvatarIcon {...args} size={SIZES.SM} />
|
||||||
|
<AvatarIcon {...args} size={SIZES.MD} />
|
||||||
|
<AvatarIcon {...args} size={SIZES.LG} />
|
||||||
|
<AvatarIcon {...args} size={SIZES.XL} />
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
Size.args = {
|
||||||
|
iconName: ICON_NAMES.CHECK_CIRCLE_ON_FILLED,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const IconName = (args) => (
|
||||||
|
<Box display={DISPLAY.FLEX} gap={1}>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.PRIMARY_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.PRIMARY_MUTED}
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.SUCCESS_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.SUCCESS_MUTED}
|
||||||
|
iconName={ICON_NAMES.CHECK_CIRCLE_ON_FILLED}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.INFO_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.INFO_MUTED}
|
||||||
|
iconName={ICON_NAMES.INFO_FILLED}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.WARNING_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.WARNING_MUTED}
|
||||||
|
iconName={ICON_NAMES.WARNING_FILLED}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.ERROR_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.ERROR_MUTED}
|
||||||
|
iconName={ICON_NAMES.DANGER_FILLED}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ColorAndBackgroundColor = (args) => (
|
||||||
|
<Box display={DISPLAY.FLEX} gap={1}>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.PRIMARY_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.PRIMARY_MUTED}
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.PRIMARY_INVERSE}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.PRIMARY_DEFAULT}
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.SUCCESS_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.SUCCESS_MUTED}
|
||||||
|
iconName={ICON_NAMES.CHECK_CIRCLE_ON_FILLED}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.INFO_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.INFO_MUTED}
|
||||||
|
iconName={ICON_NAMES.INFO_FILLED}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.WARNING_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.WARNING_MUTED}
|
||||||
|
iconName={ICON_NAMES.WARNING_FILLED}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
color={COLORS.ERROR_DEFAULT}
|
||||||
|
backgroundColor={BACKGROUND_COLORS.ERROR_MUTED}
|
||||||
|
iconName={ICON_NAMES.DANGER_FILLED}
|
||||||
|
{...args}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
105
ui/components/component-library/avatar-icon/avatar-icon.test.js
Normal file
105
ui/components/component-library/avatar-icon/avatar-icon.test.js
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/* eslint-disable jest/require-top-level-describe */
|
||||||
|
import { render } from '@testing-library/react';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { ICON_NAMES } from '..';
|
||||||
|
import { COLORS } from '../../../helpers/constants/design-system';
|
||||||
|
import { AvatarIcon, AVATAR_ICON_SIZES } from '.';
|
||||||
|
|
||||||
|
describe('AvatarIcon', () => {
|
||||||
|
it('should render correctly', () => {
|
||||||
|
const { getByTestId, container } = render(
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
data-testid="avatar-icon"
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(getByTestId('avatar-icon')).toBeDefined();
|
||||||
|
expect(container).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render with different size classes', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<>
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
size={AVATAR_ICON_SIZES.XS}
|
||||||
|
data-testid={AVATAR_ICON_SIZES.XS}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
size={AVATAR_ICON_SIZES.SM}
|
||||||
|
data-testid={AVATAR_ICON_SIZES.SM}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
size={AVATAR_ICON_SIZES.MD}
|
||||||
|
data-testid={AVATAR_ICON_SIZES.MD}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
size={AVATAR_ICON_SIZES.LG}
|
||||||
|
data-testid={AVATAR_ICON_SIZES.LG}
|
||||||
|
/>
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
size={AVATAR_ICON_SIZES.XL}
|
||||||
|
data-testid={AVATAR_ICON_SIZES.XL}
|
||||||
|
/>
|
||||||
|
</>,
|
||||||
|
);
|
||||||
|
expect(getByTestId(AVATAR_ICON_SIZES.XS)).toHaveClass(
|
||||||
|
`mm-avatar-base--size-${AVATAR_ICON_SIZES.XS}`,
|
||||||
|
);
|
||||||
|
expect(getByTestId(AVATAR_ICON_SIZES.SM)).toHaveClass(
|
||||||
|
`mm-avatar-base--size-${AVATAR_ICON_SIZES.SM}`,
|
||||||
|
);
|
||||||
|
expect(getByTestId(AVATAR_ICON_SIZES.MD)).toHaveClass(
|
||||||
|
`mm-avatar-base--size-${AVATAR_ICON_SIZES.MD}`,
|
||||||
|
);
|
||||||
|
expect(getByTestId(AVATAR_ICON_SIZES.LG)).toHaveClass(
|
||||||
|
`mm-avatar-base--size-${AVATAR_ICON_SIZES.LG}`,
|
||||||
|
);
|
||||||
|
expect(getByTestId(AVATAR_ICON_SIZES.XL)).toHaveClass(
|
||||||
|
`mm-avatar-base--size-${AVATAR_ICON_SIZES.XL}`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render with added classname', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
className="mm-avatar-icon--test"
|
||||||
|
data-testid="classname"
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(getByTestId('classname')).toHaveClass('mm-avatar-icon--test');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render with icon', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
iconProps={{ 'data-testid': 'avatar-icon' }}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByTestId('avatar-icon')).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render with success color icon and background color', () => {
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<AvatarIcon
|
||||||
|
iconName={ICON_NAMES.SWAP_HORIZONTAL_OUTLINE}
|
||||||
|
color={COLORS.SUCCESS_DEFAULT}
|
||||||
|
backgroundColor={COLORS.SUCCESS_MUTED}
|
||||||
|
data-testid="success"
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByTestId('success')).toHaveClass('box--color-success-default');
|
||||||
|
expect(getByTestId('success')).toHaveClass(
|
||||||
|
'box--background-color-success-muted',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
2
ui/components/component-library/avatar-icon/index.js
Normal file
2
ui/components/component-library/avatar-icon/index.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export { AvatarIcon } from './avatar-icon';
|
||||||
|
export { AVATAR_ICON_SIZES } from './avatar-icon.constants';
|
@ -1,5 +1,6 @@
|
|||||||
export { AvatarAccount } from './avatar-account';
|
export { AvatarAccount } from './avatar-account';
|
||||||
export { AvatarFavicon } from './avatar-favicon';
|
export { AvatarFavicon } from './avatar-favicon';
|
||||||
|
export { AvatarIcon, AVATAR_ICON_SIZES } from './avatar-icon';
|
||||||
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';
|
||||||
|
Loading…
Reference in New Issue
Block a user