From 1aada80495775605e11269adfb1984170d993fda Mon Sep 17 00:00:00 2001 From: Florent Maitre Date: Mon, 30 Dec 2024 16:49:08 +0100 Subject: [PATCH] Remove skeleton state in OudsButton --- .../ui/components/button/ButtonDemoScreen.kt | 1 - .../ouds/core/component/button/OudsButton.kt | 39 ++++--------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/orange/ouds/app/ui/components/button/ButtonDemoScreen.kt b/app/src/main/java/com/orange/ouds/app/ui/components/button/ButtonDemoScreen.kt index 23a16b95..f36ea30c 100644 --- a/app/src/main/java/com/orange/ouds/app/ui/components/button/ButtonDemoScreen.kt +++ b/app/src/main/java/com/orange/ouds/app/ui/components/button/ButtonDemoScreen.kt @@ -73,7 +73,6 @@ fun ButtonDemoScreen() = DemoScreen(rememberButtonDemoState()) { listOf( OudsButton.Style.Default, OudsButton.Style.Loading(progress = null), - OudsButton.Style.Skeleton ) } CustomizationChoiceChipsColumn( diff --git a/core/src/main/java/com/orange/ouds/core/component/button/OudsButton.kt b/core/src/main/java/com/orange/ouds/core/component/button/OudsButton.kt index 10e755ab..559c1c71 100644 --- a/core/src/main/java/com/orange/ouds/core/component/button/OudsButton.kt +++ b/core/src/main/java/com/orange/ouds/core/component/button/OudsButton.kt @@ -43,7 +43,6 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha import androidx.compose.ui.graphics.Color @@ -88,7 +87,7 @@ import kotlinx.parcelize.Parcelize * @param modifier [Modifier] applied to the button. * @param enabled Controls the enabled state of the button when [style] is equal to [OudsButton.Style.Default]. * When `false`, this button will not be clickable. - * Has no effect when [style] is equal to [OudsButton.Style.Loading] or [OudsButton.Style.Skeleton]. + * Has no effect when [style] is equal to [OudsButton.Style.Loading]. * @param style The button style. * @param hierarchy The button hierarchy. */ @@ -121,7 +120,7 @@ fun OudsButton( * @param modifier [Modifier] applied to the button. * @param enabled Controls the enabled state of the button when [style] is equal to [OudsButton.Style.Default]. * When `false`, this button will not be clickable. - * Has no effect when [style] is equal to [OudsButton.Style.Loading] or [OudsButton.Style.Skeleton]. + * Has no effect when [style] is equal to [OudsButton.Style.Loading]. * @param style The button style. * @param hierarchy The button hierarchy. */ @@ -155,7 +154,7 @@ fun OudsButton( * @param modifier [Modifier] applied to the button. * @param enabled Controls the enabled state of the button when [style] is equal to [OudsButton.Style.Default]. * When `false`, this button will not be clickable. - * Has no effect when [style] is equal to [OudsButton.Style.Loading] or [OudsButton.Style.Skeleton]. + * Has no effect when [style] is equal to [OudsButton.Style.Loading]. * @param style The button style. * @param hierarchy The button hierarchy. */ @@ -212,7 +211,7 @@ private fun OudsButton( .semantics { this.stateDescription = stateDescription }, - enabled = state !in remember { listOf(OudsButton.State.Disabled, OudsButton.State.Loading, OudsButton.State.Skeleton) }, + enabled = state !in remember { listOf(OudsButton.State.Disabled, OudsButton.State.Loading) }, shape = shape, colors = buttonColors(hierarchy = hierarchy, buttonState = state), elevation = null, @@ -226,7 +225,7 @@ private fun OudsButton( LoadingIndicator(hierarchy = hierarchy, progress) } - val alpha = if (state in remember { listOf(OudsButton.State.Loading, OudsButton.State.Skeleton) }) 0f else 1f + val alpha = if (state == OudsButton.State.Loading) 0f else 1f Row( modifier = Modifier.alpha(alpha = alpha), horizontalArrangement = Arrangement.spacedBy(buttonTokens.spaceColumnGapIcon.value), @@ -272,7 +271,6 @@ private fun rememberOudsButtonState( else -> OudsButton.State.Enabled } is OudsButton.Style.Loading -> OudsButton.State.Loading - OudsButton.Style.Skeleton -> OudsButton.State.Skeleton } } @@ -314,7 +312,6 @@ private fun borderWidth(hierarchy: OudsButton.Hierarchy, state: OudsButton.State OudsButton.State.Pressed, OudsButton.State.Loading -> if (LocalColoredBox.current) borderWidthDefaultInteractionMono else borderWidthDefaultInteraction OudsButton.State.Focused -> OudsBorderKeyToken.Width.FocusInset - OudsButton.State.Skeleton -> null } OudsButton.Hierarchy.Minimal -> when (state) { OudsButton.State.Enabled, @@ -323,7 +320,6 @@ private fun borderWidth(hierarchy: OudsButton.Hierarchy, state: OudsButton.State OudsButton.State.Pressed, OudsButton.State.Loading -> borderWidthMinimalInteraction OudsButton.State.Focused -> OudsBorderKeyToken.Width.FocusInset - OudsButton.State.Skeleton -> null } OudsButton.Hierarchy.Strong, OudsButton.Hierarchy.Negative -> if (state == OudsButton.State.Focused) OudsBorderKeyToken.Width.FocusInset else null @@ -342,7 +338,6 @@ private fun borderColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.State OudsButton.State.Loading -> if (LocalColoredBox.current) colorBorderDefaultLoadingMono else colorBorderDefaultLoading OudsButton.State.Disabled -> if (LocalColoredBox.current) colorBorderDefaultDisabledMono else colorBorderDefaultDisabled OudsButton.State.Focused -> if (LocalColoredBox.current) colorBorderDefaultFocusMono else colorBorderDefaultFocus - OudsButton.State.Skeleton -> null } OudsButton.Hierarchy.Minimal -> when (state) { OudsButton.State.Enabled -> if (LocalColoredBox.current) colorBorderMinimalEnabledMono else colorBorderMinimalEnabled @@ -351,7 +346,6 @@ private fun borderColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.State OudsButton.State.Loading -> if (LocalColoredBox.current) colorBorderMinimalLoadingMono else colorBorderMinimalLoading OudsButton.State.Disabled -> if (LocalColoredBox.current) colorBorderMinimalDisabledMono else colorBorderMinimalDisabled OudsButton.State.Focused -> if (LocalColoredBox.current) colorBorderMinimalFocusMono else colorBorderMinimalFocus - OudsButton.State.Skeleton -> null } OudsButton.Hierarchy.Strong -> if (LocalColoredBox.current) { when (state) { @@ -361,7 +355,6 @@ private fun borderColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.State OudsButton.State.Loading -> colorBorderStrongLoadingMono OudsButton.State.Disabled -> colorBorderStrongDisabledMono OudsButton.State.Focused -> colorBorderStrongFocusMono - OudsButton.State.Skeleton -> null } } else { null @@ -392,7 +385,6 @@ private fun containerColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.St OudsButton.State.Pressed -> if (LocalColoredBox.current) colorBgDefaultPressedMono else colorBgDefaultPressed OudsButton.State.Loading -> if (LocalColoredBox.current) colorBgDefaultLoadingMono else colorBgDefaultLoading OudsButton.State.Disabled -> if (LocalColoredBox.current) colorBgDefaultDisabledMono else colorBgDefaultDisabled - OudsButton.State.Skeleton -> OudsTheme.componentsTokens.skeleton.colorBg } OudsButton.Hierarchy.Minimal -> when (state) { OudsButton.State.Enabled -> if (LocalColoredBox.current) colorBgMinimalEnabledMono else colorBgMinimalEnabled @@ -401,7 +393,6 @@ private fun containerColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.St OudsButton.State.Pressed -> if (LocalColoredBox.current) colorBgMinimalPressedMono else colorBgMinimalPressed OudsButton.State.Loading -> if (LocalColoredBox.current) colorBgMinimalLoadingMono else colorBgMinimalLoading OudsButton.State.Disabled -> if (LocalColoredBox.current) colorBgMinimalDisabledMono else colorBgMinimalDisabled - OudsButton.State.Skeleton -> OudsTheme.componentsTokens.skeleton.colorBg } OudsButton.Hierarchy.Strong -> when (state) { OudsButton.State.Enabled -> if (LocalColoredBox.current) colorBgStrongEnabledMono else OudsColorKeyToken.Action.Enabled @@ -410,7 +401,6 @@ private fun containerColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.St OudsButton.State.Pressed -> if (LocalColoredBox.current) colorBgStrongPressedMono else OudsColorKeyToken.Action.Pressed OudsButton.State.Loading -> if (LocalColoredBox.current) colorBgStrongLoadingMono else OudsColorKeyToken.Action.Loading OudsButton.State.Disabled -> if (LocalColoredBox.current) colorBgStrongDisabledMono else OudsColorKeyToken.Action.Disabled - OudsButton.State.Skeleton -> OudsTheme.componentsTokens.skeleton.colorBg } OudsButton.Hierarchy.Negative -> when (state) { OudsButton.State.Enabled -> OudsColorKeyToken.Action.Negative.Enabled @@ -419,7 +409,6 @@ private fun containerColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.St OudsButton.State.Pressed -> OudsColorKeyToken.Action.Negative.Pressed OudsButton.State.Loading -> OudsColorKeyToken.Action.Negative.Loading OudsButton.State.Disabled -> OudsColorKeyToken.Action.Disabled - OudsButton.State.Skeleton -> OudsTheme.componentsTokens.skeleton.colorBg } }.value } @@ -436,7 +425,6 @@ private fun contentColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.Stat OudsButton.State.Pressed -> if (LocalColoredBox.current) colorContentDefaultPressedMono else colorContentDefaultPressed OudsButton.State.Loading -> if (LocalColoredBox.current) colorContentDefaultLoadingMono else colorContentDefaultLoading OudsButton.State.Disabled -> if (LocalColoredBox.current) colorContentDefaultDisabledMono else colorContentDefaultDisabled - OudsButton.State.Skeleton -> OudsTheme.componentsTokens.skeleton.colorBg } OudsButton.Hierarchy.Minimal -> when (state) { OudsButton.State.Enabled -> if (LocalColoredBox.current) colorContentMinimalEnabledMono else colorContentMinimalEnabled @@ -445,7 +433,6 @@ private fun contentColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.Stat OudsButton.State.Pressed -> if (LocalColoredBox.current) colorContentMinimalPressedMono else colorContentMinimalPressed OudsButton.State.Loading -> if (LocalColoredBox.current) colorContentMinimalLoadingMono else colorContentMinimalLoading OudsButton.State.Disabled -> if (LocalColoredBox.current) colorContentMinimalDisabledMono else colorContentMinimalDisabled - OudsButton.State.Skeleton -> OudsTheme.componentsTokens.skeleton.colorBg } OudsButton.Hierarchy.Strong -> when (state) { OudsButton.State.Enabled -> if (LocalColoredBox.current) colorContentStrongEnabledMono else OudsColorKeyToken.Content.OnAction.Enabled @@ -454,7 +441,6 @@ private fun contentColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.Stat OudsButton.State.Pressed -> if (LocalColoredBox.current) colorContentStrongPressedMono else OudsColorKeyToken.Content.OnAction.Pressed OudsButton.State.Loading -> if (LocalColoredBox.current) colorContentStrongLoadingMono else OudsColorKeyToken.Content.OnAction.Loading OudsButton.State.Disabled -> if (LocalColoredBox.current) colorContentStrongDisabledMono else OudsColorKeyToken.Content.OnAction.Disabled - OudsButton.State.Skeleton -> OudsTheme.componentsTokens.skeleton.colorBg } OudsButton.Hierarchy.Negative -> when (state) { OudsButton.State.Enabled, @@ -463,7 +449,6 @@ private fun contentColor(hierarchy: OudsButton.Hierarchy, state: OudsButton.Stat OudsButton.State.Loading, OudsButton.State.Focused -> OudsColorKeyToken.Content.OnAction.Negative OudsButton.State.Disabled -> OudsColorKeyToken.Content.OnAction.Disabled - OudsButton.State.Skeleton -> OudsTheme.componentsTokens.skeleton.colorBg } }.value } @@ -491,7 +476,6 @@ private fun contentPadding(icon: OudsButton.Icon?, text: String?): PaddingValues } } -@OptIn(ExperimentalComposeUiApi::class) @Composable private fun LoadingIndicator(hierarchy: OudsButton.Hierarchy, progress: Float?) { val modifier = Modifier @@ -612,16 +596,10 @@ object OudsButton { */ @Parcelize data class Loading(val progress: Float?) : Style() - - /** - * The button displays a skeleton. - */ - @Parcelize - data object Skeleton : Style() } internal enum class State { - Enabled, Hovered, Pressed, Loading, Disabled, Focused, Skeleton + Enabled, Hovered, Pressed, Loading, Disabled, Focused } } @@ -727,9 +705,8 @@ internal data class OudsButtonPreviewParameter( OudsButton.State.Pressed, OudsButton.State.Loading, OudsButton.State.Disabled, - OudsButton.State.Focused, - OudsButton.State.Skeleton - ).filter { surfaceKeyTokenGroup == null || it != OudsButton.State.Skeleton } + OudsButton.State.Focused + ) } internal class OudsButtonPreviewParameterProvider : BasicPreviewParameterProvider(*previewParameterValues.toTypedArray())