PillGroupItem

data class PillGroupItem(val key: Any?, val label: String, val selected: Boolean = false)(source)

Data class used for PillGroup

Samples

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import net.ikea.skapa.R
import net.ikea.skapa.foundation.*
import net.ikea.skapa.ui.components.Button
import net.ikea.skapa.ui.components.PillGroup
import net.ikea.skapa.ui.components.PillGroupItem
import net.ikea.skapa.ui.components.PillGroupState
import net.ikea.skapa.ui.components.PillLeadingItem.Icon
import net.ikea.skapa.ui.components.PillLeadingItem.Thumbnail

fun main() { 
   //sampleStart 
   SkapaTheme2(isSystemInDarkTheme()) {
    val items = listOf(
        PillGroupItem(null, "Functionality", true),
        PillGroupItem(
            key = null,
            label = "John Doe",
            selected = true,
            leadingItem = Thumbnail(painterResource(R.drawable.ic_image_fallback_image))
        ),
        PillGroupItem(key = null, label = "Pet-friendly", trailingIconId = R.drawable.ic_image_fallback_image),
        PillGroupItem(null, "Accessibility"),
        PillGroupItem(key = null, label = "Design", leadingItem = Icon(R.drawable.ic_image_fallback_image))
    ).toMutableStateList()

    var pillGroupState by remember { mutableStateOf(PillGroupState.Collapsed) }
    val maxVisibleItems = 3

    Column {
        PillGroup(
            items = items,
            maxVisibleItems = maxVisibleItems,
            // Provide localized text for the show more button
            expandedButtonLabel = "${items.size - maxVisibleItems} more...",
            state = pillGroupState,
            onStateChanged = { newState ->
                // Do something when state change
                pillGroupState = newState
            },
            onClickItem = { index, item ->
                // Do something Item Click
                items[index] = item.deepCopy(selected = !item.selected)
            }
        )
        // Offer a way back to the collapsed state
        if (pillGroupState == PillGroupState.Expanded) {
            Button(label = "Collapse") { pillGroupState = PillGroupState.Collapsed }
        }
    }
} 
   //sampleEnd
}

Constructors

Link copied to clipboard
constructor(key: Any?, label: String, selected: Boolean = false)
constructor(key: Any?, label: String, selected: Boolean = false, leadingItem: PillLeadingItem? = null, trailingIconId: Int? = null, @IntRange(from = 0) badgeValue: Int? = null)

Properties

Link copied to clipboard
@IntRange(from = 0)
var badgeValue: Int?
Link copied to clipboard
val key: Any?

A unique identifier for the item

Link copied to clipboard

The text to be displayed in the pill

Link copied to clipboard
Link copied to clipboard

The state of the pill

Link copied to clipboard

Functions

Link copied to clipboard
fun deepCopy(key: Any? = this.key, label: String = this.label, selected: Boolean = this.selected, leadingItem: PillLeadingItem? = this.leadingItem, trailingIconId: Int? = this.trailingIconId, @IntRange(from = 0) badgeValue: Int? = this.badgeValue): PillGroupItem

Creates a deep copy of the PillGroupItem with optional new values.