Skip to content

Commit 040953e

Browse files
committed
feat: 상태 표시 버튼 컴포넌트 추가
1 parent 1e1f13b commit 040953e

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Button } from '@/components/button';
2+
import { SpinLoading, ErrorShake, Complete } from '@/components/loading';
3+
import useDelayedLoading from '@/hooks/button/useDelayedLoading';
4+
import { cn } from '@/utils';
5+
6+
interface StatusButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
7+
isLoading: boolean;
8+
isSuccess: boolean;
9+
isError: boolean;
10+
text: string;
11+
disabled?: boolean;
12+
}
13+
14+
const StatusButton = ({
15+
isLoading,
16+
isSuccess,
17+
isError,
18+
text,
19+
disabled,
20+
className,
21+
...props
22+
}: StatusButtonProps) => {
23+
const showLoading = useDelayedLoading({ isLoading });
24+
25+
const variant = disabled ? 'disabled' : 'primary';
26+
27+
const renderContent = () => {
28+
if (showLoading) return <SpinLoading />;
29+
if (isSuccess) return <Complete />;
30+
if (isError) return <ErrorShake />;
31+
return <span>{text}</span>;
32+
};
33+
34+
return (
35+
<Button
36+
variant={variant}
37+
disabled={isLoading || disabled}
38+
className={cn(className, isError && 'bg-functional-danger')}
39+
{...props}
40+
>
41+
{renderContent()}
42+
</Button>
43+
);
44+
};
45+
46+
export default StatusButton;

0 commit comments

Comments
 (0)