← full-stack-fastapi-template / frontend/src/components/ui/avatar.tsx
| 1 | import * as React from "react" |
| 2 | import * as AvatarPrimitive from "@radix-ui/react-avatar" |
| 3 | |
| 4 | import { cn } from "@/lib/utils" |
| 5 | |
| 6 | function Avatar({ |
| 7 | className, |
| 8 | ...props |
| 9 | }: React.ComponentProps<typeof AvatarPrimitive.Root>) { |
| 10 | return ( |
| 11 | <AvatarPrimitive.Root |
| 12 | data-slot="avatar" |
| 13 | className={cn( |
| 14 | "relative flex size-8 shrink-0 overflow-hidden rounded-full", |
| 15 | className |
| 16 | )} |
| 17 | {...props} |
| 18 | /> |
| 19 | ) |
| 20 | } |
| 21 | |
| 22 | function AvatarImage({ |
| 23 | className, |
| 24 | ...props |
| 25 | }: React.ComponentProps<typeof AvatarPrimitive.Image>) { |
| 26 | return ( |
| 27 | <AvatarPrimitive.Image |
| 28 | data-slot="avatar-image" |
| 29 | className={cn("aspect-square size-full", className)} |
| 30 | {...props} |
| 31 | /> |
| 32 | ) |
| 33 | } |
| 34 | |
| 35 | function AvatarFallback({ |
| 36 | className, |
| 37 | ...props |
| 38 | }: React.ComponentProps<typeof AvatarPrimitive.Fallback>) { |
| 39 | return ( |
| 40 | <AvatarPrimitive.Fallback |
| 41 | data-slot="avatar-fallback" |
| 42 | className={cn( |
| 43 | "bg-muted flex size-full items-center justify-center rounded-full", |
| 44 | className |
| 45 | )} |
| 46 | {...props} |
| 47 | /> |
| 48 | ) |
| 49 | } |
| 50 | |
| 51 | export { Avatar, AvatarImage, AvatarFallback } |
| 52 |