Skip to content

Commit

Permalink
[#418] Avatar 컴포넌트 (#420)
Browse files Browse the repository at this point in the history
* feat: avatar 컴포넌트 작성

- avatar.svg width, height 속성 제거

* feat: avatar 스토리 작성

* fix: avatar medium size 크기 수정
  • Loading branch information
gxxrxn committed Jun 17, 2024
1 parent 199a234 commit 51d471e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public/icons/avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/stories/Base/Avatar.stories.tsx
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' },
};
48 changes: 48 additions & 0 deletions src/ui/Base/Avatar.tsx
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;

0 comments on commit 51d471e

Please sign in to comment.