Skip to content

Avatar: Add srcTransformer and statusIcon props#7870

Open
liuliu-dev wants to merge 4 commits into
mainfrom
liuliu/add-srctransformer-to-avatar
Open

Avatar: Add srcTransformer and statusIcon props#7870
liuliu-dev wants to merge 4 commits into
mainfrom
liuliu/add-srctransformer-to-avatar

Conversation

@liuliu-dev
Copy link
Copy Markdown
Contributor

@liuliu-dev liuliu-dev commented May 22, 2026

Closes https://github.com/github/core-ux/issues/2493

Adds two new props to Avatar that close gaps identified in the Primer audit, eliminating the need for the @github-ui/github-avatar and @github-ui/status-avatar wrapper packages:

  • srcTransformer(src: string, size: number) => string, transforms the image URL before rendering (e.g. appending ?size= for HiDPI support)
  • statusIconReact.ReactNode, renders an overlay positioned at the bottom-right of the avatar

Changelog

New

  • Avatar: srcTransformer prop to transform image URLs before rendering
  • Avatar: statusIcon slot to render a status icon overlay
    Screenshot 2026-05-22 at 11 44 09 AM

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

🦋 Changeset detected

Latest commit: 06aa69a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

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

@liuliu-dev liuliu-dev added the Canary Release Apply this label when you want CI to create a canary release of the current PR label May 22, 2026
@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label May 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

@github-actions
Copy link
Copy Markdown
Contributor

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:

  • Images should have meaningful alternative text (alt text) at line 16

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.

🤖 Beep boop! This comment was added automatically by github/accessibility-alt-text-bot.

@primer-integration
Copy link
Copy Markdown

👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/21389

@liuliu-dev liuliu-dev marked this pull request as ready for review May 22, 2026 19:11
@liuliu-dev liuliu-dev requested a review from a team as a code owner May 22, 2026 19:11
@liuliu-dev liuliu-dev requested review from Copilot and joshblack May 22, 2026 19:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 srcTransformer prop to allow transforming the resolved image URL prior to render.
  • Added statusIcon prop 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

Comment on lines +67 to +72
if (statusIcon) {
return (
<div className={classes.AvatarContainer} style={cssSizeVars as React.CSSProperties}>
{img}
<span className={classes.StatusIcon}>{statusIcon}</span>
</div>
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.

The style prop applies to the <img> not the container

Comment thread packages/react/src/Avatar/Avatar.module.css Outdated
@primer-integration
Copy link
Copy Markdown

Integration test results from github/github-ui:

Passed  CI   Passed
Passed  VRT   Passed
Passed  Projects   Passed

All checks passed!

Copy link
Copy Markdown
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

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.

@liuliu-dev
Copy link
Copy Markdown
Contributor Author

@joshblack thanks for taking a look! yeah I was uncertain when working on the srcTransformer change, since it won't actually allow us to delete the package. The 235 sites would still need something to pass the transformer. I thought of making the image size doubling the default behavior (like GitHubAvatar does), but worried that it wouldn't work for people outside GitHub using Primer.

Same with statusIcon, I didn't notice the hovercard in that package, thanks for calling that out!

I think closing might be the right call, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Canary Release Apply this label when you want CI to create a canary release of the current PR integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants