avatar.tsx 1.4 KB

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