|
1 | | -export function Avatar() { |
2 | | - return ( |
3 | | - <div className="inline-block w-14 h-14 border-2 border-black rounded-full overflow-hidden"> |
4 | | - <img |
5 | | - className="w-full h-full" |
6 | | - src="https://pagedone.io/asset/uploads/1704275541.png" |
7 | | - alt="Rounded Avatar" |
8 | | - /> |
9 | | - </div> |
10 | | - ); |
11 | | -} |
| 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( |
| 13 | + "relative flex h-14 w-14 border-2 border-black rounded-full overflow-hidden", |
| 14 | + className |
| 15 | + )} |
| 16 | + {...props} |
| 17 | + /> |
| 18 | +)); |
| 19 | +Avatar.displayName = "Avatar"; |
| 20 | + |
| 21 | +const AvatarImage = React.forwardRef< |
| 22 | + React.ElementRef<typeof AvatarPrimitive.Image>, |
| 23 | + React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> |
| 24 | +>(({ className, ...props }, ref) => ( |
| 25 | + <AvatarPrimitive.Image |
| 26 | + ref={ref} |
| 27 | + className={cn("aspect-square h-full w-full", className)} |
| 28 | + {...props} |
| 29 | + /> |
| 30 | +)); |
| 31 | +AvatarImage.displayName = "Avatar.Image"; |
| 32 | + |
| 33 | +const AvatarFallback = React.forwardRef< |
| 34 | + React.ElementRef<typeof AvatarPrimitive.Fallback>, |
| 35 | + React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> |
| 36 | +>(({ className, ...props }, ref) => ( |
| 37 | + <AvatarPrimitive.Fallback |
| 38 | + ref={ref} |
| 39 | + className={cn( |
| 40 | + "flex h-full w-full items-center justify-center rounded-full bg-muted", |
| 41 | + className |
| 42 | + )} |
| 43 | + {...props} |
| 44 | + /> |
| 45 | +)); |
| 46 | +AvatarFallback.displayName = "Avatar.Fallback"; |
| 47 | + |
| 48 | +const AvatarComponent = Object.assign(Avatar, { |
| 49 | + Image: AvatarImage, |
| 50 | + Fallback: AvatarFallback, |
| 51 | +}); |
| 52 | + |
| 53 | +export { AvatarComponent as Avatar }; |
0 commit comments