Skip to content

Commit

Permalink
feat: Loading 컴포넌트 구현 (#89)
Browse files Browse the repository at this point in the history
* 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
newminkyung authored Jan 7, 2024
1 parent c4ea0af commit 401c49e
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const config: StorybookConfig = {
docs: {
autodocs: 'tag',
},
staticDirs: ['../public'],
webpackFinal: async (config) => {
if (!config.resolve) return config;

Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"class-variance-authority": "^0.7.0",
"jotai": "^2.6.0",
"js-cookie": "^3.0.5",
"lottie-web": "^5.12.2",
"modern-screenshot": "^4.4.37",
"next": "14.0.2",
"react": "^18",
Expand Down
1 change: 1 addition & 0 deletions public/lotties/bandiboodi-loading.json

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/components/atoms/lottie/Lottie.stories.tsx
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]',
},
};
35 changes: 35 additions & 0 deletions src/components/atoms/lottie/Lottie.tsx
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} />;
};
1 change: 1 addition & 0 deletions src/components/atoms/lottie/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Lottie } from './Lottie';
19 changes: 19 additions & 0 deletions src/components/molecules/loading/Loading.stories.tsx
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]',
},
};
9 changes: 9 additions & 0 deletions src/components/molecules/loading/Loading.tsx
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} />;
};
1 change: 1 addition & 0 deletions src/components/molecules/loading/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Loading } from './Loading';
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6447,6 +6447,7 @@ __metadata:
jotai: "npm:^2.6.0"
js-cookie: "npm:^3.0.5"
lint-staged: "npm:^15.0.2"
lottie-web: "npm:^5.12.2"
modern-screenshot: "npm:^4.4.37"
next: "npm:14.0.2"
postcss: "npm:^8"
Expand Down Expand Up @@ -12313,6 +12314,13 @@ __metadata:
languageName: node
linkType: hard

"lottie-web@npm:^5.12.2":
version: 5.12.2
resolution: "lottie-web@npm:5.12.2"
checksum: 0aeaf631b10a76afd025df70c2a1486543530708e07a316946c08e55891dac483ffbaf2bf3648ae0b9c54c733118a0a086fd150aa76f7848606214c67ad72c30
languageName: node
linkType: hard

"lower-case@npm:^2.0.2":
version: 2.0.2
resolution: "lower-case@npm:2.0.2"
Expand Down

0 comments on commit 401c49e

Please sign in to comment.