Skip to content

Commit b8bd09a

Browse files
committed
feat: Add loading state to Button component with spinner indicator
1 parent b0f2c7d commit b8bd09a

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/components/Elements/Button/Button.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
padding: 1rem 2rem;
3333
font-size: 1.25rem;
3434
}
35+
36+
&.loading {
37+
pointer-events: none;
38+
cursor: not-allowed;
39+
opacity: 0.8;
40+
}
3541
}
3642

3743
.circle-button {

src/components/Elements/Button/Button.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import clsx from 'clsx'
22
import React from 'react'
3+
import { Spinner } from '../Spinner'
34
import './Button.css'
4-
55
const sizes = {
66
small: 'small',
77
medium: 'medium',
@@ -14,6 +14,7 @@ type ButtonProps = {
1414
size?: keyof typeof sizes
1515
startIcon?: React.ReactNode
1616
endIcon?: React.ReactNode
17+
isLoading?: boolean
1718
}
1819
export const Button = ({
1920
size = 'medium',
@@ -22,10 +23,14 @@ export const Button = ({
2223
startIcon,
2324
endIcon,
2425
children,
26+
isLoading = false,
2527
}: ButtonProps) => {
2628
return (
27-
<button className={clsx('button', sizes[size], className)} onClick={onClick}>
28-
{startIcon}
29+
<button
30+
className={clsx('button', isLoading && 'loading', sizes[size], className)}
31+
onClick={onClick}
32+
disabled={isLoading}>
33+
{isLoading ? <Spinner size="small" /> : startIcon}
2934
{children}
3035
{endIcon}
3136
</button>

0 commit comments

Comments
 (0)