Bug 1891342 - Part 3: Add parameters to customize the enabled state and label text color in ListItem and IconListItem r=android-reviewers,007

Differential Revision: https://phabricator.services.mozilla.com/D207393
This commit is contained in:
Gabriel Luong 2024-04-19 04:40:30 +00:00
parent 811420e892
commit 1be42fab76

View file

@ -165,7 +165,10 @@ fun FaviconListItem(
* text and an optional [IconButton] or [Icon] at the end. * text and an optional [IconButton] or [Icon] at the end.
* *
* @param label The label in the list item. * @param label The label in the list item.
* @param labelTextColor [Color] to be applied to the label.
* @param description An optional description text below the label. * @param description An optional description text below the label.
* @param enabled Controls the enabled state of the list item. When `false`, the list item will not
* be clickable.
* @param onClick Called when the user clicks on the item. * @param onClick Called when the user clicks on the item.
* @param beforeIconPainter [Painter] used to display an [Icon] before the list item. * @param beforeIconPainter [Painter] used to display an [Icon] before the list item.
* @param beforeIconDescription Content description of the icon. * @param beforeIconDescription Content description of the icon.
@ -179,7 +182,9 @@ fun FaviconListItem(
@Composable @Composable
fun IconListItem( fun IconListItem(
label: String, label: String,
labelTextColor: Color = FirefoxTheme.colors.textPrimary,
description: String? = null, description: String? = null,
enabled: Boolean = true,
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
beforeIconPainter: Painter, beforeIconPainter: Painter,
beforeIconDescription: String? = null, beforeIconDescription: String? = null,
@ -191,28 +196,33 @@ fun IconListItem(
) { ) {
ListItem( ListItem(
label = label, label = label,
labelTextColor = labelTextColor,
description = description, description = description,
enabled = enabled,
onClick = onClick, onClick = onClick,
beforeListAction = { beforeListAction = {
Icon( Icon(
painter = beforeIconPainter, painter = beforeIconPainter,
contentDescription = beforeIconDescription, contentDescription = beforeIconDescription,
modifier = Modifier.padding(horizontal = 16.dp), modifier = Modifier.padding(horizontal = 16.dp),
tint = beforeIconTint, tint = if (enabled) beforeIconTint else FirefoxTheme.colors.iconDisabled,
) )
}, },
afterListAction = { afterListAction = {
val tint = if (enabled) afterIconTint else FirefoxTheme.colors.iconDisabled
if (afterIconPainter != null && onAfterIconClick != null) { if (afterIconPainter != null && onAfterIconClick != null) {
IconButton( IconButton(
onClick = onAfterIconClick, onClick = onAfterIconClick,
modifier = Modifier modifier = Modifier
.padding(end = 16.dp) .padding(end = 16.dp)
.size(ICON_SIZE), .size(ICON_SIZE),
enabled = enabled,
) { ) {
Icon( Icon(
painter = afterIconPainter, painter = afterIconPainter,
contentDescription = afterIconDescription, contentDescription = afterIconDescription,
tint = afterIconTint, tint = tint,
) )
} }
} else if (afterIconPainter != null) { } else if (afterIconPainter != null) {
@ -220,7 +230,7 @@ fun IconListItem(
painter = afterIconPainter, painter = afterIconPainter,
contentDescription = afterIconDescription, contentDescription = afterIconDescription,
modifier = Modifier.padding(end = 16.dp), modifier = Modifier.padding(end = 16.dp),
tint = afterIconTint, tint = tint,
) )
} }
}, },
@ -232,7 +242,10 @@ fun IconListItem(
* text and an optional [TextButton] at the end. * text and an optional [TextButton] at the end.
* *
* @param label The label in the list item. * @param label The label in the list item.
* @param labelTextColor [Color] to be applied to the label.
* @param description An optional description text below the label. * @param description An optional description text below the label.
* @param enabled Controls the enabled state of the list item. When `false`, the list item will not
* be clickable.
* @param onClick Called when the user clicks on the item. * @param onClick Called when the user clicks on the item.
* @param beforeIconPainter [Painter] used to display an [Icon] before the list item. * @param beforeIconPainter [Painter] used to display an [Icon] before the list item.
* @param beforeIconDescription Content description of the icon. * @param beforeIconDescription Content description of the icon.
@ -244,7 +257,9 @@ fun IconListItem(
@Composable @Composable
fun IconListItem( fun IconListItem(
label: String, label: String,
labelTextColor: Color = FirefoxTheme.colors.textPrimary,
description: String? = null, description: String? = null,
enabled: Boolean = true,
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
beforeIconPainter: Painter, beforeIconPainter: Painter,
beforeIconDescription: String? = null, beforeIconDescription: String? = null,
@ -255,14 +270,16 @@ fun IconListItem(
) { ) {
ListItem( ListItem(
label = label, label = label,
labelTextColor = labelTextColor,
description = description, description = description,
enabled = enabled,
onClick = onClick, onClick = onClick,
beforeListAction = { beforeListAction = {
Icon( Icon(
painter = beforeIconPainter, painter = beforeIconPainter,
contentDescription = beforeIconDescription, contentDescription = beforeIconDescription,
modifier = Modifier.padding(horizontal = 16.dp), modifier = Modifier.padding(horizontal = 16.dp),
tint = beforeIconTint, tint = if (enabled) beforeIconTint else FirefoxTheme.colors.iconDisabled,
) )
}, },
afterListAction = { afterListAction = {
@ -270,6 +287,7 @@ fun IconListItem(
TextButton( TextButton(
text = afterButtonText, text = afterButtonText,
onClick = onAfterButtonClick, onClick = onAfterButtonClick,
enabled = enabled,
textColor = afterButtonTextColor, textColor = afterButtonTextColor,
upperCaseText = false, upperCaseText = false,
) )
@ -335,9 +353,12 @@ fun RadioButtonListItem(
* *
* @param label The label in the list item. * @param label The label in the list item.
* @param modifier [Modifier] to be applied to the layout. * @param modifier [Modifier] to be applied to the layout.
* @param labelTextColor [Color] to be applied to the label.
* @param maxLabelLines An optional maximum number of lines for the label text to span. * @param maxLabelLines An optional maximum number of lines for the label text to span.
* @param description An optional description text below the label. * @param description An optional description text below the label.
* @param maxDescriptionLines An optional maximum number of lines for the description text to span. * @param maxDescriptionLines An optional maximum number of lines for the description text to span.
* @param enabled Controls the enabled state of the list item. When `false`, the list item will not
* be clickable.
* @param onClick Called when the user clicks on the item. * @param onClick Called when the user clicks on the item.
* @param beforeListAction Optional Composable for adding UI before the list item. * @param beforeListAction Optional Composable for adding UI before the list item.
* @param afterListAction Optional Composable for adding UI to the end of the list item. * @param afterListAction Optional Composable for adding UI to the end of the list item.
@ -346,16 +367,18 @@ fun RadioButtonListItem(
private fun ListItem( private fun ListItem(
label: String, label: String,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
labelTextColor: Color = FirefoxTheme.colors.textPrimary,
maxLabelLines: Int = 1, maxLabelLines: Int = 1,
description: String? = null, description: String? = null,
maxDescriptionLines: Int = 1, maxDescriptionLines: Int = 1,
enabled: Boolean = true,
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
beforeListAction: @Composable RowScope.() -> Unit = {}, beforeListAction: @Composable RowScope.() -> Unit = {},
afterListAction: @Composable RowScope.() -> Unit = {}, afterListAction: @Composable RowScope.() -> Unit = {},
) { ) {
Row( Row(
modifier = when (onClick != null) { modifier = when (onClick != null) {
true -> Modifier.clickable { onClick() } true -> Modifier.clickable(enabled = enabled) { onClick() }
false -> Modifier false -> Modifier
}.then( }.then(
Modifier.defaultMinSize(minHeight = LIST_ITEM_HEIGHT), Modifier.defaultMinSize(minHeight = LIST_ITEM_HEIGHT),
@ -371,7 +394,7 @@ private fun ListItem(
) { ) {
Text( Text(
text = label, text = label,
color = FirefoxTheme.colors.textPrimary, color = if (enabled) labelTextColor else FirefoxTheme.colors.textDisabled,
style = FirefoxTheme.typography.subtitle1, style = FirefoxTheme.typography.subtitle1,
maxLines = maxLabelLines, maxLines = maxLabelLines,
) )
@ -379,7 +402,7 @@ private fun ListItem(
description?.let { description?.let {
Text( Text(
text = description, text = description,
color = FirefoxTheme.colors.textSecondary, color = if (enabled) FirefoxTheme.colors.textSecondary else FirefoxTheme.colors.textDisabled,
style = FirefoxTheme.typography.body2, style = FirefoxTheme.typography.body2,
maxLines = maxDescriptionLines, maxLines = maxDescriptionLines,
) )
@ -435,12 +458,33 @@ private fun IconListItemPreview() {
Column(Modifier.background(FirefoxTheme.colors.layer1)) { Column(Modifier.background(FirefoxTheme.colors.layer1)) {
IconListItem( IconListItem(
label = "Left icon list item", label = "Left icon list item",
onClick = {},
beforeIconPainter = painterResource(R.drawable.mozac_ic_folder_24), beforeIconPainter = painterResource(R.drawable.mozac_ic_folder_24),
beforeIconDescription = "click me", beforeIconDescription = "click me",
) )
IconListItem(
label = "Left icon list item",
labelTextColor = FirefoxTheme.colors.textAccent,
onClick = {},
beforeIconPainter = painterResource(R.drawable.mozac_ic_folder_24),
beforeIconDescription = "click me",
beforeIconTint = FirefoxTheme.colors.iconAccentViolet,
)
IconListItem( IconListItem(
label = "Left icon list item + right icon", label = "Left icon list item + right icon",
onClick = {},
beforeIconPainter = painterResource(R.drawable.mozac_ic_folder_24),
beforeIconDescription = "click me",
afterIconPainter = painterResource(R.drawable.mozac_ic_chevron_right_24),
afterIconDescription = null,
)
IconListItem(
label = "Left icon list item + right icon (disabled)",
enabled = false,
onClick = {},
beforeIconPainter = painterResource(R.drawable.mozac_ic_folder_24), beforeIconPainter = painterResource(R.drawable.mozac_ic_folder_24),
beforeIconDescription = "click me", beforeIconDescription = "click me",
afterIconPainter = painterResource(R.drawable.mozac_ic_chevron_right_24), afterIconPainter = painterResource(R.drawable.mozac_ic_chevron_right_24),