Avatar: Add srcTransformer and statusIcon props#7870
Conversation
🦋 Changeset detectedLatest commit: 06aa69a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
Uh oh! @liuliu-dev, at least one image you shared is missing helpful alt text. Check your pull request body to fix the following violations:
Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image. Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.
|
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/21389 |
There was a problem hiding this comment.
Pull request overview
Adds two new customization hooks to Avatar (srcTransformer and statusIcon) to remove the need for external wrapper components, along with supporting styles, tests, Storybook coverage, docs metadata, and a minor-version changeset.
Changes:
- Added
srcTransformerprop to allow transforming the resolved image URL prior to render. - Added
statusIconprop to render a bottom-right overlay icon via a new wrapper/container structure. - Added CSS, unit tests, Storybook stories, docs.json entries, and a minor changeset for the new API.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/Avatar/Avatar.tsx | Adds srcTransformer support and conditionally wraps the <img> to render statusIcon. |
| packages/react/src/Avatar/Avatar.test.tsx | Adds unit tests validating srcTransformer behavior and statusIcon rendering/ref forwarding. |
| packages/react/src/Avatar/Avatar.module.css | Introduces container + overlay styles for the status icon. |
| packages/react/src/Avatar/Avatar.features.stories.tsx | Adds Storybook examples for srcTransformer and statusIcon. |
| packages/react/src/Avatar/Avatar.docs.json | Registers the new feature stories and documents the new props. |
| .changeset/clear-groups-cross.md | Declares a minor release for the new Avatar props. |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 2
| if (statusIcon) { | ||
| return ( | ||
| <div className={classes.AvatarContainer} style={cssSizeVars as React.CSSProperties}> | ||
| {img} | ||
| <span className={classes.StatusIcon}>{statusIcon}</span> | ||
| </div> |
There was a problem hiding this comment.
The style prop applies to the <img> not the container
joshblack
left a comment
There was a problem hiding this comment.
I think the audit might need a pass before we take a stab at implementing things in it, there were some things that stood out as strange when going over it 🤔
I think this PR has one example of this with srcTransformer. I'm not sure why it made that suggestion as, if we implement this, they would still need the component downstream to use this prop for the behavior they have. If we want to replace the component itself, we would have to emulate that (e.g. how they compute avatarUrl)
This is similar with statusIcon since they would still have the downstream package because hover cards are built into it that one.
|
@joshblack thanks for taking a look! yeah I was uncertain when working on the Same with I think closing might be the right call, what do you think? |
Closes https://github.com/github/core-ux/issues/2493
Adds two new props to
Avatarthat close gaps identified in the Primer audit, eliminating the need for the@github-ui/github-avatarand@github-ui/status-avatarwrapper packages:srcTransformer—(src: string, size: number) => string, transforms the image URL before rendering (e.g. appending?size=for HiDPI support)statusIcon—React.ReactNode, renders an overlay positioned at the bottom-right of the avatarChangelog
New
Avatar:srcTransformerprop to transform image URLs before renderingAvatar:statusIconslot to render a status icon overlayRollout strategy
Testing & Reviewing
Merge checklist