Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#418] Avatar 컴포넌트 #420

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.5rem] h-[3.5rem]';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ask;

피그마에서 규란님이 작업하신 Avatar 컴포넌트에
width height 각각 32px과 35px인 컴포넌트도 있던데
32px 크기는 의도적으로 제외하신건지 궁금합니다

32px: 모임 상세 페이지
35px: 모임 멤버목록 페이지

}
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}`}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment;

오.. Next/Image 컴포넌트에도 className을 통해서 스타일링이 가능한지는 처음알았네요!! 👍

/>
) : (
<IconAvatar />
)}
</span>
);
};

export default Avatar;