Skip to content

Commit 8c43bae

Browse files
committed
[#51] ✨ add Avatart component
1 parent c93b131 commit 8c43bae

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import Image from 'next/image'
2+
3+
import { IcAvatar } from '@/assets/IconList'
4+
import clsx from 'clsx'
5+
6+
type AvatarSize = 24 | 48 | 60 | 180
7+
8+
interface AvatarProps {
9+
image?: string | null
10+
size?: AvatarSize
11+
alt?: string
12+
className?: string
13+
}
14+
15+
const baseStyle =
16+
'relative flex items-center justify-center overflow-hidden rounded-full bg-gray-200'
17+
18+
const styleBySize: Record<AvatarSize, string> = {
19+
24: 'w-24 h-24',
20+
48: 'w-44 h-44',
21+
60: 'w-60 h-60',
22+
180: 'w-180 h-180',
23+
}
24+
25+
export const Avatar = ({
26+
image = null,
27+
size = 48,
28+
alt = 'username',
29+
className = '',
30+
}: AvatarProps): JSX.Element => {
31+
const avatarStyle = clsx(baseStyle, styleBySize[size], className)
32+
33+
return (
34+
<div className={avatarStyle} role='img'>
35+
{image ? (
36+
<Image
37+
src={image}
38+
alt={`${alt} 아바타`}
39+
fill
40+
className='object-cover'
41+
/>
42+
) : (
43+
<IcAvatar />
44+
)}
45+
</div>
46+
)
47+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Avatar } from './Avatar'
2+
3+
export { Avatar }

0 commit comments

Comments
 (0)