Skip to content

Commit

Permalink
[#305] Fix display of filter chips
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea committed Nov 23, 2022
1 parent 73533f4 commit 79fa3bd
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ internal object OdsChipDefaults {
*/
internal const val SurfaceOverlayOpacity = 0.12f

/**
* The color opacity used for a selected chip's leading icon or content overlay.
*/
private const val SelectedOverlayOpacity = 0.16f

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun chipColors(
Expand Down Expand Up @@ -53,14 +58,32 @@ internal object OdsChipDefaults {
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun filterChipColors(
backgroundColor: Color = OdsTheme.colors.onSurface.copy(alpha = SurfaceOverlayOpacity)
.compositeOver(OdsTheme.colors.surface),
backgroundColor: Color = OdsTheme.colors.onSurface.copy(alpha = SurfaceOverlayOpacity).compositeOver(OdsTheme.colors.surface),
contentColor: Color = OdsTheme.colors.onSurface.copy(alpha = ChipDefaults.ContentOpacity),
leadingIconColor: Color = contentColor.copy(alpha = ChipDefaults.LeadingIconOpacity)
) = ChipDefaults.filterChipColors(
backgroundColor = backgroundColor,
contentColor = contentColor,
leadingIconColor = contentColor.copy(alpha = ChipDefaults.LeadingIconOpacity),
leadingIconColor = leadingIconColor,
selectedBackgroundColor = OdsTheme.colors.onSurface.copy(alpha = SurfaceOverlayOpacity).compositeOver(backgroundColor),
selectedContentColor = OdsTheme.colors.onSurface.copy(alpha = SelectedOverlayOpacity).compositeOver(contentColor),
selectedLeadingIconColor = OdsTheme.colors.onSurface.copy(alpha = SelectedOverlayOpacity).compositeOver(leadingIconColor),
disabledBackgroundColor = backgroundColor.copy(alpha = ContentAlpha.disabled)
)

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun outlinedFilterChipColors(
backgroundColor: Color = OdsTheme.colors.surface,
contentColor: Color = OdsTheme.colors.onSurface.copy(alpha = ChipDefaults.ContentOpacity),
leadingIconColor: Color = contentColor.copy(alpha = ChipDefaults.LeadingIconOpacity)
) = ChipDefaults.outlinedFilterChipColors(
backgroundColor = backgroundColor,
contentColor = contentColor,
leadingIconColor = leadingIconColor,
selectedBackgroundColor = OdsTheme.colors.onSurface.copy(alpha = SurfaceOverlayOpacity).compositeOver(backgroundColor),
selectedContentColor = OdsTheme.colors.onSurface.copy(alpha = SelectedOverlayOpacity).compositeOver(contentColor),
selectedLeadingIconColor = OdsTheme.colors.onSurface.copy(alpha = SelectedOverlayOpacity).compositeOver(leadingIconColor),
disabledBackgroundColor = backgroundColor.copy(alpha = ContentAlpha.disabled)
)
}

0 comments on commit 79fa3bd

Please sign in to comment.