|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import * as React from "react"; |
| 4 | +import * as AvatarPrimitive from "@radix-ui/react-avatar"; |
| 5 | + |
| 6 | +import { cva, VariantProps } from "class-variance-authority"; |
| 7 | +import { cn } from "../../utilities"; |
| 8 | + |
| 9 | +export const avatarVariants = cva("relative flex shrink-0 overflow-hidden", { |
| 10 | + variants: { |
| 11 | + type: { square: "rounded-md", rounded: "rounded-rounded" }, |
| 12 | + size: { |
| 13 | + xs: "w-3 h-3", |
| 14 | + sm: "w-5 h-5", |
| 15 | + md: "w-6 h-6", |
| 16 | + lg: "w-7 h-7", |
| 17 | + xl: "w-9 h-9", |
| 18 | + xxl: "w-12 h-12" |
| 19 | + } |
| 20 | + }, |
| 21 | + defaultVariants: { |
| 22 | + type: "rounded", |
| 23 | + size: "lg" |
| 24 | + } |
| 25 | +}); |
| 26 | + |
| 27 | +const fallbackVariants = cva( |
| 28 | + "flex aspect-square items-center justify-center bg-primary-50 text-theme-text-brand font-semibold uppercase", |
| 29 | + { |
| 30 | + variants: { |
| 31 | + size: { |
| 32 | + xs: "text-text-xs", |
| 33 | + sm: "text-text-xs", |
| 34 | + md: "text-text-md", |
| 35 | + lg: "text-text-lg", |
| 36 | + xl: "text-display-sm", |
| 37 | + xxl: "text-display-md" |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | +); |
| 42 | + |
| 43 | +const Avatar = React.forwardRef< |
| 44 | + React.ElementRef<typeof AvatarPrimitive.Root>, |
| 45 | + React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> & VariantProps<typeof avatarVariants> |
| 46 | +>(({ className, size, type, ...props }, ref) => ( |
| 47 | + <AvatarPrimitive.Root |
| 48 | + ref={ref} |
| 49 | + className={cn(avatarVariants({ size, type }), className)} |
| 50 | + {...props} |
| 51 | + /> |
| 52 | +)); |
| 53 | +Avatar.displayName = AvatarPrimitive.Root.displayName; |
| 54 | + |
| 55 | +const AvatarImage = React.forwardRef< |
| 56 | + React.ElementRef<typeof AvatarPrimitive.Image>, |
| 57 | + React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> |
| 58 | +>(({ className, ...props }, ref) => ( |
| 59 | + <AvatarPrimitive.Image |
| 60 | + ref={ref} |
| 61 | + className={cn("aspect-square h-full w-full", className)} |
| 62 | + {...props} |
| 63 | + /> |
| 64 | +)); |
| 65 | +AvatarImage.displayName = AvatarPrimitive.Image.displayName; |
| 66 | + |
| 67 | +const AvatarFallback = React.forwardRef< |
| 68 | + React.ElementRef<typeof AvatarPrimitive.Fallback>, |
| 69 | + React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> & |
| 70 | + VariantProps<typeof fallbackVariants> |
| 71 | +>(({ className, size, ...props }, ref) => ( |
| 72 | + <AvatarPrimitive.Fallback |
| 73 | + ref={ref} |
| 74 | + className={cn(fallbackVariants({ size }), className)} |
| 75 | + {...props} |
| 76 | + /> |
| 77 | +)); |
| 78 | +AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName; |
| 79 | + |
| 80 | +export { Avatar, AvatarImage, AvatarFallback }; |
0 commit comments