diff --git a/android/sample/src/main/kotlin/com/gu/source/previews/ChipsPreview.kt b/android/sample/src/main/kotlin/com/gu/source/previews/ChipsPreview.kt index 52cc9e84..390fd921 100644 --- a/android/sample/src/main/kotlin/com/gu/source/previews/ChipsPreview.kt +++ b/android/sample/src/main/kotlin/com/gu/source/previews/ChipsPreview.kt @@ -11,7 +11,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import com.gu.source.R import com.gu.source.Source -import com.gu.source.components.chips.ChipIndicator +import com.gu.source.components.chips.ChipDecoration import com.gu.source.components.chips.SourceChip import com.gu.source.components.chips.SourceChipSupportingButton import com.gu.source.components.chips.SourceMultiSelectChip @@ -63,7 +63,7 @@ internal fun ChipsPreview(modifier: Modifier = Modifier) { size = size, onClick = {}, showBadge = false, - iconOrImage = ChipIndicator.Icon.Component { + iconOrImage = ChipDecoration.Icon.Component { Icon( imageVector = Source.Icons.Base.Plus, contentDescription = null, @@ -78,7 +78,7 @@ internal fun ChipsPreview(modifier: Modifier = Modifier) { size = size, onClick = {}, showBadge = false, - iconOrImage = ChipIndicator.Image.Painter( + iconOrImage = ChipDecoration.Image.Painter( painter = painterResource(R.drawable.marina_hyde), contentDescription = null, ), @@ -90,7 +90,7 @@ internal fun ChipsPreview(modifier: Modifier = Modifier) { size = size, onClick = {}, showBadge = false, - iconOrImage = ChipIndicator.Image.Painter( + iconOrImage = ChipDecoration.Image.Painter( painter = painterResource(R.drawable.marina_hyde), contentDescription = null, ), @@ -105,7 +105,7 @@ internal fun ChipsPreview(modifier: Modifier = Modifier) { style = SourceChip.Style.Default.copy( badgeColour = AppColour.Unspecified, ), - iconOrImage = ChipIndicator.Icon.Vector( + iconOrImage = ChipDecoration.Icon.Vector( imageVector = Source.Icons.Base.Plus, ), ) @@ -147,7 +147,7 @@ internal fun ChipsPreview(modifier: Modifier = Modifier) { size = SourceChip.Size.Medium, onClick = {}, style = SourceChip.Style.Default, - iconOrImage = ChipIndicator.Icon.Painter( + iconOrImage = ChipDecoration.Icon.Painter( painter = painterResource(R.drawable.ic_list), ), ) @@ -166,7 +166,7 @@ internal fun ChipsPreview(modifier: Modifier = Modifier) { text = "Follow", size = SourceChip.Size.Medium, onClick = {}, - iconOrImage = ChipIndicator.Icon.Vector( + iconOrImage = ChipDecoration.Icon.Vector( imageVector = Source.Icons.Base.Plus, ), ) diff --git a/android/source/detekt-baseline.xml b/android/source/detekt-baseline.xml index fcb9d078..1946eeef 100644 --- a/android/source/detekt-baseline.xml +++ b/android/source/detekt-baseline.xml @@ -2,6 +2,6 @@ - CognitiveComplexMethod:SourceChip.kt$private fun getSpacing( size: SourceChip.Size, leadingIndicator: ChipIndicator, hasTrailIndicator: Boolean, hasText: Boolean, ): Spacing + CognitiveComplexMethod:SourceChip.kt$private fun getSpacing( size: SourceChip.Size, leadingDecoration: ChipDecoration, hasTrailDecoration: Boolean, hasText: Boolean, ): Spacing diff --git a/android/source/src/main/kotlin/com/gu/source/components/chips/ChipIndicator.kt b/android/source/src/main/kotlin/com/gu/source/components/chips/ChipDecoration.kt similarity index 91% rename from android/source/src/main/kotlin/com/gu/source/components/chips/ChipIndicator.kt rename to android/source/src/main/kotlin/com/gu/source/components/chips/ChipDecoration.kt index e39cfae6..f67b1bd0 100644 --- a/android/source/src/main/kotlin/com/gu/source/components/chips/ChipIndicator.kt +++ b/android/source/src/main/kotlin/com/gu/source/components/chips/ChipDecoration.kt @@ -18,8 +18,8 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.gu.source.R import com.gu.source.Source -import com.gu.source.components.chips.ChipIndicator.Icon -import com.gu.source.components.chips.ChipIndicator.Image +import com.gu.source.components.chips.ChipDecoration.Icon +import com.gu.source.components.chips.ChipDecoration.Image import com.gu.source.icons.Check /** @@ -28,16 +28,16 @@ import com.gu.source.icons.Check * [Icon]s are `18.dp` tall and the [Image]s are `24.dp` tall. * * The icon or image will be tinted with the [SourceChip.Style.contentColour]. To override the - * tinting, use [ChipIndicator.Icon.Component] or [ChipIndicator.Image.Component] and provide a + * tinting, use [ChipDecoration.Icon.Component] or [ChipDecoration.Image.Component] and provide a * custom composable function with the desired colour. * - * For icons, prefer to use [ChipIndicator.Icon.Vector] with a [Source.Icons] vector where possible. - * Alternatively use [ChipIndicator.Icon.Painter] with a drawable resource ID. + * For icons, prefer to use [ChipDecoration.Icon.Vector] with a [Source.Icons] vector where possible. + * Alternatively use [ChipDecoration.Icon.Painter] with a drawable resource ID. * - * For images, prefer to use [ChipIndicator.Image.Painter] for static images. For images fetched - * from the network, use [ChipIndicator.Image.Component] with a custom composable function. + * For images, prefer to use [ChipDecoration.Image.Painter] for static images. For images fetched + * from the network, use [ChipDecoration.Image.Component] with a custom composable function. */ -sealed class ChipIndicator { +sealed class ChipDecoration { /** * The content to display. The provided modifier _must_ be set on the content. * The modifier is used to apply the correct size to the icon/image. @@ -51,7 +51,7 @@ sealed class ChipIndicator { * Represents an [Icon] displayed before/after the chip's text. Icons are `18.dp` tall and will * be tinted with the [SourceChip.Style.contentColour]. */ - sealed class Icon : ChipIndicator() { + sealed class Icon : ChipDecoration() { override val height: Dp = 18.dp /** @@ -111,7 +111,7 @@ sealed class ChipIndicator { /** * Represents an [Image] displayed before/after the chip's text. Images are `24.dp` tall. */ - sealed class Image : ChipIndicator() { + sealed class Image : ChipDecoration() { override val height: Dp = 24.dp /** @@ -168,7 +168,7 @@ sealed class ChipIndicator { } /** Represents no image or icon displayed before/after the chip's text. */ - data object None : ChipIndicator() { + data object None : ChipDecoration() { override val content: @Composable RowScope.(Modifier) -> Unit = {} override val height: Dp = 0.dp } diff --git a/android/source/src/main/kotlin/com/gu/source/components/chips/SourceChip.kt b/android/source/src/main/kotlin/com/gu/source/components/chips/SourceChip.kt index a27f7e4c..9ad683ba 100644 --- a/android/source/src/main/kotlin/com/gu/source/components/chips/SourceChip.kt +++ b/android/source/src/main/kotlin/com/gu/source/components/chips/SourceChip.kt @@ -204,7 +204,7 @@ fun SourceChip( modifier: Modifier = Modifier, style: SourceChip.Style = SourceChip.Style.Default, onClickLabel: String? = null, - iconOrImage: ChipIndicator = ChipIndicator.None, + iconOrImage: ChipDecoration = ChipDecoration.None, ) { SourceChipInternal( text = text, @@ -215,8 +215,8 @@ fun SourceChip( modifier = modifier, allowsMultiSelection = false, onClickLabel = onClickLabel, - indicatorBefore = iconOrImage, - indicatorAfter = ChipIndicator.None, + decorationBeforeText = iconOrImage, + decorationAfterText = ChipDecoration.None, badge = if (showBadge) { { Badge(containerColor = it) } } else { @@ -252,7 +252,7 @@ fun SourceMultiSelectChip( modifier: Modifier = Modifier, style: SourceChip.Style = SourceChip.Style.Default, onClickLabel: String? = null, - iconOrImage: ChipIndicator = ChipIndicator.None, + iconOrImage: ChipDecoration = ChipDecoration.None, ) { SourceChipInternal( text = text, @@ -263,9 +263,9 @@ fun SourceMultiSelectChip( modifier = modifier, allowsMultiSelection = true, onClickLabel = onClickLabel, - indicatorBefore = iconOrImage, - indicatorAfter = if (isSelected) { - ChipIndicator.Icon.Component { + decorationBeforeText = iconOrImage, + decorationAfterText = if (isSelected) { + ChipDecoration.Icon.Component { Icon( imageVector = Source.Icons.Base.Check, contentDescription = null, @@ -273,7 +273,7 @@ fun SourceMultiSelectChip( ) } } else { - ChipIndicator.None + ChipDecoration.None }, badge = if (showBadge) { { Badge(containerColor = it) } @@ -284,8 +284,8 @@ fun SourceMultiSelectChip( } private data class Spacing( - val beforeLeadingIndicator: Dp, - val betweenLeadingIndicatorAndText: Dp, + val beforeLeadingDecoration: Dp, + val betweenLeadingDecorationAndText: Dp, val betweenTextAndCheckmark: Dp, val afterCheckmark: Dp, ) @@ -315,11 +315,11 @@ private data class Spacing( */ private fun getSpacing( size: SourceChip.Size, - leadingIndicator: ChipIndicator, - hasTrailIndicator: Boolean, + leadingDecoration: ChipDecoration, + hasTrailDecoration: Boolean, hasText: Boolean, ): Spacing { - val beforeLeadingIndicator = if (leadingIndicator is ChipIndicator.None) { + val beforeLeadingDecoration = if (leadingDecoration is ChipDecoration.None) { // Label only 16.dp } else if (!hasText) { @@ -333,18 +333,18 @@ private fun getSpacing( } } - val betweenLeadingIndicatorAndText = when (leadingIndicator) { - is ChipIndicator.Icon -> { + val betweenLeadingDecorationAndText = when (leadingDecoration) { + is ChipDecoration.Icon -> { if (hasText) 4.dp else 0.dp } - is ChipIndicator.Image -> if (hasText) 8.dp else 0.dp - ChipIndicator.None -> 0.dp + is ChipDecoration.Image -> if (hasText) 8.dp else 0.dp + ChipDecoration.None -> 0.dp } - val betweenTextAndCheckmark = if (hasTrailIndicator) 8.dp else 0.dp + val betweenTextAndCheckmark = if (hasTrailDecoration) 8.dp else 0.dp - val afterCheckmark = if (hasTrailIndicator) { + val afterCheckmark = if (hasTrailDecoration) { 8.dp } else if (hasText) { // Label only without check @@ -355,8 +355,8 @@ private fun getSpacing( } return Spacing( - beforeLeadingIndicator = beforeLeadingIndicator, - betweenLeadingIndicatorAndText = betweenLeadingIndicatorAndText, + beforeLeadingDecoration = beforeLeadingDecoration, + betweenLeadingDecorationAndText = betweenLeadingDecorationAndText, betweenTextAndCheckmark = betweenTextAndCheckmark, afterCheckmark = afterCheckmark, ) @@ -378,8 +378,8 @@ private fun getSpacing( * @param allowsMultiSelection Optional - whether the chip allows multiple selections. This is used * to set correct semantic role for the chip - checkbox if true, button if false. * @param onClickLabel Optional label for the onClick action. - * @param indicatorBefore Optional content to display an icon/image before the title. - * @param indicatorAfter Optional content to display an icon/image after the title. + * @param decorationBeforeText Optional content to display an icon/image before the title. + * @param decorationAfterText Optional content to display an icon/image after the title. * @param badge Optional content to display a badge over the chip. Usually a [Badge]. Badge colour * is passed to the [badge] slot. */ @@ -395,8 +395,8 @@ internal fun SourceChipInternal( style: SourceChip.Style = SourceChip.Style.Default, allowsMultiSelection: Boolean = false, onClickLabel: String? = null, - indicatorBefore: ChipIndicator = ChipIndicator.None, - indicatorAfter: ChipIndicator = ChipIndicator.None, + decorationBeforeText: ChipDecoration = ChipDecoration.None, + decorationAfterText: ChipDecoration = ChipDecoration.None, badge: @Composable ((Color) -> Unit)? = null, ) { SourceBaseChip( @@ -425,17 +425,17 @@ internal fun SourceChipInternal( val spacing = getSpacing( size = size, - leadingIndicator = indicatorBefore, - hasTrailIndicator = indicatorAfter !is ChipIndicator.None, + leadingDecoration = decorationBeforeText, + hasTrailDecoration = decorationAfterText !is ChipDecoration.None, hasText = text.isNotBlank(), ) CompositionLocalProvider(LocalContentColor provides contentColour) { - Spacer(modifier = Modifier.width(spacing.beforeLeadingIndicator)) + Spacer(modifier = Modifier.width(spacing.beforeLeadingDecoration)) - indicatorBefore.content(this, Modifier.height(indicatorBefore.height)) + decorationBeforeText.content(this, Modifier.height(decorationBeforeText.height)) - Spacer(modifier = Modifier.width(spacing.betweenLeadingIndicatorAndText)) + Spacer(modifier = Modifier.width(spacing.betweenLeadingDecorationAndText)) HorizontalExpandingText( text = text, @@ -447,7 +447,7 @@ internal fun SourceChipInternal( Spacer(modifier = Modifier.width(spacing.betweenTextAndCheckmark)) - indicatorAfter.content(this, Modifier) + decorationAfterText.content(this, Modifier) Spacer(modifier = Modifier.width(spacing.afterCheckmark)) } @@ -475,7 +475,7 @@ fun SourceChipSupportingButton( onClick: () -> Unit, modifier: Modifier = Modifier, style: SourceChip.Style = SourceChip.Style.SupportingButton, - iconOrImage: ChipIndicator = ChipIndicator.None, + iconOrImage: ChipDecoration = ChipDecoration.None, ) { SourceChipInternal( text = text, @@ -484,8 +484,8 @@ fun SourceChipSupportingButton( style = style, onClick = onClick, modifier = modifier, - indicatorBefore = iconOrImage, - indicatorAfter = ChipIndicator.None, + decorationBeforeText = iconOrImage, + decorationAfterText = ChipDecoration.None, ) } @@ -534,7 +534,7 @@ internal fun SourceChipPreview(modifier: Modifier = Modifier) { size = size, onClick = {}, showBadge = false, - iconOrImage = ChipIndicator.Icon.Component { + iconOrImage = ChipDecoration.Icon.Component { Icon( imageVector = Source.Icons.Base.Plus, contentDescription = null, @@ -549,7 +549,7 @@ internal fun SourceChipPreview(modifier: Modifier = Modifier) { size = size, onClick = {}, showBadge = false, - iconOrImage = ChipIndicator.Image.Painter( + iconOrImage = ChipDecoration.Image.Painter( painter = painterResource(R.drawable.marina_hyde), contentDescription = null, ), @@ -561,7 +561,7 @@ internal fun SourceChipPreview(modifier: Modifier = Modifier) { size = size, onClick = {}, showBadge = false, - iconOrImage = ChipIndicator.Image.Painter( + iconOrImage = ChipDecoration.Image.Painter( painter = painterResource(R.drawable.marina_hyde), contentDescription = null, ), @@ -576,7 +576,7 @@ internal fun SourceChipPreview(modifier: Modifier = Modifier) { style = SourceChip.Style.Default.copy( badgeColour = AppColour.Unspecified, ), - iconOrImage = ChipIndicator.Icon.Vector( + iconOrImage = ChipDecoration.Icon.Vector( imageVector = Source.Icons.Base.Plus, ), ) @@ -618,7 +618,7 @@ internal fun SourceChipPreview(modifier: Modifier = Modifier) { size = SourceChip.Size.Medium, onClick = {}, style = SourceChip.Style.Default, - iconOrImage = ChipIndicator.Icon.Painter( + iconOrImage = ChipDecoration.Icon.Painter( painter = painterResource(R.drawable.ic_list), ), ) @@ -637,7 +637,7 @@ internal fun SourceChipPreview(modifier: Modifier = Modifier) { text = "Follow", size = SourceChip.Size.Medium, onClick = {}, - iconOrImage = ChipIndicator.Icon.Vector( + iconOrImage = ChipDecoration.Icon.Vector( imageVector = Source.Icons.Base.Plus, ), )