-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 이미지 컴포넌트 - 대표 색깔 기반의 스켈레톤 - 실패 시 슬픈 피우미 이미지 * refactor: 타입 import 분리 타입 import의 경우 명시적으로 분리 Co-authored-by: 유강현 <[email protected]> --------- Co-authored-by: 유강현 <[email protected]>
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 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.
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,30 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import Image from '.'; | ||
|
||
const meta: Meta<typeof Image> = { | ||
component: Image, | ||
|
||
args: { | ||
type: 'circle', | ||
size: '77px', | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Image>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
src: 'https://images.unsplash.com/photo-1555841769-75541ae4fc9f', | ||
alt: '참새', | ||
loading: 'lazy', | ||
}, | ||
}; | ||
|
||
export const Skeleton: Story = { | ||
args: { | ||
src: '', | ||
alt: '무조건 실패하는 이미지', | ||
}, | ||
}; |
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,35 @@ | ||
import { keyframes, styled } from 'styled-components'; | ||
|
||
export interface StyledImageProps { | ||
type: 'circle' | 'square'; | ||
size: string; | ||
} | ||
|
||
const wave = (size: string) => keyframes` | ||
0% { | ||
background-position: -${size} 0; | ||
} | ||
100% { | ||
background-position: ${size} 0; | ||
} | ||
`; | ||
|
||
export const StyledImage = styled.img<StyledImageProps>` | ||
display: inline-flex; | ||
width: ${({ size }) => size}; | ||
height: ${({ size }) => size}; | ||
object-fit: cover; | ||
background: linear-gradient( | ||
to right, | ||
${({ theme }) => theme.color.primary}33 7%, | ||
${({ theme }) => theme.color.primary}4C 17%, | ||
${({ theme }) => theme.color.primary}33 37% | ||
); | ||
background-size: 77px 77px; | ||
border-radius: ${({ type }) => (type === 'circle' ? '50%' : 0)}; | ||
animation: ${({ size }) => wave(size)} 2.5s linear infinite; | ||
`; |
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,18 @@ | ||
import type { StyledImageProps } from './Image.style'; | ||
import { StyledImage } from './Image.style'; | ||
import sadpiumi from 'assets/sadpiumi.png'; | ||
|
||
type ImageProps = Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'onError'> & | ||
Partial<StyledImageProps>; | ||
|
||
const Image = (props: ImageProps) => { | ||
const { type = 'circle', size = '77px', ...imageProps } = props; | ||
|
||
const setErrorImage: React.ReactEventHandler<HTMLImageElement> = ({ currentTarget }) => { | ||
currentTarget.src = sadpiumi; | ||
}; | ||
|
||
return <StyledImage type={type} size={size} onError={setErrorImage} {...imageProps} />; | ||
}; | ||
|
||
export default Image; |