avertra-ui
uiavatarsource: ok · hit
Avatar
An avatar component for displaying user images.
npx shadcn add "https://micomponents.micustomer.io/r/avatar.json"free
No selection tags yet — empty means no evidence, not lack of support.
Files1 · source cached 10/9/2026, 8:11:29 AM
src/components/ui/avatar.tsx
// src/components/ui/avatar.tsx
"use client";
import * as React from "react";
import * as AvatarPrimitive from "@radix-ui/react-avatar";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/stories/lib/utils";
const avatarVariants = cva("relative flex shrink-0 overflow-hidden", {
variants: {
variant: {
primary: "bg-primary text-primary-foreground",
secondary: "bg-secondary text-secondary-foreground",
tertiary: "bg-tertiary text-tertiary-foreground",
quaternary: "bg-quaternary text-quaternary-foreground",
},
size: {
micro: "h-4 w-4 text-[6px]",
xs: "h-6 w-6 text-[9px]",
sm: "h-7 w-7 text-[12px]",
md: "h-9 w-9 text-sm", // changed to text-sm
lg: "h-11 w-11 text-base", // text-base
xl: "h-14 w-14 text-lg",
},
shape: {
circle: "rounded-full",
square: "rounded-sm",
},
},
defaultVariants: {
variant: "primary",
size: "md",
shape: "square",
},
});
export interface AvatarProps
extends
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>,
VariantProps<typeof avatarVariants> {}
const Avatar = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
AvatarProps
>(({ className, variant, size, shape, ...props }, ref) => (
// IMPORTANT: merge the variant classes first, then any external className
<AvatarPrimitive.Root
ref={ref}
className={cn(avatarVariants({ variant, size, shape }), className)}
{...props}
/>
));
Avatar.displayName = "Avatar";
const AvatarImage = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Image>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Image
ref={ref}
className={cn("aspect-square h-full w-full object-cover", className)}
{...props}
/>
));
AvatarImage.displayName = "AvatarImage";
const AvatarFallback = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center text-sm font-medium leading-none",
className,
)}
{...props}
/>
));
AvatarFallback.displayName = "AvatarFallback";
export { Avatar, AvatarImage, AvatarFallback };