Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use dim3 for all components to handle disabled state #587

Merged
merged 7 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import com.adevinta.spark.components.icons.IconSize
import com.adevinta.spark.icons.IdentityOutline
import com.adevinta.spark.icons.SparkIcon
import com.adevinta.spark.icons.SparkIcons
import com.adevinta.spark.tokens.dim3
import com.adevinta.spark.tools.modifiers.sparkUsageOverlay

@InternalSparkApi
Expand Down Expand Up @@ -232,9 +231,6 @@ public object SparkButtonDefaults {
vertical = size.contentVerticalPadding,
)

internal val Color.disabled: Color
@Composable get() = this.dim3

/**
* The default border of [ButtonOutlined]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.adevinta.spark.PreviewTheme
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.buttons.SparkButtonDefaults.disabled
import com.adevinta.spark.icons.IdentityOutline
import com.adevinta.spark.icons.Link
import com.adevinta.spark.icons.SparkIcon
import com.adevinta.spark.icons.SparkIcons
import com.adevinta.spark.tokens.disabled
import com.adevinta.spark.tools.preview.ThemeProvider
import com.adevinta.spark.tools.preview.ThemeVariant

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.adevinta.spark.PreviewTheme
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.buttons.SparkButtonDefaults.disabled
import com.adevinta.spark.icons.IdentityOutline
import com.adevinta.spark.icons.SparkIcon
import com.adevinta.spark.icons.SparkIcons
import com.adevinta.spark.tokens.disabled
import com.adevinta.spark.tools.preview.ThemeProvider
import com.adevinta.spark.tools.preview.ThemeVariant

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
import com.adevinta.spark.LocalHighlightToken
import com.adevinta.spark.PreviewTheme
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.buttons.SparkButtonDefaults.disabled
import com.adevinta.spark.icons.IdentityOutline
import com.adevinta.spark.icons.Link
import com.adevinta.spark.icons.SparkIcon
import com.adevinta.spark.icons.SparkIcons
import com.adevinta.spark.tokens.disabled
import com.adevinta.spark.tools.preview.ThemeProvider
import com.adevinta.spark.tools.preview.ThemeVariant

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.adevinta.spark.PreviewTheme
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.buttons.SparkButtonDefaults.disabled
import com.adevinta.spark.icons.CameraFill
import com.adevinta.spark.icons.IdentityOutline
import com.adevinta.spark.icons.SparkIcon
import com.adevinta.spark.icons.SparkIcons
import com.adevinta.spark.tokens.disabled
import com.adevinta.spark.tools.preview.ThemeProvider
import com.adevinta.spark.tools.preview.ThemeVariant

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.adevinta.spark.PreviewTheme
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.buttons.SparkButtonDefaults.disabled
import com.adevinta.spark.icons.IdentityOutline
import com.adevinta.spark.icons.SparkIcon
import com.adevinta.spark.icons.SparkIcons
import com.adevinta.spark.tokens.disabled
import com.adevinta.spark.tools.preview.ThemeProvider
import com.adevinta.spark.tools.preview.ThemeVariant

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import androidx.compose.foundation.BorderStroke
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.tokens.dim3
import com.adevinta.spark.tokens.disabled

public enum class ChipStyles {
Outlined {
Expand All @@ -38,7 +37,7 @@ public enum class ChipStyles {
backgroundColor = Color.Transparent,
contentColor = contentColor,
disabledBackgroundColor = Color.Transparent,
disabledContentColor = contentColor.dim3,
disabledContentColor = contentColor.disabled,
)
}
},
Expand All @@ -50,10 +49,8 @@ public enum class ChipStyles {
return ChipColors(
backgroundColor = backgroundColor,
contentColor = contentColor,
disabledBackgroundColor = backgroundColor.dim3
.compositeOver(SparkTheme.colors.surface),
disabledContentColor = contentColor.dim3
.compositeOver(SparkTheme.colors.surface),
disabledBackgroundColor = backgroundColor.disabled,
disabledContentColor = contentColor.disabled,
)
}
},
Expand All @@ -65,10 +62,8 @@ public enum class ChipStyles {
return ChipColors(
backgroundColor = backgroundColor,
contentColor = contentColor,
disabledBackgroundColor = backgroundColor.dim3
.compositeOver(SparkTheme.colors.surface),
disabledContentColor = contentColor.dim3
.compositeOver(SparkTheme.colors.surface),
disabledBackgroundColor = backgroundColor.disabled,
disabledContentColor = contentColor.disabled,
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ import androidx.compose.ui.unit.Constraints
import com.adevinta.spark.ExperimentalSparkApi
import com.adevinta.spark.InternalSparkApi
import com.adevinta.spark.PreviewTheme
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.icons.Icon
import com.adevinta.spark.components.icons.IconSize
import com.adevinta.spark.components.text.Text
import com.adevinta.spark.icons.AccountFill
import com.adevinta.spark.icons.SparkIcon
import com.adevinta.spark.icons.SparkIcons
import com.adevinta.spark.tokens.disabled
import com.adevinta.spark.tools.modifiers.ifNotNull
import com.adevinta.spark.tools.modifiers.ifNull
import com.adevinta.spark.tools.modifiers.sparkUsageOverlay
Expand Down Expand Up @@ -97,7 +97,7 @@ internal fun SparkTab(
contentDescription: String? = null,
enabled: Boolean = true,
selectedContentColor: Color = TabDefaults.SelectedContentIntent.color(),
unselectedContentColor: Color = LocalContentColor.current,
unselectedContentColor: Color = TabDefaults.ContentColor,
size: TabSize = TabDefaults.Size,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
trailingContent: @Composable () -> Unit = {},
Expand All @@ -112,7 +112,7 @@ internal fun SparkTab(
LocalContentColor provides if (enabled) {
unselectedContentColor
} else {
unselectedContentColor.copy(alpha = SparkTheme.colors.dim3)
unselectedContentColor.disabled
},
) {
MaterialTab(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.adevinta.spark.components.tab

import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
Expand All @@ -30,6 +31,11 @@ import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.icons.IconSize.Small

internal object TabDefaults {
/** Default content color of a tab */
val ContentColor: Color
@Composable get() = LocalContentColor.current

/** Default intent color of a selected tab */
internal val SelectedContentIntent = TabIntent.Basic
internal val Size = TabSize.Medium
internal val HorizontalArrangementSpace = 8.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand All @@ -47,16 +46,6 @@ import androidx.compose.ui.unit.dp
* Contains default implementations and values used for TabRow.
*/
internal object TabGroupDefaults {

/** Default container color of a tab row. */

val containerColor: Color
@Composable get() = TabIntent.Basic.color()

/** Default content color of a tab row. */
val contentColor: Color
@Composable get() = LocalContentColor.current

/** Minimum width of a tab */
val minTabWidth = 48.dp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package com.adevinta.spark.components.toggles
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.buttons.SparkButtonDefaults.disabled
import com.adevinta.spark.tokens.disabled
import androidx.compose.material3.SwitchDefaults as MaterialSwitchDefaults

public object SwitchDefaults {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ import androidx.compose.material3.RadioButtonColors
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.SwitchColors
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import com.adevinta.spark.SparkTheme
import com.adevinta.spark.components.IntentColor
import com.adevinta.spark.components.IntentColors
import com.adevinta.spark.tokens.dim3
import com.adevinta.spark.tokens.disabled

public enum class ToggleIntent {
/**
Expand Down Expand Up @@ -142,6 +140,3 @@ internal fun ToggleIntent.toRadioButtonDefaultsColors(): RadioButtonColors = wit

private val UncheckedColor
@Composable get() = SparkTheme.colors.outline

private val Color.disabled: Color
@Composable get() = this.dim3.compositeOver(SparkTheme.colors.surface)
8 changes: 8 additions & 0 deletions spark/src/main/kotlin/com/adevinta/spark/tokens/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Devices
Expand Down Expand Up @@ -1231,6 +1232,13 @@ public val Color.dim4: Color
public val Color.dim5: Color
@Composable get() = this.copy(alpha = SparkTheme.colors.dim5)

/**
* Extension property to get a [Color] with dim3(disabled element) applied composite over SparkTheme.colors.surface
* to prevent the color being transparent
*/
public val Color.disabled: Color
@Composable get() = this.dim3.compositeOver(SparkTheme.colors.surface)

/**
* Updates the internal values of the given [SparkColors] with values from the [other] [SparkColors]. This
* allows efficiently updating a subset of [SparkColors], without recomposing every composable that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public fun EmphasizeMedium(content: @Composable () -> Unit) {
}

/**
* This function is used to set the current value of [LocalContentColor] to onSurface with a disabled apha.
* This function is used to set the current value of [LocalContentColor] to onSurface with a disabled alpha.
* Any [Text], Icons, other components included in this component's [content] will be styled with this a content
* color alpha that apply a disabled emphasis which is close to Gray or Light Gray.
*/
Expand Down
Loading