nuxt / nuxt/ui

Add deterministic background colors to UAvatar

Open
#6,808 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.