diff --git a/src/components/Button/Button.module.css b/src/components/Button/Button.module.css index ea0747f3..d6afec06 100644 --- a/src/components/Button/Button.module.css +++ b/src/components/Button/Button.module.css @@ -58,6 +58,11 @@ border-color: var(--border-color-disabled); } +.loading { + pointer-events: none; + cursor: wait; +} + /* Variant */ .primary { diff --git a/src/components/Button/Button.tsx b/src/components/Button/Button.tsx index a5374139..76528947 100644 --- a/src/components/Button/Button.tsx +++ b/src/components/Button/Button.tsx @@ -3,6 +3,7 @@ import { clsx } from 'clsx'; import { forwardRef } from 'react'; import styles from './Button.module.css'; +import { CircularProgress } from './CircularProgress'; import { VariantIcon } from './VariantIcon'; import type { ButtonProps } from './ButtonTypes'; @@ -17,11 +18,14 @@ export const Button = forwardRef( fixedIcon: _fixedIcon, suffixIcon: _suffixIcon, type = 'button', + disabled = false, + loading = false, + onClick, ...props }, ref, ) => { - const icon = _icon === 'default' ? : _icon; + const icon = loading ? : _icon === 'default' ? : _icon; const fixedIcon = _fixedIcon === 'default' ? : _fixedIcon; const suffixIcon = _suffixIcon === 'default' ? : _suffixIcon; const cls = clsx({ @@ -29,10 +33,29 @@ export const Button = forwardRef( [styles[variant]]: true, [styles[size]]: true, [styles.block]: block, - [styles.disabled]: !!props.disabled, + [styles.disabled]: disabled, + [styles.loading]: loading, }); + + const handleClick = (e: React.MouseEvent) => { + if (loading) { + e.preventDefault(); + return; + } + + onClick?.(e); + }; + return ( -