Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: replace and remove deprecated Avatar component #15930

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

Merged
merged 32 commits into from
Dec 20, 2024

Conversation

BrunoQuaresma
Copy link
Collaborator

Close #14997

@BrunoQuaresma
Copy link
Collaborator Author

BrunoQuaresma commented Dec 18, 2024

During the refactor, I noticed that ShadCN adds some boilerplate to the Avatar component. Since we already have a well-established usage of this component across the codebase, I’m wondering if we could simplify it to the following:

Instead of:

<Avatar>
  <Avatar src="..." />
  <AvatarFallback>{avatarLetter("Bruno Quaresma")}</AvatarFallback>
</Avatar>

It could be:

<Avatar src="..." alt="Bruno Quaresma" />

@jaaydenh wdyt?

@jaaydenh
Copy link
Contributor

jaaydenh commented Dec 18, 2024

@BrunoQuaresma Are you proposing alt gets converted internally to the AvatarFallback? or not using the AvatarFallback? It feels like Avatar should have 3 props, src, alt and fallback. I definitely can see a benefit to simplifying the usage from 4 lines to 1 since Avatar is used in so many places.

@BrunoQuaresma
Copy link
Collaborator Author

@BrunoQuaresma Are you proposing alt gets converted internally to the AvatarFallback? or not using the AvatarFallback? It feels like Avatar should have 3 props, src, alt and fallback. I definitely can see a benefit to simplifying the usage from 4 lines to 1 since Avatar is used in so many places.

Yes, I was initially thinking of using alt to generate the fallback, but after some consideration, I agree with you—it should include the three props you mentioned instead. I’ll put up a PR with these changes.

@BrunoQuaresma
Copy link
Collaborator Author

@jaaydenh it is ready for review! 👍

/>
{fallback && (
<AvatarPrimitive.Fallback className="flex h-full w-full items-center justify-center rounded-full">
{fallback.charAt(0).toUpperCase()}
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a separate PR but it would be nice if we started using 2 letters for the fallback case. For example, the first letter of the first 2 words in display name. For example, if you look at the users page on dev.coder.com there are many duplicated avatars for the letters A and B that it doesn't serve much purpose as a identifier.

Copy link
Collaborator Author

@BrunoQuaresma BrunoQuaresma Dec 19, 2024

Choose a reason for hiding this comment

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

Yes, I was planning to address this in another PR if necessary. Since we don’t control the name or display name, we can’t enforce them to have at least two words to display two letters. In such cases, we would display only one letter, correct? Since this involves some logic and could slightly impact the design, I left it out of the scope for this PR.

@@ -35,7 +35,6 @@ export const UserDropdown: FC<UserDropdownProps> = ({
<div css={styles.badgeContainer}>
<Badge overlap="circular">
<UserAvatar
css={styles.avatar}
username={user.username}
Copy link
Contributor

Choose a reason for hiding this comment

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

based on the designs for the topbar navigation, https://www.figma.com/design/WfqIgsTFXN2BscBSSyXWF8/Coder-kit?node-id=656-2354&t=ZPGincsj3IkIlTun-1

The size for the UserAvatar should be size="lg"

/>
);
export const TopbarAvatar: FC<{ src: string }> = ({ src }) => {
return <Avatar variant="icon" size="sm" src={src} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

the TopbarAvatar needs the fallback prop

default: "h-6 w-6 text-2xs",
sm: "h-[18px] w-[18px] text-[8px]",
lg: "h-[--avatar-lg] w-[--avatar-lg] rounded-[6px] text-sm font-medium",
default: "h-[--avatar-default] w-[--avatar-default] text-2xs",
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm, do you think default is being used alot more than lg and sm? otherwise I would name this "md"

Copy link
Contributor

Choose a reason for hiding this comment

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

For example, I used "default" and "sm" for Button.tsx because I imagined default would be used most of the time.

Copy link
Contributor

Choose a reason for hiding this comment

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

As I think about this more, I feel default makes alot more sense for a variant than it does for a size

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. I think we can use md instead.

@jaaydenh
Copy link
Contributor

@BrunoQuaresma one general comment is that I noticed you are not currently using the alt prop on the Avatar component.

@jaaydenh
Copy link
Contributor

UserAvatar.tsx and GroupAvatar.tsx do not seem to provide any extra value except handle the props slightly differently. Is there a specific use case for these? It feels like both could be removed without missing much.

@BrunoQuaresma
Copy link
Collaborator Author

@BrunoQuaresma one general comment is that I noticed you are not currently using the alt prop on the Avatar component.

Good point. I think we can just remove it for now since the Avatar is more of a presentational component. What do you think?

@BrunoQuaresma
Copy link
Collaborator Author

UserAvatar.tsx and GroupAvatar.tsx do not seem to provide any extra value except handle the props slightly differently. Is there a specific use case for these? It feels like both could be removed without missing much.

I’ll take a look, but that makes sense.

@jaaydenh
Copy link
Contributor

@BrunoQuaresma one general comment is that I noticed you are not currently using the alt prop on the Avatar component.

Good point. I think we can just remove it for now since the Avatar is more of a presentational component. What do you think?

I think though the alt prop gets passed to the underlying radix avatar component and is used as the alt prop for the image if the image doesn't load for some reason

@BrunoQuaresma
Copy link
Collaborator Author

@BrunoQuaresma one general comment is that I noticed you are not currently using the alt prop on the Avatar component.

Good point. I think we can just remove it for now since the Avatar is more of a presentational component. What do you think?

I think though the alt prop gets passed to the underlying radix avatar component and is used as the alt prop for the image if the image doesn't load for some reason

Yep, but honestly, in this case, alt doesn’t add much value since we already use the avatar alongside other text or inside a button with a label (or aria-label). Since the avatar is more of a presentational element, I wouldn’t worry too much about it. That said, let’s involve @Parkreiner to see if it makes sense from a usability perspective.

@BrunoQuaresma
Copy link
Collaborator Author

BrunoQuaresma commented Dec 20, 2024

@jaaydenh I think this PR is ready to merge. Regarding this comment, I think we can circle back to it later if needed. What do you think?

Copy link
Contributor

@jaaydenh jaaydenh left a comment

Choose a reason for hiding this comment

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

Looks good now, I think it would be helpful to create an issue and tag christine to discuss the implementation for a 2 letter avatar fallback.

@BrunoQuaresma
Copy link
Collaborator Author

@jaaydenh issue created here

@BrunoQuaresma BrunoQuaresma merged commit 300ad87 into main Dec 20, 2024
29 checks passed
@BrunoQuaresma BrunoQuaresma deleted the bq/use-new-avatar branch December 20, 2024 12:57
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve default avatar style
2 participants