@@ -123,10 +123,8 @@ fun WCColoredButton(
123123 ) {
124124 Box {
125125 if (loading) {
126- CircularProgressIndicator (
127- color = LocalContentColor .current,
126+ ButtonCircularProgressIndicator (
128127 modifier = Modifier
129- .size(24 .dp)
130128 .align(Alignment .Center )
131129 )
132130 }
@@ -185,14 +183,15 @@ fun WCOutlinedButton(
185183 leadingIcon : @Composable (() -> Unit )? = null,
186184 trailingIcon : @Composable (() -> Unit )? = null,
187185 enabled : Boolean = true,
186+ loading : Boolean = false,
188187 shape : Shape = MaterialTheme .shapes.small,
189188 colors : ButtonColors = ButtonDefaults .wcOutlinedButtonColors(),
190189 border : BorderStroke ? = ButtonDefaults .wcOutlinedButtonBorder(enabled),
191190 contentPadding : PaddingValues = ButtonDefaults .ContentPadding ,
192191 interactionSource : MutableInteractionSource ? = null,
193192) {
194193 WCOutlinedButton (
195- onClick = onClick,
194+ onClick = { if ( ! loading) onClick() } ,
196195 modifier = modifier,
197196 enabled = enabled,
198197 shape = shape,
@@ -201,14 +200,21 @@ fun WCOutlinedButton(
201200 contentPadding = contentPadding,
202201 interactionSource = interactionSource
203202 ) {
204- if (leadingIcon != null ) {
205- leadingIcon()
206- Spacer (modifier = Modifier .width(dimensionResource(id = R .dimen.minor_100)))
207- }
208- Text (text = text)
209- if (trailingIcon != null ) {
210- Spacer (modifier = Modifier .width(dimensionResource(id = R .dimen.minor_100)))
211- trailingIcon()
203+ if (loading) {
204+ ButtonCircularProgressIndicator (
205+ modifier = Modifier
206+ .align(Alignment .CenterVertically )
207+ )
208+ } else {
209+ if (leadingIcon != null ) {
210+ leadingIcon()
211+ Spacer (modifier = Modifier .width(dimensionResource(id = R .dimen.minor_100)))
212+ }
213+ Text (text = text)
214+ if (trailingIcon != null ) {
215+ Spacer (modifier = Modifier .width(dimensionResource(id = R .dimen.minor_100)))
216+ trailingIcon()
217+ }
212218 }
213219 }
214220}
@@ -415,6 +421,15 @@ private fun ProvideMaterial3CompositionForMaterial2(
415421 }
416422}
417423
424+ @Composable
425+ private fun ButtonCircularProgressIndicator (modifier : Modifier = Modifier ) {
426+ CircularProgressIndicator (
427+ color = LocalContentColor .current,
428+ modifier = modifier
429+ .size(24 .dp)
430+ )
431+ }
432+
418433@LightDarkThemePreviews
419434@Composable
420435private fun ButtonsPreview () {
@@ -459,6 +474,11 @@ private fun ButtonsPreview() {
459474 )
460475 }
461476 )
477+ WCColoredButton (
478+ text = " Button Loading" ,
479+ loading = true ,
480+ onClick = {},
481+ )
462482
463483 WCOutlinedButton (onClick = {}) {
464484 Text (text = " Outlined Button" )
@@ -475,6 +495,11 @@ private fun ButtonsPreview() {
475495 Icon (imageVector = Icons .Default .Check , contentDescription = null , modifier = Modifier .size(16 .dp))
476496 }
477497 )
498+ WCOutlinedButton (
499+ text = " Outlined Button Loading" ,
500+ loading = true ,
501+ onClick = {},
502+ )
478503
479504 WCTextButton (onClick = {}) {
480505 Text (text = " Text button" )
0 commit comments