-
Notifications
You must be signed in to change notification settings - Fork 0
/
avatar.tsx
42 lines (36 loc) · 1.39 KB
/
avatar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use client";
import * as AvatarPrimitive from "@radix-ui/react-avatar";
import { type ComponentPropsWithoutRef, type ElementRef, forwardRef } from "react";
import { cn } from "./cn";
const Avatar = forwardRef<
ElementRef<typeof AvatarPrimitive.Root>,
ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
>(({ className, ...rest }, ref) => (
<AvatarPrimitive.Root
ref={ref}
data-testid="avatar"
className={cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", className)}
{...rest}
/>
));
const AvatarImage = forwardRef<
ElementRef<typeof AvatarPrimitive.Image>,
ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
>(({ className, ...rest }, ref) => (
<AvatarPrimitive.Image ref={ref} className={cn("aspect-square h-full w-full", className)} {...rest} />
));
const AvatarFallback = forwardRef<
ElementRef<typeof AvatarPrimitive.Fallback>,
ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...rest }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
data-testid="avatar-fallback"
className={cn("flex h-full w-full items-center justify-center rounded-full bg-muted", className)}
{...rest}
/>
));
Avatar.displayName = AvatarPrimitive.Root.displayName;
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
AvatarImage.displayName = AvatarPrimitive.Image.displayName;
export { Avatar, AvatarImage, AvatarFallback };