Skip to content

Commit 9ccb5f5

Browse files
committed
add loading position button prop
1 parent 78f700a commit 9ccb5f5

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

idea/vara-eth/frontend/src/components/ui/button/button.module.scss

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
@keyframes spin {
2+
to {
3+
transform: rotate(360deg);
4+
}
5+
}
6+
17
.button {
28
position: relative;
39
display: inline-flex;
@@ -99,6 +105,28 @@
99105
}
100106
}
101107

108+
.loadingPosition {
109+
&center {
110+
.content {
111+
display: none;
112+
}
113+
}
114+
115+
&end {
116+
.spinner {
117+
order: 1;
118+
}
119+
}
120+
}
121+
122+
.content {
123+
display: contents;
124+
}
125+
126+
.spinner {
127+
animation: spin 1s linear infinite;
128+
}
129+
102130
.size-default {
103131
padding: 15px 25px;
104132
}
@@ -118,13 +146,3 @@
118146
.size-icon {
119147
padding: 15px;
120148
}
121-
122-
@keyframes spin {
123-
to {
124-
transform: rotate(360deg);
125-
}
126-
}
127-
128-
.animate-spin {
129-
animation: spin 1s linear infinite;
130-
}

idea/vara-eth/frontend/src/components/ui/button/button.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
1010
variant?: 'default' | 'outline' | 'link' | 'icon' | 'ghost' | 'secondary';
1111
size?: 'default' | 'sm' | 'xs' | 'icon';
1212
isLoading?: boolean;
13+
loadingPosition?: 'start' | 'center' | 'end';
1314
className?: string;
1415
};
1516

@@ -20,24 +21,24 @@ const Button = ({
2021
disabled,
2122
children,
2223
className,
24+
loadingPosition = 'center',
2325
type = 'button',
2426
...props
2527
}: ButtonProps) => {
2628
const isDisabled = disabled || isLoading;
29+
2730
const buttonClass = clsx(
2831
styles.button,
2932
styles[`btn--variant-${variant}`],
3033
styles[`size-${size}`],
31-
{
32-
[styles[`state-disabled`]]: isDisabled,
33-
[styles[`state-loading`]]: isLoading,
34-
},
34+
styles[`loadingPosition${loadingPosition}`],
3535
className,
3636
);
3737

3838
return (
3939
<button className={buttonClass} disabled={isDisabled} aria-disabled={isDisabled} type={type} {...props}>
40-
{isLoading ? <LoadingIcon className={styles['animate-spin']} /> : children}
40+
{isLoading && <LoadingIcon className={styles.spinner} />}
41+
<span className={styles.content}>{children}</span>
4142
</button>
4243
);
4344
};

idea/vara-eth/frontend/src/components/wallet/wallet-button.module.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.button {
22
min-height: 48px;
3-
padding-block: 6px !important; // override default padding
3+
4+
// override defaults
5+
padding-block: 6px !important;
6+
gap: 0 !important;
47

58
flex-direction: column;
69
}

idea/vara-eth/frontend/src/features/programs/ui/top-up-exec-balance/top-up-exec-balance.module.scss

Lines changed: 0 additions & 9 deletions
This file was deleted.

idea/vara-eth/frontend/src/features/programs/ui/top-up-exec-balance/top-up-exec-balance.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import { parseUnits } from 'viem';
55
import { useEthereumClient, useMirrorContract } from '@/app/api';
66
import { useVaraEthApi } from '@/app/providers';
77
import { useAddMyActivity, TransactionTypes, unpackReceipt } from '@/app/store';
8-
import LoadingSVG from '@/assets/icons/loading.svg?react';
98
import { Button } from '@/components';
109

1110
import { useWatchProgramStateChange } from '../../lib';
1211

13-
import styles from './top-up-exec-balance.module.scss';
14-
1512
type Props = {
1613
programId: HexString;
1714
onSuccess: () => void;
@@ -86,9 +83,7 @@ const TopUpExecBalance = ({ programId, onSuccess }: Props) => {
8683
};
8784

8885
return (
89-
// TODO: spinner position prop? loadingText prop?
90-
<Button size="xs" onClick={handleTopUpClick} disabled={isLoading} variant="secondary">
91-
{isLoading && <LoadingSVG className={styles.spinner} />}
86+
<Button size="xs" onClick={handleTopUpClick} loadingPosition="start" disabled={isLoading} variant="secondary">
9287
{getButtonText()}
9388
</Button>
9489
);

0 commit comments

Comments
 (0)