From 448e526ffa376c70c5456fdcb6f38d4ea7a53a4f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 22 Aug 2023 10:38:24 +0200 Subject: [PATCH] Button theme: fix small integration mistake on button padding from Figma. --- .../designsystem/theme/components/Button.kt | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Button.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Button.kt index 99d2a68036..ccc014b2c8 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Button.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Button.kt @@ -133,23 +133,39 @@ internal fun ButtonInternal( ButtonSize.Large -> 48.dp } - val contentPadding = when (size) { - ButtonSize.Medium -> { - when (style) { - ButtonStyle.Filled, - ButtonStyle.Outlined -> PaddingValues(horizontal = 16.dp, vertical = 10.dp) - ButtonStyle.Text -> PaddingValues(horizontal = 12.dp, vertical = 10.dp) - } + val hasNoStartDrawable = !showProgress && leadingIcon == null + + val (paddingStart, paddingCenter, paddingEnd) = when (size) { + ButtonSize.Medium -> when (style) { + ButtonStyle.Filled, + ButtonStyle.Outlined -> if (hasNoStartDrawable) + Triple(24.dp, 0.dp, 24.dp) + else + Triple(16.dp, 8.dp, 24.dp) + ButtonStyle.Text -> if (hasNoStartDrawable) + Triple(12.dp, 0.dp, 12.dp) + else + Triple(12.dp, 8.dp, 16.dp) } - ButtonSize.Large -> { - when (style) { - ButtonStyle.Filled, - ButtonStyle.Outlined -> PaddingValues(horizontal = 24.dp, vertical = 13.dp) - ButtonStyle.Text -> PaddingValues(horizontal = 16.dp, vertical = 13.dp) - } + ButtonSize.Large -> when (style) { + ButtonStyle.Filled, + ButtonStyle.Outlined -> if (hasNoStartDrawable) + Triple(32.dp, 0.dp, 32.dp) + else + Triple(24.dp, 8.dp, 32.dp) + ButtonStyle.Text -> if (hasNoStartDrawable) + Triple(16.dp, 0.dp, 16.dp) + else + Triple(12.dp, 8.dp, 16.dp) } } + val contentPadding = when (size) { + ButtonSize.Medium -> PaddingValues(start = paddingStart, end = paddingEnd, top = 10.dp, bottom = 10.dp) + ButtonSize.Large -> PaddingValues(start = paddingStart, end = paddingEnd, top = 13.dp, bottom = 13.dp) + } + val internalPadding = PaddingValues(start = paddingCenter) + val shape = when (style) { ButtonStyle.Filled, ButtonStyle.Outlined -> RoundedCornerShape(percent = 50) @@ -170,12 +186,6 @@ internal fun ButtonInternal( ButtonSize.Large -> ElementTheme.typography.fontBodyLgMedium } - val internalPadding = when (style) { - ButtonStyle.Filled, - ButtonStyle.Outlined -> PaddingValues(horizontal = 8.dp) - ButtonStyle.Text -> if (leadingIcon != null) PaddingValues(start = 8.dp) else PaddingValues(0.dp) - } - androidx.compose.material3.Button( onClick = { if (!showProgress) {