-
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.
* chore: lottie-web 설치 * chore: lottie json 추가 * feat: Lottie 컴포넌트 구현 * chore: storybook staticDir 설정 추가 * feat: Lottie storybook 추가 * feat: Loading 컴포넌트 구현 * fix: Loading 스토리북 경로 atoms -> molecules로 변경 * refactor: use client 제거 * refactor: container props 제거
- Loading branch information
1 parent
c4ea0af
commit 401c49e
Showing
12 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Lottie } from './Lottie'; | ||
|
||
const meta: Meta<typeof Lottie> = { | ||
title: 'components/atoms/lottie', | ||
component: Lottie, | ||
argTypes: { | ||
src: { | ||
control: { | ||
type: 'text', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Lottie>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
src: '/lotties/bandiboodi-loading.json', | ||
className: 'h-[250px] w-[250px]', | ||
}, | ||
}; |
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 type { HTMLAttributes } from 'react'; | ||
import { useEffect, useRef } from 'react'; | ||
import type { AnimationConfig, AnimationItem } from 'lottie-web'; | ||
import lottie from 'lottie-web'; | ||
|
||
interface LottieProps extends HTMLAttributes<HTMLDivElement>, Omit<AnimationConfig, 'container'> { | ||
src: string; | ||
} | ||
|
||
export const Lottie = ({ src, loop = true, autoplay = true, ...props }: LottieProps) => { | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
const animationRef = useRef<AnimationItem>(); | ||
|
||
useEffect(() => { | ||
if (!containerRef.current) return; | ||
|
||
animationRef.current = lottie.loadAnimation({ | ||
container: containerRef.current, | ||
loop, | ||
autoplay, | ||
renderer: 'svg', | ||
path: src, | ||
rendererSettings: { | ||
progressiveLoad: true, | ||
hideOnTransparent: true, | ||
}, | ||
}); | ||
|
||
return () => { | ||
animationRef.current?.destroy(); | ||
}; | ||
}, [autoplay, loop, src]); | ||
|
||
return <div ref={containerRef} {...props} />; | ||
}; |
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 @@ | ||
export { Lottie } from './Lottie'; |
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,19 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Loading } from './Loading'; | ||
|
||
const meta: Meta<typeof Loading> = { | ||
title: 'components/molecules/loading', | ||
component: Loading, | ||
argTypes: {}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Loading>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
className: 'h-[250px] w-[250px]', | ||
}, | ||
}; |
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,9 @@ | ||
import type { HTMLAttributes } from 'react'; | ||
|
||
import { Lottie } from '@/components/atoms/lottie'; | ||
|
||
interface LoadingProps extends HTMLAttributes<HTMLDivElement> {} | ||
|
||
export const Loading = ({ ...props }: LoadingProps) => { | ||
return <Lottie src="/lotties/bandiboodi-loading.json" {...props} />; | ||
}; |
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 @@ | ||
export { Loading } from './Loading'; |
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