GlassKit UI
Components

Avatar

A contact / sender avatar — a photo when you have one, else initials on a gradient plate. The building block for notifications, chats, and calls.

MLSODR
600 × 600 · live

Installation

npx @glasskit-ui/cli add avatar

Install the SDK (it provides GlassViewport, useDpad and the stylesheet), then copy these files into your project:

npm install @glasskit-ui/react
// components/lib/utils.tsexport type ClassValue = string | number | null | undefined | false;/** * Join truthy class names. Dependency-free on purpose: the lens components * style via bespoke semantic classes (no conflicting Tailwind utilities to * de-dupe), so this needs no clsx/tailwind-merge and resolves from anywhere * the registry is vendored. */export function cn(...inputs: ClassValue[]): string {  return inputs.filter(Boolean).join(" ");}/** * Accessible name from a free-form `label` prop: the label itself when it's a * plain string, otherwise undefined (a ReactNode can't become an aria-label). */export function stringLabel(label: unknown): string | undefined {  return typeof label === "string" ? label : undefined;}
// components/glasskit/avatar.tsximport type { ReactNode } from "react";import { cn } from "../lib/utils";export type AvatarTone =  | "blue"  | "green"  | "peach"  | "violet"  | "cyan"  | "amber";/** * <Avatar> — a contact / sender avatar: a photo when you have one, else initials * on a gradient plate. Used by NotificationCard, ChatBubble, CallCard. RTL-safe. */export function Avatar({  name,  src,  tone = "blue",  size = "md",  className,}: {  /** Display name — used for initials + the a11y label. */  name: string;  /** Optional image URL. */  src?: string;  /** Gradient tone when showing initials. */  tone?: AvatarTone;  size?: "sm" | "md" | "lg";  className?: string;}) {  const initials = name    .split(/\s+/)    .map((w) => w[0])    .filter(Boolean)    .slice(0, 2)    .join("")    .toUpperCase();  return (    <span      className={cn(        "gk-avatar",        `gk-avatar--${size}`,        !src && `gk-grad-${tone}`,        className,      )}      role="img"      aria-label={name}    >      {src ? (        // eslint-disable-next-line @next/next/no-img-element        <img className="gk-avatar__img" src={src} alt="" />      ) : (        <span className="gk-avatar__initials">{initials}</span>      )}    </span>  );}

Usage

<Avatar name="Mara Lin" tone="violet" /><Avatar name="Sam Ortiz" src={photoUrl} />

Props

Prop

Type