Pantrix UI

List Item

A row of a list: a title, with what leads it, what ends it and a line or two under it, as a list of messages, of settings or of results has.

import com.pantrixui.components.data.listitem.PantrixListItem

Examples

An inbox

An inbox: who wrote, when, and about what. A press on a row chooses it; the chosen row is filled. The lines are drawn from where the text starts, and leave the column of avatars whole.

var open by remember { mutableStateOf("0") }
Column {
    INBOX.forEachIndexed { index, mail ->
        PantrixListItem(
            headline = mail.from,
            supportingText = mail.subject,
            trailingText = mail.time,
            leading = { PantrixAvatar(contentDescription = null, initials = mail.initials) },
            selected = open == "$index",
            onClick = { open = "$index" },
            divider = ListItemDivider.Inset,
            tagKey = "mail_$index"
        )
    }
}

private class InboxMessage(
    val from: String,
    val initials: String,
    val subject: String,
    val time: String
)

private val INBOX = listOf(
    InboxMessage("Ayşe Demir", "AD", "The agenda of Monday's meeting", "12:40"),
    InboxMessage("Mert Kaya", "MK", "The design files are ready", "11:05"),
    InboxMessage("Elif Şahin", "EŞ", "Invoice: October", "Yesterday")
)

Settings

Settings: the rows that lead on to another screen have their values and a chevron at their end. The notifications' row is not pressed; the switch at its end is a control of its own. A row that is turned off takes no press and is written faintly.

var notify by remember { mutableStateOf(true) }
Column {
    PantrixListItem(
        headline = "Downloads",
        trailingText = "Wi-Fi only",
        leading = { PantrixIcon(PantrixIcons.Download, contentDescription = null) },
        chevron = true,
        onClick = {},
        divider = ListItemDivider.Full,
        tagKey = "downloads"
    )
    PantrixListItem(
        headline = "Notifications",
        supportingText = "When a new message comes",
        leading = { PantrixIcon(PantrixIcons.Inbox, contentDescription = null) },
        trailing = {
            PantrixSwitchButton(
                checked = notify,
                onCheckedChange = { notify = it },
                contentDescription = "Notifications",
                tagKey = "notify"
            )
        },
        divider = ListItemDivider.Full,
        tagKey = "notifications"
    )
    PantrixListItem(
        headline = "Backup",
        supportingText = "Not in your plan",
        leading = { PantrixIcon(PantrixIcons.Upload, contentDescription = null) },
        chevron = true,
        onClick = {},
        enabled = false,
        tagKey = "backup"
    )
}

Three lines

Three lines, read and not pressed: the date over it, up to two lines of supporting text under it, a tag at its end. In a row of three lines what leads and ends it stands at its top.

Column {
    PantrixListItem(
        headline = "Order 1042",
        overline = "28 October",
        supportingText = "Two books and a notebook. Shipped, and expected to arrive tomorrow.",
        trailing = { PantrixTag(text = "On its way", tone = TagTone.Info) },
        divider = ListItemDivider.Full,
        tagKey = "order_1042"
    )
    PantrixListItem(
        headline = "Order 1039",
        overline = "21 October",
        supportingText = "A pair of headphones.",
        trailing = { PantrixTag(text = "Delivered", tone = TagTone.Success) },
        tagKey = "order_1039"
    )
}

What a search found

A search's results: the word searched for is set in bold in the title (the overload that takes an AnnotatedString), and the supporting text says where it was found.

val typed = "Area"
Column {
    listOf("Text Area", "Filled Text Area").forEachIndexed { index, title ->
        val at = title.indexOf(typed)
        PantrixListItem(
            headline = buildAnnotatedString {
                append(title.take(at))
                withStyle(SpanStyle(fontWeight = FontWeight.ExtraBold)) { append(typed) }
                append(title.drop(at + typed.length))
            },
            supportingText = "Component · Form",
            leading = { PantrixIcon(PantrixIcons.Search, contentDescription = null) },
            onClick = {},
            tagKey = "found_$index"
        )
    }
}

A style and colours of its own

A style and colours of its own: denser rows (ListItemStyle), the title in the theme's callout role, the selected row in a success colour (ListItemColors), the supporting text in the footnote type (supportingTextStyle), the price in the code type (trailingTextStyle).

val success = PantrixTheme.colors.success
var chosen by remember { mutableStateOf(0) }
Column {
    listOf("Weekly" to "29 ₺", "Monthly" to "99 ₺", "Yearly" to "990 ₺").forEachIndexed { index, (plan, price) ->
        PantrixListItem(
            headline = plan,
            supportingText = if (index == 2) "Two months on us" else null,
            trailingText = price,
            selected = chosen == index,
            onClick = { chosen = index },
            style = ListItemStyle(oneLineHeight = 40.dp, twoLineHeight = 52.dp, headlineRole = TypeRole.Callout),
            colors = ListItemColors(selectedContainer = success.container, selectedContent = success.onContainer),
            supportingTextStyle = PantrixTheme.typography.footnote,
            trailingTextStyle = PantrixTheme.typography.code,
            tagKey = "plan_$index"
        )
    }
}

API

headline

A row of a list: a title, with what leads it, what ends it and a line or two under it, as a list of messages, of settings or of results has.

ParameterTypeDefaultWhat it is
headlineStringwhat the row is, in a few words: its name for a screen reader.
modifierModifierModifierthe row's modifier. The row is as wide as it is given, and at least as tall as its style's height for the lines it has.
supportingTextString?nulla line or two under the title, in a smaller and quieter type: what the row says more.
overlineString?nulla short line over the title, in the theme's caption: a category, a date.
trailingTextString?nulla short text at the end of the title's line, on its baseline, in trailingTextStyle: a time, a count, a setting's value.
leading(@Composable () -> Unit)?nullwhat leads the row: an icon, an avatar, a picture. It is given the row's quiet colour.
trailing(@Composable () -> Unit)?nullwhat ends the row: a badge, a button, a switch. It is given the row's quiet colour.
chevronBooleanfalsewhether a chevron ends the row, after trailing, for a row that leads on to another screen.
onClick(() -> Unit)?nullwhat a press on the row does. Null makes it a row that is read and not pressed.
selectedBooleanfalsewhether the row is the one chosen, as the message shown beside a list is.
enabledBooleantruewhether the row can be pressed. One that cannot is written in the disabled colour.
dividerListItemDividerListItemDivider.Nonethe line the row draws under itself.
supportingMaxLinesInt2how many lines supportingText runs to before it is cut.
styleListItemStyle?nullthis call's own style: over every enclosing one and under the density.
colorsListItemColors?nullthis row's own colours, where they are not the theme's.
tagKeyString?nullthe row's automation key: the row is ListItem_<tagKey>.
headlineStyleTextStyle?nullthe type the title is set in: the style's headlineRole unless given.
supportingTextStyleTextStyle?nullthe type the supporting text is set in: the style's supportingRole unless given.
trailingTextStyleTextStyle?nullthe type trailingText is set in: supportingTextStyle unless given, as a time beside a message's title is written in the message's own small type.

headline

A row of a list whose title has more in it than words: a word marked where a search found it, a part in bold.

ParameterTypeDefaultWhat it is
headlineAnnotatedStringwhat the row is, with its spans: its name for a screen reader.
modifierModifierModifierthe row's modifier. The row is as wide as it is given, and at least as tall as its style's height for the lines it has.
supportingTextString?nulla line or two under the title, in a smaller and quieter type: what the row says more.
overlineString?nulla short line over the title, in the theme's caption: a category, a date.
trailingTextString?nulla short text at the end of the title's line, on its baseline, in trailingTextStyle: a time, a count, a setting's value.
leading(@Composable () -> Unit)?nullwhat leads the row: an icon, an avatar, a picture. It is given the row's quiet colour.
trailing(@Composable () -> Unit)?nullwhat ends the row: a badge, a button, a switch. It is given the row's quiet colour.
chevronBooleanfalsewhether a chevron ends the row, after trailing, for a row that leads on to another screen. It is drawn in the row's quiet colour, turned round where the layout is read from the right, and not read out.
onClick(() -> Unit)?nullwhat a press on the row does. Null makes it a row that is read and not pressed.
selectedBooleanfalsewhether the row is the one chosen, as the message shown beside a list is.
enabledBooleantruewhether the row can be pressed. One that cannot takes no press and is written in the disabled colour.
dividerListItemDividerListItemDivider.Nonethe line the row draws under itself: none, one across the row, or one from where its text starts.
supportingMaxLinesInt2how many lines supportingText runs to before it is cut with an ellipsis.
styleListItemStyle?nullthis call's own style: over every enclosing one and under the density. Only the fields it sets change, on every platform.
colorsListItemColors?nullthis row's own colours: the ones it sets, with the theme's for the rest.
tagKeyString?nullthe row's automation key: the row is ListItem_<tagKey>.
headlineStyleTextStyle?nullthe type the title is set in: the style's headlineRole unless given. A colour in it is not the title's, which is the row's.
supportingTextStyleTextStyle?nullthe type the supporting text is set in: the style's supportingRole unless given.
trailingTextStyleTextStyle?nullthe type trailingText is set in: supportingTextStyle unless given, as a time beside a message's title is written in the message's own small type.

ListItemStyle

PantrixListItem's geometry and type: how tall a row of one, two and three lines is at the least, the room around and between what it holds, the corners of its fill and the types it writes in.

ParameterTypeDefaultWhat it is
oneLineHeightDpDp.UnspecifiedThe least height of a row of its title alone.
twoLineHeightDpDp.UnspecifiedThe least height of a row of a title and one other line: an overline or a supporting text.
threeLineHeightDpDp.UnspecifiedThe least height of a row of a title, an overline and a supporting text.
horizontalPaddingDpDp.UnspecifiedThe room between the row's sides and what it holds.
verticalPaddingDpDp.UnspecifiedThe room over and under what the row holds, where it is taller than the least height.
gapDpDp.UnspecifiedThe room between what leads the row, its text and what ends it.
shapeShapeSpecShapeSpec.UnspecifiedThe corners of the row's fill: none on Android and iOS, small on the desktop and the web.
chevronSizeDpDp.UnspecifiedThe width and height of the chevron at the end of a row that leads on.
headlineRoleTypeRole?nullThe type the title is set in: the body on Android and iOS, the label on the desktop and the web.
supportingRoleTypeRole?nullThe type the supporting text and the trailing text are set in: the label on Android and iOS, the footnote on the desktop and the web.

ListItemColors

What a PantrixListItem is painted with, where it is not the theme's: a colour that is set is used, and one that is left out stays the theme's.

ParameterTypeDefaultWhat it is
containerColorColor.UnspecifiedThe row's own fill: none, by default.
contentColorColor.UnspecifiedThe title and the trailing text: the theme's primary text on its grounds, what reads on a fill.
supportingContentColorColor.UnspecifiedThe overline, the supporting text and the chevron: the theme's secondary text on its grounds, and on a fill content.
selectedContainerColorColor.UnspecifiedThe fill of a selected row: the primary role's container.
selectedContentColorColor.UnspecifiedWhat a selected row is written in: what the theme pairs with selectedContainer.
dividerColorColor.UnspecifiedThe line under a row that draws one: the theme's divider on its grounds, a share of content on a fill.