Skip to content

Commit

Permalink
Merge pull request #4004 from element-hq/feature/bma/customAlertSolid
Browse files Browse the repository at this point in the history
Add destructive param to BigIcon.Style.Default to be able to render icons with red tint
  • Loading branch information
bmarty authored Dec 6, 2024
2 parents eae73ac + 4cf0fdb commit d1cfad4
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ package io.element.android.libraries.designsystem.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CatchingPokemon
Expand Down Expand Up @@ -48,8 +51,13 @@ object BigIcon {
*
* @param vectorIcon the [ImageVector] to display
* @param contentDescription the content description of the icon, if any. It defaults to `null`
* @param useCriticalTint whether the icon and background should be rendered using critical tint
*/
data class Default(val vectorIcon: ImageVector, val contentDescription: String? = null) : Style
data class Default(
val vectorIcon: ImageVector,
val contentDescription: String? = null,
val useCriticalTint: Boolean = false,
) : Style

/**
* An alert style with a transparent background.
Expand Down Expand Up @@ -84,25 +92,40 @@ object BigIcon {
modifier: Modifier = Modifier,
) {
val backgroundColor = when (style) {
is Style.Default -> ElementTheme.colors.bgSubtleSecondary
Style.Alert, Style.Success -> Color.Transparent
is Style.Default -> if (style.useCriticalTint) {
ElementTheme.colors.bgCriticalSubtle
} else {
ElementTheme.colors.bgSubtleSecondary
}
Style.Alert,
Style.Success -> Color.Transparent
Style.AlertSolid -> ElementTheme.colors.bgCriticalSubtle
Style.SuccessSolid -> ElementTheme.colors.bgSuccessSubtle
}
val icon = when (style) {
is Style.Default -> style.vectorIcon
Style.Alert, Style.AlertSolid -> CompoundIcons.Error()
Style.Success, Style.SuccessSolid -> CompoundIcons.CheckCircleSolid()
Style.Alert,
Style.AlertSolid -> CompoundIcons.Error()
Style.Success,
Style.SuccessSolid -> CompoundIcons.CheckCircleSolid()
}
val contentDescription = when (style) {
is Style.Default -> style.contentDescription
Style.Alert, Style.AlertSolid -> stringResource(CommonStrings.common_error)
Style.Success, Style.SuccessSolid -> stringResource(CommonStrings.common_success)
Style.Alert,
Style.AlertSolid -> stringResource(CommonStrings.common_error)
Style.Success,
Style.SuccessSolid -> stringResource(CommonStrings.common_success)
}
val iconTint = when (style) {
is Style.Default -> ElementTheme.colors.iconSecondary
Style.Alert, Style.AlertSolid -> ElementTheme.colors.iconCriticalPrimary
Style.Success, Style.SuccessSolid -> ElementTheme.colors.iconSuccessPrimary
is Style.Default -> if (style.useCriticalTint) {
ElementTheme.colors.iconCriticalPrimary
} else {
ElementTheme.colors.iconSecondary
}
Style.Alert,
Style.AlertSolid -> ElementTheme.colors.iconCriticalPrimary
Style.Success,
Style.SuccessSolid -> ElementTheme.colors.iconSuccessPrimary
}
Box(
modifier = modifier
Expand All @@ -123,11 +146,19 @@ object BigIcon {

@PreviewsDayNight
@Composable
internal fun BigIconPreview() {
ElementPreview {
Row(horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.padding(10.dp)) {
val provider = BigIconStyleProvider()
for (style in provider.values) {
internal fun BigIconPreview() = ElementPreview {
LazyVerticalGrid(
modifier = Modifier
.fillMaxSize()
.padding(10.dp),
columns = GridCells.Adaptive(minSize = 64.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
items(BigIconStyleProvider().values.toList()) { style ->
Box(
contentAlignment = Alignment.Center
) {
BigIcon(style = style)
}
}
Expand All @@ -140,6 +171,7 @@ internal class BigIconStyleProvider : PreviewParameterProvider<BigIcon.Style> {
BigIcon.Style.Default(Icons.Filled.CatchingPokemon),
BigIcon.Style.Alert,
BigIcon.Style.AlertSolid,
BigIcon.Style.Default(Icons.Filled.CatchingPokemon, useCriticalTint = true),
BigIcon.Style.Success,
BigIcon.Style.SuccessSolid
)
Expand Down
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.

0 comments on commit d1cfad4

Please sign in to comment.