npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@choice-ui/avatar

v0.0.5

Published

A user avatar component that displays profile images, initials, or icons with customizable styling

Downloads

243

Readme

Avatar

A flexible user avatar component that displays profile photos, initial letters, or a fallback icon. It includes automatic color contrast detection and multiple visual states.

Import

import { Avatar } from "@choice-ui/react"

Features

  • Three display modes: photo, initial letter, or default icon
  • Automatic color contrast detection for text
  • Image loading states with skeleton animation
  • Progressive enhancement with graceful fallbacks
  • Multiple sizes and visual state variants
  • Performance optimized with memoization
  • Accessible with proper alt text support

Usage

Basic

// With photo
<Avatar photo="/user-photo.jpg" name="John Doe" />

// With initial letter (no photo)
<Avatar name="John Doe" />

// Default icon (no photo or name)
<Avatar />

Sizes

<Avatar size="small" name="Jane" />
<Avatar size="medium" name="Jane" />  // default
<Avatar size="large" name="Jane" />

Custom Colors

<Avatar name="John" color="#6B46C1" />
<Avatar name="Jane" color="#DC2626" />
<Avatar name="Alex" color="#059669" />

Visual States

// Default state
<Avatar name="John" states="default" />

// With dash indicator
<Avatar name="John" states="dash" />

// With solid border ring
<Avatar name="John" states="design" />

// With dashed border ring
<Avatar name="John" states="spotlight" />

With Children

<Avatar
  photo="/user.jpg"
  name="John"
>
  <span className="status-indicator" />
</Avatar>

Props

interface AvatarProps extends Omit<HTMLProps<HTMLDivElement>, "size"> {
  /** Additional content to render inside avatar */
  children?: React.ReactNode

  /** Background color for letter avatars (default: "#d3d3d3") */
  color?: string

  /** User's name (used for initial letter fallback) */
  name?: string

  /** URL to user's photo */
  photo?: string

  /** Avatar size variant */
  size?: "small" | "medium" | "large"

  /** Visual state variant */
  states?: "default" | "dash" | "design" | "spotlight"
}
  • Defaults:
    • size: "medium"
    • color: "#d3d3d3"
    • states: "default"

Styling

  • Component uses Tailwind Variants for consistent styling
  • Size dimensions:
    • small: 16x16 pixels
    • medium: 24x24 pixels
    • large: 32x32 pixels
  • Automatically adjusts text color based on background color brightness
  • Custom background colors work with the initial letter display

Best Practices

  • Always provide name for better fallback experience
  • Use consistent avatar sizes within the same context
  • Consider using the states prop to indicate user status or roles
  • Provide meaningful alt text through the name prop
  • Use web-optimized images for better performance

Examples

User List

const users = [
  { id: 1, name: "Alice Johnson", photo: "/alice.jpg" },
  { id: 2, name: "Bob Smith", photo: "/bob.jpg" },
  { id: 3, name: "Charlie Brown" }, // No photo
]

<div className="flex gap-2">
  {users.map(user => (
    <Avatar
      key={user.id}
      name={user.name}
      photo={user.photo}
      size="medium"
    />
  ))}
</div>

Team Member with Status

<div className="flex items-center gap-2">
  <Avatar
    photo="/team-member.jpg"
    name="Sarah Connor"
    states="design"
    size="large"
  />
  <div>
    <div className="font-strong">Sarah Connor</div>
    <div className="text-body-small text-gray-500">Designer</div>
  </div>
</div>

Avatar Group

<div className="flex -space-x-2">
  <Avatar
    name="User 1"
    color="#EF4444"
  />
  <Avatar
    name="User 2"
    color="#3B82F6"
  />
  <Avatar
    name="User 3"
    color="#10B981"
  />
  <Avatar
    name="User 4"
    color="#8B5CF6"
  />
</div>

Notes

  • The component automatically extracts the first letter from the name prop
  • Text color (white or black) is determined automatically based on background brightness
  • Images are lazy-loaded with a smooth skeleton animation
  • Failed image loads gracefully fall back to initial letter display
  • The component is wrapped in React.memo() for performance optimization