Skip to content
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

[Feat] Spinner 컴포넌트 추가 #69

Merged
merged 4 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions apps/web/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const LottieAnimation = dynamic(
ssr: false,
}
);

const Spinner = dynamic(
() => import('@repo/ui/Spinner').then((mod) => mod.Spinner),
{
ssr: false,
}
);

export default function Home() {
const { register, handleSubmit } = useForm<FormValues>({
defaultValues: {
Expand Down Expand Up @@ -202,9 +210,15 @@ export default function Home() {
<Breadcrumb.Item active>기초 경제 지식</Breadcrumb.Item>
</Breadcrumb>
</div>
<div style={{ display: 'flex', gap: '8px' }}>
<IconButton icon="arrowBottom" />
<IconButton icon="plus" />
<div
style={{
display: 'flex',
gap: '8px',
backgroundColor: 'grey',
}}
>
<Spinner color="black" />
<Spinner color="white" />
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"import": "./dist/index.js"
},
"./LottieAnimation": "./dist/components/LottieAnimation/LottieAnimation.js",
"./Spinner": "./dist/components/Spinner/Spinner.js",
"./styles": "./dist/index.css"
},
"scripts": {
Expand Down
43 changes: 43 additions & 0 deletions packages/ui/src/components/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use client';

import { forwardRef } from 'react';
import { lotties } from '../LottieAnimation/assets';
import {
LottieAnimation,
LottieAnimationProps,
} from '../LottieAnimation/LottieAnimation';

type LottieType = keyof typeof lotties;

type SpinnerColorType = 'black' | 'white';

const SpinnerColor: Record<SpinnerColorType, LottieType> = {
black: 'loadingBlack',
white: 'loadingWhite',
};

export type SpinnerProps = {
color?: keyof typeof SpinnerColor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러면 keyof typeof 까지 안해도 되지 않을까.. 근데 뭐가 더 좋은 방법일지 모르겠네요

} & Omit<LottieAnimationProps, 'animationData'>;

/**
* @param {SpinnerProps} props - 스피너 속성
* @property {SpinnerColor} [color='white'] - 스피너 색상 선택
* @property {LottieAnimationProps} [otherProps] - LottieAnimation의 props
*/
export const Spinner = forwardRef<HTMLSpanElement, SpinnerProps>(
({ color = 'white', width = '4rem', height = '4rem', ...rest }) => {
return (
<span>
<LottieAnimation
animationData={SpinnerColor[color]}
width={width}
height={height}
{...rest}
/>
</span>
);
}
);
kongnayeon marked this conversation as resolved.
Show resolved Hide resolved

Spinner.displayName = 'Spinner';
Loading