Skip to content

feat: add avatar component#711

Merged
finalight merged 1 commit intov4from
feature/next-avatar
Jan 17, 2023
Merged

feat: add avatar component#711
finalight merged 1 commit intov4from
feature/next-avatar

Conversation

@finalight
Copy link
Copy Markdown
Contributor

No description provided.

@finalight finalight self-assigned this Jan 13, 2023
@finalight finalight force-pushed the feature/next-avatar branch 16 times, most recently from 029fbaf to bf2245b Compare January 16, 2023 13:48
Comment thread src/@next/Avatar/Avatar.tsx Outdated
export type AvatarSizeVariant = typeof AvatarSizeVariant[number];

export interface AvatarProps extends React.HTMLAttributes<HTMLDivElement> {
variant: AvatarBackgroundColorVariant;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should also be optional since we should define a default based on the Figma

Comment thread src/@next/Avatar/Avatar.tsx Outdated
initials?: string;
}

export const Avatar = ({ variant, size, initials, ...props }: AvatarProps) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

based on Figma, both variant and size have default values. we can define them here instead of adding logic on the passed props below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i've passed in the default value for the props

Comment thread src/@next/Avatar/Avatar.tsx
Comment thread src/@next/Avatar/AvatarStyle.tsx Outdated
const getAvatarBackgroundColor = (variant: AvatarBackgroundColorVariant) => {
if (!(variant in avatarBackgroundColor)) {
console.warn(
`${variant} is not a valid variant for the backgroud color, default will be used`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
`${variant} is not a valid variant for the backgroud color, default will be used`
`${variant} is not a valid variant for the background color, default will be used`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed the typo

Comment thread src/@next/Avatar/AvatarStyle.tsx Outdated
Comment on lines +20 to +45
const avatarSize: {
[variant in AvatarSizeVariant[number]]: number;
} = {
['large']: 60,
['medium']: 40,
};

const mobileAvatarSize: {
[variant in AvatarSizeVariant[number]]: number;
} = {
['large']: 40,
['medium']: 32,
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we do something like this for both medium and large styles:

const mediumAvatarSizeStyle = `
  width: 40px;
  height: 40px;
  
  @media (max-width: ${Breakpoints.large}) {
    width: 32px;
    height: 32px;
  }
`;

and map the style with the size so we eliminate the other called functions as much as we can inside the styled component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i did some refactoring of it, you can take a look

also, i've made sure that the snapshot didn't get updated to maintain the integrity of the outcome

Comment thread src/@next/Avatar/Avatar.tsx Outdated
...props
}: AvatarProps) => {
return (
<AvatarStyle variant={variant} size={size ?? 'large'} {...props}>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<AvatarStyle variant={variant} size={size ?? 'large'} {...props}>
<AvatarStyle variant={variant} size={size} {...props}>

we should be able to remove this because of the default value above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment thread src/@next/Avatar/Avatar.tsx Outdated
return (
<AvatarStyle variant={variant} size={size ?? 'large'} {...props}>
<Typography
variant={size === null || size === 'medium' ? 'body1' : 'headline6'}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
variant={size === null || size === 'medium' ? 'body1' : 'headline6'}
variant={size === 'medium' ? 'body1' : 'headline6'}

we should be able to remove this because of the default value above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/@next/Avatar/Avatar.tsx
@finalight finalight force-pushed the feature/next-avatar branch from 47c4a2a to 630a933 Compare January 17, 2023 10:25
Copy link
Copy Markdown
Contributor

@ninariccimarie ninariccimarie left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@finalight finalight merged commit 6b53653 into v4 Jan 17, 2023
@finalight finalight deleted the feature/next-avatar branch January 17, 2023 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants