Skip to content

Commit

Permalink
Remove skeleton state in OudsButton
Browse files Browse the repository at this point in the history
  • Loading branch information
florentmaitre committed Dec 31, 2024
1 parent ed24ad3 commit f24ea23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fun ButtonDemoScreen() = DemoScreen(rememberButtonDemoState()) {
listOf(
OudsButton.Style.Default,
OudsButton.Style.Loading(progress = null),
OudsButton.Style.Skeleton
)
}
CustomizationChoiceChipsColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -272,7 +271,6 @@ private fun rememberOudsButtonState(
else -> OudsButton.State.Enabled
}
is OudsButton.Style.Loading -> OudsButton.State.Loading
OudsButton.Style.Skeleton -> OudsButton.State.Skeleton
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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<OudsButtonPreviewParameter>(*previewParameterValues.toTypedArray())
Expand Down

0 comments on commit f24ea23

Please sign in to comment.