Add deterministic background colors to UAvatar
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.9k
- Forks
- 1.1k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 57
Description
Package
v4.x
Description
It would be useful to optionally generate a deterministic background color for each UAvatar based on its identity, such as its alt or text value.
This would make lists of avatars with fallback initials easier to scan while ensuring that the same person always receives the same color. The color should be generated deterministically using a lightweight mathematical operation, for example by hashing the characters of the name into an HSL hue:
const hue = [...text].reduce((acc, char) => acc + char.charCodeAt(0), 0) % 360
const backgroundColor = `hsl(${hue}, 68%, 60%)`
The feature should be opt-in and remain compatible with the existing color prop. Possible APIs could include:
<UAvatar alt="Jane Doe" color="auto" />
or:
<UAvatar alt="Jane Doe" :deterministic-color="true" />
The generated color should:
- Be stable across renders, sessions, and server-side rendering
- Be based on the avatar’s text or alt value
- Only apply when displaying the fallback content
- Preserve the current behavior by default
- Provide sufficient contrast for the fallback initials or icon
- Allow an explicitly provided color to take precedence
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the UAvatar component entry point and inspect how its current color prop and fallback content are handled. Decide on the opt-in API and deterministic color behavior, then verify fallback contrast, explicit color precedence, stable rendering, and unchanged default behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100