-
Notifications
You must be signed in to change notification settings - Fork 7
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
사용자 프로필 바 컴포넌트 구현 #152
사용자 프로필 바 컴포넌트 구현 #152
Changes from all commits
33ea651
695204d
4cafa68
843415d
f40582b
f298758
c4270c4
b42900e
f381ccc
e394169
173743e
c86e5f7
eba83fc
8b6f68d
f847e03
9ed261c
14ae4ee
0ac6d4d
be06975
262b51b
b397214
2539e3f
4f27148
b5eb8bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import ProfileCard from './ProfileCard'; | ||
import EmptyProfile from '@_common/assets/empty_profile.svg'; | ||
import Plus from '@_common/assets/tabler_plus.svg?url'; | ||
|
||
const meta = { | ||
component: ProfileCard, | ||
title: 'Components/ProfileCard', | ||
} satisfies Meta<typeof ProfileCard>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
profile: { | ||
nickname: '치코', | ||
src: EmptyProfile, | ||
role: 'moimee', | ||
}, | ||
}, | ||
render: (args) => <ProfileCard {...args} />, | ||
}; | ||
|
||
export const WithCustomImage: Story = { | ||
args: { | ||
profile: { | ||
nickname: '치코', | ||
src: Plus, | ||
role: 'moimee', | ||
}, | ||
}, | ||
render: (args) => <ProfileCard {...args} />, | ||
}; | ||
|
||
export const WithErrorHandling: Story = { | ||
args: { | ||
profile: { | ||
nickname: '치코', | ||
src: 'invalid-url.jpg', // 오류를 발생시키기 위한 잘못된 URL | ||
role: 'moimee', | ||
}, | ||
}, | ||
render: (args) => <ProfileCard {...args} />, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { css, Theme } from '@emotion/react'; | ||
|
||
export const ProfileCard = css` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.4rem; | ||
align-items: center; | ||
justify-content: flex-end; | ||
|
||
width: auto; | ||
width: fit-content; | ||
`; | ||
|
||
export const ProfileName = (props: { theme: Theme }) => css` | ||
${props.theme.typography.s2} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import ProfileFrame from './ProfileFrame'; | ||
import * as S from './ProfileCard.style'; | ||
import { useTheme } from '@emotion/react'; | ||
import { Participation } from '@_types/index'; | ||
|
||
interface ProfileCardProps { | ||
profile: Participation; | ||
} | ||
export default function ProfileBox(props: ProfileCardProps) { | ||
const { profile } = props; | ||
const theme = useTheme(); | ||
return ( | ||
<div css={S.ProfileCard}> | ||
<ProfileFrame | ||
width={7} | ||
height={7} | ||
src={profile.src} | ||
role={profile.role} | ||
/> | ||
<div css={S.ProfileName({ theme })}>{profile.nickname}</div> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import ProfileFrame from './ProfileFrame'; | ||
import EmptyProfile from '@_common/assets/empty_profile.svg'; | ||
import Plus from '@_common/assets/tabler_plus.svg?url'; | ||
|
||
const meta = { | ||
component: ProfileFrame, | ||
title: 'Components/ProfileFrame', | ||
} satisfies Meta<typeof ProfileFrame>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
width: 7, | ||
height: 7, | ||
src: EmptyProfile, | ||
}, | ||
render: (args) => <ProfileFrame {...args} />, | ||
}; | ||
|
||
export const WithCustomImageAndCrown: Story = { | ||
args: { | ||
width: 7, | ||
height: 7, | ||
src: Plus, | ||
role: 'moimer', | ||
}, | ||
render: (args) => <ProfileFrame {...args} />, | ||
}; | ||
|
||
export const WithCustomImage: Story = { | ||
args: { | ||
width: 7, | ||
height: 7, | ||
src: Plus, | ||
}, | ||
render: (args) => <ProfileFrame {...args} />, | ||
}; | ||
|
||
export const WithErrorHandling: Story = { | ||
args: { | ||
width: 7, | ||
height: 7, | ||
src: 'invalid-url.jpg', // 오류를 발생시키기 위한 잘못된 URL | ||
}, | ||
render: (args) => <ProfileFrame {...args} />, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
type Size = number; | ||
|
||
export const profileBox = () => { | ||
return css` | ||
width: fit-content; | ||
`; | ||
}; | ||
|
||
export const profileFrame = (width: Size, height: Size) => { | ||
return css` | ||
overflow: hidden; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
width: ${width}rem; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 아예 문자에 rem을 박아버렸는데요 이 부분을 조정해보면 좋을 것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 밑에 width을 계산하는 부분이 있어서 rem으로 받으면 rem을 분리하고 숫자로 만든 다음 계산을 해야해서 일단 구현의 편의상 이와 같은 방식으로 구현했습니다. 다음 구현때 수정하도록 하겠습니다. |
||
height: ${height}rem; | ||
|
||
border: 0.5rem solid orange; | ||
border-radius: 300rem; | ||
`; | ||
}; | ||
|
||
export const profileImage = () => { | ||
return css` | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
`; | ||
}; | ||
|
||
// 크라운 이미지를 가운데 정렬하기 위한 css | ||
export const profileCrown = (width: Size) => { | ||
return css` | ||
position: relative; | ||
top: 1rem; | ||
left: ${width / 2 - (3 * (width / 8)) / 2}rem; | ||
width: ${3 * (width / 8)}rem; | ||
`; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ImgHTMLAttributes } from 'react'; | ||
import * as S from './ProfileFrame.style'; | ||
import EmptyProfile from '@_common/assets/empty_profile.svg?url'; | ||
import Crown from '@_common/assets/crown.svg?url'; | ||
import { Role } from '@_types/index'; | ||
|
||
interface ProfileFrameProps extends ImgHTMLAttributes<HTMLImageElement> { | ||
role?: Role; | ||
width: number; | ||
height: number; | ||
} | ||
export default function ProfileFrame(props: ProfileFrameProps) { | ||
const { width, height, onError, role, ...args } = props; | ||
|
||
const handleError = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 이게 싫어서 빈 프로필을 png로 두었어요. 이미지가 없는 에러가 나면 이미지 에러=>js 단에서 onError 수행=>이미지 변경된 컴포넌트 변경=>재렌더링=>재패칭 인데 background로 url을 두 개 두게되면 css에서 이미지 에러=>바로 재패칭 이렇게 되니깐요 물론 svg가 가벼워서 이 방식이 처음에는 더 이득일 수도 있겠네요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것도 한번 다시 생각해볼 필요가 있겠네요. 아마 지금은 svg를 url로 사용할 수 있으니 가능할 것 같아요 |
||
event: React.SyntheticEvent<HTMLImageElement, Event>, | ||
) => { | ||
if (onError) { | ||
onError(event); | ||
} | ||
event.currentTarget.src = EmptyProfile; | ||
}; | ||
|
||
return ( | ||
<div css={S.profileBox()}> | ||
{role === 'moimer' ? <img src={Crown} css={S.profileCrown(width)} /> : ''} | ||
<div css={S.profileFrame(width, height)}> | ||
<img css={S.profileImage} {...args} onError={handleError} /> | ||
</div> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Meta, StoryObj } from '@storybook/react/*'; | ||
import ProfileList from './ProfileList'; | ||
|
||
const meta = { | ||
title: 'components/ProfileList', | ||
component: ProfileList, | ||
} satisfies Meta<typeof ProfileList>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
participants: [ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 이 부분을 상수화해서 배열에 우겨넣으면 가독성이 좋더라구요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그런 방법도 있네요. refact 과정에 반영하도록 하겠습니다. |
||
nickname: '치코', | ||
src: '', | ||
role: 'moimer', | ||
}, | ||
{ | ||
nickname: '치코', | ||
src: '', | ||
role: 'moimee', | ||
}, | ||
{ | ||
nickname: '치코', | ||
src: '', | ||
role: 'moimer', | ||
}, | ||
{ | ||
nickname: '치코', | ||
src: '', | ||
role: 'moimer', | ||
}, | ||
{ | ||
nickname: '치코', | ||
src: '', | ||
role: 'moimer', | ||
}, | ||
{ | ||
nickname: '치코', | ||
src: '', | ||
role: 'moimer', | ||
}, | ||
{ | ||
nickname: '치코', | ||
src: '', | ||
role: 'moimer', | ||
}, | ||
{ | ||
nickname: '치코', | ||
src: '', | ||
role: 'moimer', | ||
}, | ||
], | ||
}, | ||
render: (args) => <ProfileList {...args} />, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
export const ProfileContanier = css` | ||
scrollbar-width: none; /* TODO Firefox 현재 no-unsupported-browser-features 경고 발생 중 추후 확인 필요 */ | ||
|
||
overflow: auto hidden; | ||
display: flex; | ||
gap: 20px; | ||
|
||
width: auto; | ||
|
||
-ms-overflow-style: none; | ||
|
||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import ProfileCard from '@_components/Profile/ProfileCard'; | ||
import * as S from './ProfileList.style'; | ||
import { Participation } from '@_types/index'; | ||
|
||
interface ProfileListProps { | ||
participants: Participation[]; | ||
} | ||
|
||
export default function ProfileList(props: ProfileListProps) { | ||
const { participants } = props; | ||
|
||
return ( | ||
<div css={S.ProfileContanier}> | ||
{participants.map((participant) => { | ||
return <ProfileCard key={participant.nickname} profile={participant} />; | ||
})} | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ declare module '*.woff2' { | |
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.svg?url' { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
const content: string; | ||
export default content; | ||
} | ||
declare module '*.svg' { | ||
import React = require('react'); | ||
export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProfileBox -> ProfileCard
컴포넌트 이름이 수정이 안돼있어요!!!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 수정했습니다.