Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding avatar icon to design system react #420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

georgewrmarshall
Copy link
Contributor

@georgewrmarshall georgewrmarshall commented Feb 5, 2025

Description

This PR adds AvatarIcon to design system react

  • Five predefined sizes (Xs, Sm, Md, Lg, Xl) with corresponding icon sizes
  • Five severity levels (Default, Info, Success, Error, Warning) with appropriate background and icon colors
  • Customizable icon properties and additional className support
  • Comprehensive Storybook documentation and test coverage

The component is built on top of the existing AvatarBase and Icon components, ensuring consistency with the design system.

Related issues

Fixes: #370

Manual testing steps

  1. Go to Storybook and navigate to the AvatarIcon component
  2. Test different icon names using the IconName story
  3. Verify all size variations in the Size story
  4. Check all severity levels in the Severity story
  5. Test custom className and iconProps functionality

Screenshots/Recordings

Before

N/A (New component)

After

after720.mov

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Comment on lines +6 to +15
export const AVATAR_ICON_SIZE_TO_ICON_SIZE_CLASSNAME_MAP: Record<
AvatarIconSize,
IconSize
> = {
[AvatarIconSize.Xs]: IconSize.Xs, // 16px avatar -> 12px icon
[AvatarIconSize.Sm]: IconSize.Sm, // 24px avatar -> 16px icon
[AvatarIconSize.Md]: IconSize.Md, // 32px avatar -> 20px icon
[AvatarIconSize.Lg]: IconSize.Lg, // 40px avatar -> 24px icon
[AvatarIconSize.Xl]: IconSize.Xl, // 48px avatar -> 32px icon
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maps avatar size to icon size

Comment on lines +17 to +41
export const AVATAR_ICON_SEVERITY_CLASSNAME_MAP: Record<
AvatarIconSeverity,
{ background: string; iconColor: IconColor }
> = {
[AvatarIconSeverity.Default]: {
background: 'bg-background-muted',
iconColor: IconColor.IconAlternative,
},
[AvatarIconSeverity.Info]: {
background: 'bg-info-muted',
iconColor: IconColor.InfoDefault,
},
[AvatarIconSeverity.Success]: {
background: 'bg-success-muted',
iconColor: IconColor.SuccessDefault,
},
[AvatarIconSeverity.Error]: {
background: 'bg-error-muted',
iconColor: IconColor.ErrorDefault,
},
[AvatarIconSeverity.Warning]: {
background: 'bg-warning-muted',
iconColor: IconColor.WarningDefault,
},
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maps severity prop to icon color and background color

Comment on lines +43 to +52
export const AVATAR_ICON_TO_AVATAR_BASE_SIZE_MAP: Record<
AvatarIconSize,
AvatarBaseSize
> = {
[AvatarIconSize.Xs]: AvatarBaseSize.Xs,
[AvatarIconSize.Sm]: AvatarBaseSize.Sm,
[AvatarIconSize.Md]: AvatarBaseSize.Md,
[AvatarIconSize.Lg]: AvatarBaseSize.Lg,
[AvatarIconSize.Xl]: AvatarBaseSize.Xl,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mapping the new AvatarIconSize enum to AvatarBaseSize. The circular dependency issue has finally caught up with me, so I'll stop exporting as—it seems to be causing circular dependencies and undefined issues.

Comment on lines +14 to +35
export enum AvatarIconSize {
/**
* Extra small size (16px)
*/
Xs = 'xs',
/**
* Small size (24px)
*/
Sm = 'sm',
/**
* Medium size (32px)
*/
Md = 'md',
/**
* Large size (40px)
*/
Lg = 'lg',
/**
* Extra large size (48px)
*/
Xl = 'xl',
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, I exported AvatarBaseSize as AvatarIconSize from the AvatarIcon index, but it caused circular dependencies. After some consideration, I think this is bad practice and could lead to issues, so we'll need to revert to defining individual enums.


# AvatarIcon

Avatar reserved for representing static icons inside of an avatar.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description matches figma


Avatar reserved for representing static icons inside of an avatar.

> Note: For icon buttons, use the [ButtonIcon](/docs/react-components-buttonicon--docs) component.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding not as per the insight report

@@ -38,3 +38,6 @@ export type { ButtonIconProps } from './button-icon';

export { AvatarBase, AvatarBaseSize } from './avatar-base';
export type { AvatarBaseProps } from './avatar-base';

export { AvatarIcon, AvatarIconSize, AvatarIconSeverity } from './avatar-icon';
export type { AvatarIconProps } from './avatar-icon';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exporting from root index

@georgewrmarshall georgewrmarshall marked this pull request as ready for review February 5, 2025 03:17
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner February 5, 2025 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[React]: Create AvatarIcon component in shared UI component library
1 participant