Skip to content

Commit 13fec4e

Browse files
I've added a loading state to the Button component. Specifically, I added an isLoading prop to Button.tsx to display a spinner and disable the button, and created a Spinner.tsx component with Neobrutalism/Glassmorphism styling support. Additionally, I updated Auth.tsx to use the new prop on the authentication button and cleaned up the manual loading text handling in favor of the standardized component state.
1 parent 22f39f1 commit 13fec4e

File tree

4 files changed

+2906
-2
lines changed

4 files changed

+2906
-2
lines changed

web/components/ui/Button.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import React from 'react';
22
import { THEMES } from '../../constants';
33
import { useTheme } from '../../contexts/ThemeContext';
4+
import { Spinner } from './Spinner';
45

56
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
67
variant?: 'primary' | 'secondary' | 'danger' | 'ghost';
78
size?: 'sm' | 'md' | 'lg';
9+
isLoading?: boolean;
810
}
911

1012
export const Button: React.FC<ButtonProps> = ({
1113
children,
1214
variant = 'primary',
1315
size = 'md',
1416
className = '',
17+
isLoading = false,
1518
...props
1619
}) => {
1720
const { style } = useTheme();
@@ -47,8 +50,10 @@ export const Button: React.FC<ButtonProps> = ({
4750
return (
4851
<button
4952
className={`${baseStyles} ${sizeStyles[size]} ${themeStyles} ${className}`}
53+
disabled={isLoading || props.disabled}
5054
{...props}
5155
>
56+
{isLoading && <Spinner className="mr-1" />}
5257
{children}
5358
</button>
5459
);

web/components/ui/Spinner.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { Loader2 } from 'lucide-react';
3+
4+
interface SpinnerProps {
5+
className?: string;
6+
size?: number;
7+
}
8+
9+
export const Spinner: React.FC<SpinnerProps> = ({ className = '', size = 18 }) => {
10+
return (
11+
<Loader2
12+
className={`animate-spin ${className}`}
13+
size={size}
14+
aria-label="Loading"
15+
/>
16+
);
17+
};

web/pages/Auth.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ export const Auth = () => {
251251
</motion.div>
252252
)}
253253

254-
<Button type="submit" disabled={loading} className={`w-full py-4 text-lg ${isNeo ? 'rounded-none' : ''}`}>
255-
{loading ? 'Processing...' : isLogin ? 'Log In' : 'Create Account'} <ArrowRight size={20} />
254+
<Button type="submit" isLoading={loading} className={`w-full py-4 text-lg ${isNeo ? 'rounded-none' : ''}`}>
255+
{isLogin ? 'Log In' : 'Create Account'} {!loading && <ArrowRight size={20} />}
256256
</Button>
257257
</form>
258258

0 commit comments

Comments
 (0)