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

프로필 컴포넌트 생성 #41

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Button from './components/common/button/Button'
import './styles/index.css'

function App() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
import Button from './Button'
const meta = {
title: 'Component/Button',
title: 'Components/Button',
component: Button,
parameters: {
layout: 'centered'
Expand Down
43 changes: 43 additions & 0 deletions src/components/common/profile/Profile.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { Meta, StoryObj } from '@storybook/react'
import Profile from './Profile'
const meta = {
title: 'Components/Profile',
component: Profile,
parameters: {
layout: 'centered'
},
tags: ['autodocs'],
argTypes: {
imageSize: {
control: 'select',
options: ['S', 'M', 'L']
}
}
} satisfies Meta<typeof Profile>

export default meta
type Story = StoryObj<typeof meta>

export const LargeProfile: Story = {
args: {
imageSize: 'L',
canEdit: true,
onClick: () => alert('l size 프로필 변경')
}
}

export const MediumProfile: Story = {
args: {
imageSize: 'M',
canEdit: false,
onClick: () => alert('l size 프로필 변경')
}
}

export const SmallProfile: Story = {
args: {
imageSize: 'S',
canEdit: true,
onClick: () => alert('s size 프로필 변경')
}
}
39 changes: 39 additions & 0 deletions src/components/common/profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { ProfileImageProps } from './ProfileType'
import { PROFILE_SIZE, PROFILE_BORDER_COLOR } from './constants'

const Profile = ({
imageSize,
imageUrl = 'https://chanwookim.me/agumon-dday/agumon.png',
canEdit = false
}: ProfileImageProps) => {
return (
<div
className={`border ${canEdit && 'cursor-pointer'} ${
PROFILE_BORDER_COLOR['black500']
} rounded-full relative overflow-hidden ${
imageSize === 'S'
? PROFILE_SIZE['S']
: imageSize === 'M'
? PROFILE_SIZE['M']
: imageSize === 'L'
? PROFILE_SIZE['L']
: ''
}`}
>
<img
onClick={
canEdit
? () => {
alert('프로필 바꾸는 기능!')
}
: undefined
}
src={imageUrl}
alt={'profile photo'}
className={'absolute top-0 left-0 w-[100%] h-[100%]'}
/>
</div>
)
}

export default Profile
8 changes: 8 additions & 0 deletions src/components/common/profile/ProfileType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type ProfileImageType = 'S' | 'M' | 'L'

export interface ProfileImageProps {
imageSize: ProfileImageType
imageUrl?: string
canEdit?: boolean
onClick?: () => void
}
8 changes: 8 additions & 0 deletions src/components/common/profile/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const PROFILE_SIZE = {
L: 'w-[150px] h-[150px]',
M: 'w-[92px] h-[92px]',
S: 'w-[70px] h-[70px]'
}
export const PROFILE_BORDER_COLOR = {
black500: 'border-black-500'
}