-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: avatar 컴포넌트 작성 - avatar.svg width, height 속성 제거 * feat: avatar 스토리 작성 * fix: avatar medium size 크기 수정
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import Avatar from '@/ui/Base/Avatar'; | ||
|
||
const meta: Meta<typeof Avatar> = { | ||
title: 'Base/Avatar', | ||
component: Avatar, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Avatar>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; | ||
|
||
export const WithSrc: Story = { | ||
args: { src: '/icons/logo.svg', name: 'dadok', size: 'large' }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Image from 'next/image'; | ||
|
||
import { IconAvatar } from '@public/icons'; | ||
|
||
type AvatarSize = 'small' | 'medium' | 'large'; | ||
|
||
interface AvatarProps { | ||
name?: string; | ||
src?: string; | ||
size?: AvatarSize; | ||
} | ||
|
||
const getSizeClasses = (size: AvatarSize) => { | ||
switch (size) { | ||
case 'small': { | ||
return 'w-[2rem] h-[2rem]'; | ||
} | ||
case 'medium': { | ||
return 'w-[3.2rem] h-[3.2rem]'; | ||
} | ||
case 'large': { | ||
return 'w-[7rem] h-[7rem]'; | ||
} | ||
} | ||
}; | ||
|
||
const Avatar = ({ name, src, size = 'medium' }: AvatarProps) => { | ||
const sizeClass = getSizeClasses(size); | ||
|
||
return ( | ||
<span | ||
className={`relative inline-block rounded-full bg-white ${sizeClass}`} | ||
> | ||
{src ? ( | ||
<Image | ||
alt={name || 'avatar'} | ||
src={src} | ||
fill | ||
className={`rounded-full object-cover ${sizeClass}`} | ||
/> | ||
) : ( | ||
<IconAvatar /> | ||
)} | ||
</span> | ||
); | ||
}; | ||
|
||
export default Avatar; |