Skip to content

Implement Avatar component #2104

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 6 commits into from
Aug 25, 2021
Merged

Implement Avatar component #2104

merged 6 commits into from
Aug 25, 2021

Conversation

solimant
Copy link
Collaborator

@solimant solimant commented Jul 13, 2021

Closes #1345

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

  1. Open the Avatar storybook
  2. In any of the stories (except the "disabled" one), inspect that Avatar can receive focus and show a focus ring

image

🧢 Your Project:

Adobe/RSP

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

thanks for getting this going!

/**
* The image URL for the avatar.
*/
src: string
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding of this guideline is that the client should use a generic avatar if their user/organization has not specified one.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yep, we interpreted it two different ways. Let's get some more opinions.
Down sides of both:

  • optional image src means we would need to embed some images by default or code it to a discoverable place that we control so it can't be changed without us knowing
  • required img src means potential for people forgetting to implement the generic icon or getting it from the wrong place

Copy link
Collaborator Author

@solimant solimant left a comment

Choose a reason for hiding this comment

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

@snowystinger - please have another look

/**
* The image URL for the avatar.
*/
src: string
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding of this guideline is that the client should use a generic avatar if their user/organization has not specified one.

@solimant solimant force-pushed the 1345 branch 2 times, most recently from d78cc13 to d51a424 Compare July 15, 2021 02:06
Copy link
Member

@LFDanLu LFDanLu 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 for the most part, just some comments

Copy link
Collaborator Author

@solimant solimant left a comment

Choose a reason for hiding this comment

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

@snowystinger, @LFDanLu - thank you for the review. I've addressed your comments/requests. Happy to address any further asks.

@solimant solimant force-pushed the 1345 branch 4 times, most recently from 791a213 to 50e15a6 Compare July 22, 2021 23:18
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple package.json cleanup bits

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

I got clarification from design, this is how the 'size' prop should behave

<Avatar size="avatar-size-100" /> // allowed
<Avatar size="600px" /> // allowed
<Avatar size="30em" /> // allowed
<Avatar size="100" /> // NOT allowed
<Avatar size="size-100" /> // NOT allowed
<Avatar height="anything" /> // NOT allowed at all
<Avatar width="anything" /> // NOT allowed at all

and <Avatar size={100} /> behaves the same as <Avatar size="100px" />

@solimant solimant force-pushed the 1345 branch 4 times, most recently from fc6c424 to da44ae4 Compare July 31, 2021 11:05
Copy link
Collaborator Author

@solimant solimant left a comment

Choose a reason for hiding this comment

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

@LFDanLu - I've made the changes, please have another look.

i did just notice that this is a size prop, not width, so this may be less of an issue
though maybe we need to remove width/height as props that Avatar accepts?

@snowystinger - yes, we're removing width and height in SpectrumAvatarProps.

I got clarification from design, this is how the 'size' prop should behave

@snowystinger - thank you for checking. I've approached in a way that should satisfy that ask. I'm making an assumption, though, that disallowed values default to the default value; i.e. avatar-size-100. Please have another look.

Copy link
Collaborator Author

@solimant solimant left a comment

Choose a reason for hiding this comment

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

@snowystinger - I've addressed your comments. Please have a look. Thank you 🙏🏼

LFDanLu
LFDanLu previously approved these changes Aug 3, 2021
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

One last clean up item and then I'm happy to approve as well

* component. An avatar is a thumbnail representation of an entity, such as a
* user or an organization.
*/
export function useAvatar(props: AriaAvatarOptions): AvatarAria {
Copy link
Member

Choose a reason for hiding this comment

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

we can leave this here for now because the packages are still private and we may decide to move useAvatar into the Avatar component as it may be a very specific to Spectrum component

Disabled.storyName = 'isDisabled';

export const CustomSize = AvatarTemplate.bind({});
CustomSize.args = {size: 'size-1000', src: SRC_URL_2};
Copy link
Member

Choose a reason for hiding this comment

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

This one is an invalid size now, it'll just do default

Suggested change
CustomSize.args = {size: 'size-1000', src: SRC_URL_2};
CustomSize.args = {size: 100, src: SRC_URL_2};

@solimant
Copy link
Collaborator Author

@snowystinger, @LFDanLu - thank you very much for the review and comments. I've addressed the requested changes, and have also introduced support for more element types via 16f710c. I'm happy to omit those changes and refactor whatever is necessary.

Also, on a similar note, and further to our offline conversations, I understand we want to repurpose useAvatar to be something more generic. Perhaps we can call it useGraphic, or something of the like..? This can then encapsulate all ARIA-related logic for anything that depends on graphical HTML elements; e.g. svg, img, etc., and could also be used in the Image component. If that makes sense, or if it's at least a good start, I'm happy to pull this into its own PR and refactor what's necessary here to close things off.

@LFDanLu
Copy link
Member

LFDanLu commented Aug 17, 2021

cc @dannify regarding the above. We talked about this offline previously, do we want to go ahead and move the hook's contents into the Avatar component for now? IMO useGraphic might be a good name for this hook and we can split it out into another pull to discuss what else the hook may cover.

@dannify
Copy link
Member

dannify commented Aug 19, 2021

I think for the first release I would like to merge the hook into React Spectrum. I think we will need it down the track but we don't have enough of a use case to make a pattern out of it just yet. It will likely be used as some sort of focusable image hook but we probably need to figure out what else will use it before we can generalize it and I'd rather not release it now because then we are stuck with the package.

@solimant
Copy link
Collaborator Author

Thank you, @dannify - consolidation is done and ready for review.

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

lgtm! thanks!

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@LFDanLu LFDanLu merged commit 562b400 into adobe:main Aug 25, 2021
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.

Implement Avatar component
5 participants