-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: MemberImage 컴포넌트 추가 * refactor: 기존의 프로필 이미지 컴포넌트들을 MemberImage 컴포넌트로 교체 * feat: 프로필 이미지에 오류 발생 시 기본 이미지로 대체 * feat: 상태를 boolean값으로 변경
- Loading branch information
Showing
12 changed files
with
113 additions
and
60 deletions.
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.
24 changes: 24 additions & 0 deletions
24
src/components/Members/MemberImage/MemberImage.stories.tsx
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,24 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import MemberImage from './MemberImage'; | ||
import DefaultMemberImage from '../../../assets/defaultProfile.png'; | ||
|
||
const meta: Meta<typeof MemberImage> = { | ||
title: 'members/MemberImage', | ||
component: MemberImage, | ||
args: { | ||
src: 'https://github.com/woowacourse-teams/2023-fun-eat/assets/78616893/1f0fd418-131c-4cf8-b540-112d762b7c34', | ||
alt: '펀잇님의 프로필 사진', | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof MemberImage>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Error: Story = { | ||
args: { | ||
src: DefaultMemberImage, | ||
}, | ||
}; |
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,42 @@ | ||
import { useState } from 'react'; | ||
import type { CSSProp } from 'styled-components'; | ||
import styled from 'styled-components'; | ||
|
||
import DefaultMemberImage from '@/assets/defaultProfile.png'; | ||
|
||
interface MemberImageProps { | ||
src: string; | ||
alt: string; | ||
width?: number; | ||
height?: number; | ||
css?: CSSProp; | ||
} | ||
|
||
const MemberImage = ({ src, alt, width = 45, height = 45, css }: MemberImageProps) => { | ||
const [isError, setIsError] = useState(false); | ||
|
||
const handleImageError = () => { | ||
setIsError(true); | ||
}; | ||
|
||
return ( | ||
<StyledMemberImage | ||
src={isError ? DefaultMemberImage : src} | ||
alt={alt} | ||
width={width} | ||
height={height} | ||
css={css} | ||
onError={handleImageError} | ||
/> | ||
); | ||
}; | ||
|
||
export default MemberImage; | ||
|
||
const StyledMemberImage = styled.img` | ||
border: 2px solid ${({ theme }) => theme.colors.primary}; | ||
border-radius: 50%; | ||
background: ${({ theme }) => theme.backgroundColors.default}; | ||
object-fit: cover; | ||
${({ css }) => css}; | ||
`; |
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
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
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
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
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
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
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
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
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