@@ -8,6 +8,7 @@ interface ToggleProps {
8
8
label : string
9
9
onClick : ( ) => void
10
10
disabled ?: boolean
11
+ isLoading ?: boolean
11
12
dataMarketing : string
12
13
}
13
14
@@ -16,6 +17,7 @@ function Toggle({
16
17
value = false ,
17
18
onClick,
18
19
disabled = false ,
20
+ isLoading = false ,
19
21
dataMarketing,
20
22
} : ToggleProps ) {
21
23
const ID = uniqueId ( 'toggle' )
@@ -24,7 +26,7 @@ function Toggle({
24
26
< div
25
27
data-marketing = { `${ ID } -${ dataMarketing } ` }
26
28
onClick = { ( ) => {
27
- if ( ! disabled ) {
29
+ if ( ! disabled && ! isLoading ) {
28
30
onClick ( )
29
31
}
30
32
} }
@@ -43,7 +45,7 @@ function Toggle({
43
45
'bg-toggle-active' : value ,
44
46
'bg-toggle-inactive' : ! value && ! disabled ,
45
47
'bg-toggle-disabled' : disabled ,
46
- 'cursor-not-allowed' : disabled ,
48
+ 'cursor-not-allowed' : disabled || isLoading ,
47
49
}
48
50
) }
49
51
aria-pressed = "false"
@@ -63,18 +65,31 @@ function Toggle({
63
65
) }
64
66
>
65
67
< div
66
- className = { cn ( {
68
+ className = { cn ( 'flex size-5 items-center justify-center' , {
67
69
'text-toggle-active' : value ,
68
70
'text-toggle-inactive' : ! value && ! disabled ,
69
71
'text-toggle-disabled' : disabled ,
70
72
} ) }
71
73
>
72
- < Icon
73
- name = { value ? 'check' : 'x' }
74
- label = { value ? 'check' : 'x' }
75
- variant = "solid"
76
- size = "flex"
77
- />
74
+ { isLoading ? (
75
+ < div
76
+ data-testid = "toggle-loading-spinner"
77
+ className = { cn (
78
+ 'size-4 animate-spin rounded-full border-4 border-white' ,
79
+ {
80
+ 'border-t-toggle-active' : value ,
81
+ 'border-t-toggle-inactive' : ! value && ! disabled ,
82
+ }
83
+ ) }
84
+ />
85
+ ) : (
86
+ < Icon
87
+ name = { value ? 'check' : 'x' }
88
+ label = { value ? 'check' : 'x' }
89
+ variant = "solid"
90
+ size = "flex"
91
+ />
92
+ ) }
78
93
</ div >
79
94
</ span >
80
95
</ button >
0 commit comments