kanso/ui
Display

Avatar

An image of a person, with a text fallback while it loads or if it fails.

LiveRev. 01
KAKU
ALBTCRDK

Installation

CLI

$ npx shadcn@latest add https://konsa.rohitxyz.me/r/avatar.json

Manual

Install the dependencies

npm install radix-ui

Copy the source into your project

components/ui/avatar.tsx
"use client";

import * as React from "react";
import { Avatar as AvatarPrimitive } from "radix-ui";

import { cn } from "@/lib/utils";

function Avatar({
  className,
  ...props
}: React.ComponentProps<typeof AvatarPrimitive.Root>) {
  return (
    <AvatarPrimitive.Root
      data-slot="avatar"
      className={cn(
        "relative flex size-8 shrink-0 overflow-hidden rounded-full",
        className,
      )}
      {...props}
    />
  );
}

function AvatarImage({
  className,
  ...props
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
  return (
    <AvatarPrimitive.Image
      data-slot="avatar-image"
      className={cn("aspect-square size-full object-cover", className)}
      {...props}
    />
  );
}

function AvatarFallback({
  className,
  ...props
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
  return (
    <AvatarPrimitive.Fallback
      data-slot="avatar-fallback"
      className={cn(
        "flex size-full items-center justify-center rounded-full bg-muted text-xs font-medium text-muted-foreground",
        className,
      )}
      {...props}
    />
  );
}

function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="avatar-group"
      className={cn(
        "flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
        className,
      )}
      {...props}
    />
  );
}

export { Avatar, AvatarImage, AvatarFallback, AvatarGroup };

Update the import paths to match your project

The file imports cn from @/lib/utils. See installation.

Usage

import { Avatar, AvatarImage, AvatarFallback, AvatarGroup } from "@/components/ui/avatar";
<Avatar>
  <AvatarImage src="/me.png" alt="Me" />
  <AvatarFallback>ME</AvatarFallback>
</Avatar>
Avatar