Skip to content

Avatar Issue #3627

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

moulichan99
Copy link

Linked Issue

Closes #{issueNumber}

Description

{description}

Checklist

Please read and apply all contribution requirements.

  • Your branch should be prefixed with: docs/, feature/, chore/, bugfix/
  • Contributions should target the main branch
  • Documentation should be updated to describe all relevant changes
  • Run pnpm check in the root of the monorepo
  • Run pnpm format in the root of the monorepo
  • Run pnpm lint in the root of the monorepo
  • Run pnpm test in the root of the monorepo
  • If you modify /package projects, please supply a Changeset

Changesets

View our documentation to learn more about Changesets. To create a Changeset:

  1. Navigate to the root of the monorepo in your terminal
  2. Run pnpm changeset and follow the prompts
  3. Commit and push the changeset before flagging your PR review for review.

Copy link

changeset-bot bot commented Aug 6, 2025

⚠️ No Changeset found

Latest commit: f2c4da1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Aug 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
themes.skeleton.dev 🔄 Building (Inspect) Visit Preview 💬 Add feedback Aug 6, 2025 0:18am
www.skeleton.dev ❌ Failed (Inspect) Aug 6, 2025 0:18am

Copy link
Contributor

@endigo9740 endigo9740 left a comment

Choose a reason for hiding this comment

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

@moulichan99 great job.

First off, make sure to complete the PR original post in full. It needs the original issue ID, a brief description, and the checkboxes ticked please. You will also need to include a Changeset as this modifies component code. Instructions are provided above.

Minus these small adjustments detailed below, the only other thing missing is documentation to show users how to implement and utilize this new feature. This will need to be present for both React and Svelte docs.

https://www.skeleton.dev/docs/components/avatar/react
https://www.skeleton.dev/docs/components/avatar/svelte

I'd recommend a new section above "Fallback" like so:

## Initials

Provide an `initials` array to define what part of the name is used to generate initials. Use index values to identify each desired name, and `-1` to represent the last possible name.

(example)

Per the example, feel free remove the initials showcase in the Fallback example and description. Then showcase 2-3 avatars with mixed usage in this new example block, including:

  • Default value (no prop defined) - moved from Fallback
  • All initials for a three word name, ex: [0, 1, 2]
  • Two initials from a three word name, [0, -1]

As per the name, something like "Jane Michelle Doe" will work.

.split(' ')
.map((word) => word[0])
.join('');
const getInitials = (name: string, initials: number[] = [0, -1]) => {
Copy link
Contributor

@endigo9740 endigo9740 Aug 6, 2025

Choose a reason for hiding this comment

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

There's a few things here:

1.initials should not need to be passed in as params - and technically not name either. Feel free to remove both and inherit those from the parent scope.
2. The default values for initials should be defined on the prop list (line 30)
3. name is a required prop, so we don't need the early return
4. namePart can be exchanged for chaining at/charAt/toUpperCase and drop the ternary conditional

With all modifications it should condense down to something like this:

NOTE: this is untested, so let me know if it gives you any trouble.

const getInitials = () => {
    return initials.map(index => (name
        .split(' ')
        .at(index)
        .charAt(0)
        .toUpperCase()
        .join()
    ))
}

@@ -27,6 +27,7 @@ export const Avatar: FC<AvatarProps> = ({
fallbackClasses = '',
// Children
children,
initials,
Copy link
Contributor

@endigo9740 endigo9740 Aug 6, 2025

Choose a reason for hiding this comment

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

Move this to match the suggested types.ts position and go ahead and set [0, -1] as the default here.

@@ -64,7 +69,7 @@ export const Avatar: FC<AvatarProps> = ({
)}
{/* Fallback */}
<span {...api.getFallbackProps()} className={`${fallbackBase} ${fallbackClasses}`} data-testid="avatar-fallback">
{children ? children : getInitials(name)}
{children ? children : getInitials(name, initials)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Update: getInitials(...) -> getInitials

@@ -38,4 +38,5 @@ export interface AvatarProps extends Omit<avatar.Props, 'id'>, React.PropsWithCh
fallbackBase?: string;
/** Provide arbitrary CSS classes to fallback element. */
fallbackClasses?: string;
initials?: number[];
Copy link
Contributor

Choose a reason for hiding this comment

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

initials is a "functional prop" per our concerns, so feel free to bump this up under name and give it a JSDocs comment like so:

Initials will be generated based on the name and this index array.

@@ -25,6 +25,7 @@
fallbackClasses = '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Same changes as React please!

@@ -43,4 +43,5 @@ export interface AvatarProps extends Omit<avatar.Props, 'id'>, Pick<HTMLAttribut
// Snippets ---
Copy link
Contributor

Choose a reason for hiding this comment

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

Same changes as React please!

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.

2 participants