Add destructive param to BigIcon.Style.Default to be able to render icons with red tint.

This commit is contained in:
Benoit Marty 2024-12-06 11:58:52 +01:00
parent aadf35ab9d
commit 3cc1f46795

View file

@ -49,7 +49,11 @@ object BigIcon {
* @param vectorIcon the [ImageVector] to display * @param vectorIcon the [ImageVector] to display
* @param contentDescription the content description of the icon, if any. It defaults to `null` * @param contentDescription the content description of the icon, if any. It defaults to `null`
*/ */
data class Default(val vectorIcon: ImageVector, val contentDescription: String? = null) : Style data class Default(
val vectorIcon: ImageVector,
val contentDescription: String? = null,
val destructive: Boolean = false,
) : Style
/** /**
* An alert style with a transparent background. * An alert style with a transparent background.
@ -84,25 +88,40 @@ object BigIcon {
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val backgroundColor = when (style) { val backgroundColor = when (style) {
is Style.Default -> ElementTheme.colors.bgSubtleSecondary is Style.Default -> if (style.destructive) {
Style.Alert, Style.Success -> Color.Transparent ElementTheme.colors.bgCriticalSubtle
} else {
ElementTheme.colors.bgSubtleSecondary
}
Style.Alert,
Style.Success -> Color.Transparent
Style.AlertSolid -> ElementTheme.colors.bgCriticalSubtle Style.AlertSolid -> ElementTheme.colors.bgCriticalSubtle
Style.SuccessSolid -> ElementTheme.colors.bgSuccessSubtle Style.SuccessSolid -> ElementTheme.colors.bgSuccessSubtle
} }
val icon = when (style) { val icon = when (style) {
is Style.Default -> style.vectorIcon is Style.Default -> style.vectorIcon
Style.Alert, Style.AlertSolid -> CompoundIcons.Error() Style.Alert,
Style.Success, Style.SuccessSolid -> CompoundIcons.CheckCircleSolid() Style.AlertSolid -> CompoundIcons.Error()
Style.Success,
Style.SuccessSolid -> CompoundIcons.CheckCircleSolid()
} }
val contentDescription = when (style) { val contentDescription = when (style) {
is Style.Default -> style.contentDescription is Style.Default -> style.contentDescription
Style.Alert, Style.AlertSolid -> stringResource(CommonStrings.common_error) Style.Alert,
Style.Success, Style.SuccessSolid -> stringResource(CommonStrings.common_success) Style.AlertSolid -> stringResource(CommonStrings.common_error)
Style.Success,
Style.SuccessSolid -> stringResource(CommonStrings.common_success)
} }
val iconTint = when (style) { val iconTint = when (style) {
is Style.Default -> ElementTheme.colors.iconSecondary is Style.Default -> if (style.destructive) {
Style.Alert, Style.AlertSolid -> ElementTheme.colors.iconCriticalPrimary ElementTheme.colors.iconCriticalPrimary
Style.Success, Style.SuccessSolid -> ElementTheme.colors.iconSuccessPrimary } else {
ElementTheme.colors.iconSecondary
}
Style.Alert,
Style.AlertSolid -> ElementTheme.colors.iconCriticalPrimary
Style.Success,
Style.SuccessSolid -> ElementTheme.colors.iconSuccessPrimary
} }
Box( Box(
modifier = modifier modifier = modifier
@ -140,6 +159,7 @@ internal class BigIconStyleProvider : PreviewParameterProvider<BigIcon.Style> {
BigIcon.Style.Default(Icons.Filled.CatchingPokemon), BigIcon.Style.Default(Icons.Filled.CatchingPokemon),
BigIcon.Style.Alert, BigIcon.Style.Alert,
BigIcon.Style.AlertSolid, BigIcon.Style.AlertSolid,
BigIcon.Style.Default(Icons.Filled.CatchingPokemon, destructive = true),
BigIcon.Style.Success, BigIcon.Style.Success,
BigIcon.Style.SuccessSolid BigIcon.Style.SuccessSolid
) )