File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
src/components/common/avatar Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ import { Avatar } from './Avatar'
2+
3+ export { Avatar }
You can’t perform that action at this time.
0 commit comments