main
tsx 38 lines 1.33 KB
Raw
1 import * as React from "react";
2 import * as AvatarPrimitive from "@radix-ui/react-avatar";
3
4 import { cn } from "@/lib/utils";
5
6 const Avatar = React.forwardRef<
7 React.ElementRef<typeof AvatarPrimitive.Root>,
8 React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
9 >(({ className, ...props }, ref) => (
10 <AvatarPrimitive.Root
11 ref={ref}
12 className={cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", className)}
13 {...props}
14 />
15 ));
16 Avatar.displayName = AvatarPrimitive.Root.displayName;
17
18 const AvatarImage = React.forwardRef<
19 React.ElementRef<typeof AvatarPrimitive.Image>,
20 React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
21 >(({ className, ...props }, ref) => (
22 <AvatarPrimitive.Image ref={ref} className={cn("aspect-square h-full w-full", className)} {...props} />
23 ));
24 AvatarImage.displayName = AvatarPrimitive.Image.displayName;
25
26 const AvatarFallback = React.forwardRef<
27 React.ElementRef<typeof AvatarPrimitive.Fallback>,
28 React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
29 >(({ className, ...props }, ref) => (
30 <AvatarPrimitive.Fallback
31 ref={ref}
32 className={cn("flex h-full w-full items-center justify-center rounded-full bg-muted", className)}
33 {...props}
34 />
35 ));
36 AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
37
38 export { Avatar, AvatarImage, AvatarFallback };