avatar.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use client"
  2. import * as React from "react"
  3. import { Avatar as AvatarPrimitive } from "@base-ui/react/avatar"
  4. import { cn } from "@/lib/utils/client"
  5. const Avatar = React.forwardRef<
  6. HTMLSpanElement,
  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 = "Avatar"
  19. const AvatarImage = React.forwardRef<
  20. HTMLImageElement,
  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 = "AvatarImage"
  30. const AvatarFallback = React.forwardRef<
  31. HTMLSpanElement,
  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 = "AvatarFallback"
  44. export { Avatar, AvatarImage, AvatarFallback }