|
1 | | -'use client' |
2 | | - |
| 1 | +import * as React from 'react' |
3 | 2 | import * as AvatarPrimitive from '@radix-ui/react-avatar' |
4 | | -import { cva, VariantProps } from 'class-variance-authority' |
5 | | -import { ComponentPropsWithoutRef, ElementRef, forwardRef } from 'react' |
6 | | -import { cn } from '~/lib/utils' |
7 | | - |
8 | | -const avatarVariants = cva( |
9 | | - 'relative flex shrink-0 overflow-hidden rounded-full', |
10 | | - { |
11 | | - variants: { |
12 | | - size: { |
13 | | - sm: 'w-6 h-6', |
14 | | - md: 'w-10 h-10', |
15 | | - }, |
16 | | - }, |
17 | | - defaultVariants: { |
18 | | - size: 'md', |
19 | | - }, |
20 | | - } |
21 | | -) |
22 | | - |
23 | | -export interface AvatarProps |
24 | | - extends ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>, |
25 | | - VariantProps<typeof avatarVariants> {} |
26 | 3 |
|
27 | | -const Avatar = forwardRef<ElementRef<typeof AvatarPrimitive.Root>, AvatarProps>( |
28 | | - ({ className, size, ...props }, ref) => ( |
29 | | - <AvatarPrimitive.Root |
30 | | - ref={ref} |
31 | | - className={cn(avatarVariants({ size, className }))} |
32 | | - {...props} |
33 | | - /> |
34 | | - ) |
35 | | -) |
| 4 | +import { cn } from '~/lib/utils' |
36 | 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-10 w-10 shrink-0 overflow-hidden rounded-full', |
| 14 | + className |
| 15 | + )} |
| 16 | + {...props} |
| 17 | + /> |
| 18 | +)) |
37 | 19 | Avatar.displayName = AvatarPrimitive.Root.displayName |
38 | 20 |
|
39 | | -const AvatarImage = forwardRef< |
40 | | - ElementRef<typeof AvatarPrimitive.Image>, |
41 | | - ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> |
| 21 | +const AvatarImage = React.forwardRef< |
| 22 | + React.ElementRef<typeof AvatarPrimitive.Image>, |
| 23 | + React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> |
42 | 24 | >(({ className, ...props }, ref) => ( |
43 | 25 | <AvatarPrimitive.Image |
44 | 26 | ref={ref} |
45 | 27 | className={cn('aspect-square h-full w-full', className)} |
46 | 28 | {...props} |
47 | 29 | /> |
48 | 30 | )) |
49 | | - |
50 | 31 | AvatarImage.displayName = AvatarPrimitive.Image.displayName |
51 | 32 |
|
52 | | -const AvatarFallback = forwardRef< |
53 | | - ElementRef<typeof AvatarPrimitive.Fallback>, |
54 | | - ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> |
| 33 | +const AvatarFallback = React.forwardRef< |
| 34 | + React.ElementRef<typeof AvatarPrimitive.Fallback>, |
| 35 | + React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> |
55 | 36 | >(({ className, ...props }, ref) => ( |
56 | 37 | <AvatarPrimitive.Fallback |
57 | 38 | ref={ref} |
58 | 39 | className={cn( |
59 | | - 'flex h-full w-full items-center justify-center rounded-full bg-slate-100 dark:bg-slate-700', |
| 40 | + 'flex h-full w-full items-center justify-center rounded-full bg-muted', |
60 | 41 | className |
61 | 42 | )} |
62 | 43 | {...props} |
63 | 44 | /> |
64 | 45 | )) |
65 | | - |
66 | 46 | AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName |
67 | 47 |
|
68 | 48 | export { Avatar, AvatarImage, AvatarFallback } |
0 commit comments