Skip to content

Commit 4ddec91

Browse files
committed
Update Button with loading state
Signed-off-by: Leonardo Rossi <[email protected]>
1 parent fb11c10 commit 4ddec91

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/components/Button.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
ACTIVE_AND_INACTIVE_STATUS,
1313
TRANSPARENT
1414
} from './constants'
15-
// ${inactive ? styles.inactive : styles.active}
15+
import SpinnerCircular from './loaders/SpinnerCircular'
16+
1617
function Button ({
1718
textClass = '',
1819
paddingClass = '',
@@ -28,6 +29,7 @@ function Button ({
2829
platformaticIcon = null,
2930
platformaticIconAfter = null,
3031
selected = false,
32+
loading = false,
3133
...rest
3234
}) {
3335
let buttonClassName = textClass
@@ -39,7 +41,7 @@ function Button ({
3941
} else {
4042
contentClassName += `${styles['button-' + size]} `
4143
}
42-
if (disabled) {
44+
if (disabled || loading) {
4345
tmpBorderedClassName = commonStyles[`bordered--${color}-30`]
4446
buttonClassName += ` ${styles.disabled}`
4547
} else {
@@ -109,6 +111,7 @@ function Button ({
109111
return (
110112
<button className={`${buttonClassName} ${restClassName()} ${borderedClassName}`} disabled={disabled} alt={label} {...rest} onMouseLeave={() => setHover(false)} onMouseOver={() => setHover(true)}>
111113
<div className={`${contentClassName} ${backgroundClassName}`}>
114+
{loading ? <SpinnerCircular className={styles.spinner} size={30} thickness={2} color={color} /> : null}
112115
{platformaticIcon ? <PlatformaticIcon key='left' iconName={platformaticIcon.iconName} color={platformaticIcon.color} data-testid='button-icon' onClick={null} inactive={inactive} /> : null}
113116
<span className={styles.label}>{label}</span>
114117
{platformaticIconAfter ? <PlatformaticIcon key='right' iconName={platformaticIconAfter.iconName} color={platformaticIconAfter.color} data-testid='button-icon' onClick={null} inactive={inactive} /> : null}

src/components/Button.module.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,7 @@
145145
}
146146
.cursorDefault {
147147
@apply cursor-default;
148-
}
148+
}
149+
.spinner {
150+
@apply z-50 relative top-[20px] left-[20px] transform -translate-x-1/2 -translate-y-1/2
151+
}

src/stories/Button.stories.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,9 @@ export const FigmaTemplate = DesignSystem.bind({})
670670
FigmaTemplate.args = {
671671
label: 'Sample label'
672672
}
673+
674+
export const LoadingButton = Template.bind({})
675+
LoadingButton.args = {
676+
label: 'Loading Button',
677+
loading: true
678+
}

0 commit comments

Comments
 (0)