PillGroupItem

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

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.IconPosition
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

fun main() { 
   //sampleStart 
   SkapaTheme2(darkTheme = isSystemInDarkTheme()) {
    val items = listOf(
        PillGroupItem(null, "Functionality", true),
        PillGroupItem(null, "John Doe", painterResource(R.drawable.ic_image_fallback_image), true),
        PillGroupItem(null, "Pet-friendly", R.drawable.ic_image_fallback_image, iconPosition = IconPosition.Horizontal.Trailing),
        PillGroupItem(null, "Accessibility"),
        PillGroupItem(null, "Design", 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, @DrawableRes iconId: Int, selected: Boolean = false, iconPosition: IconPosition.Horizontal = IconPosition.Horizontal.Leading)
constructor(key: Any?, label: String, painter: Painter, selected: Boolean = false)
constructor(key: Any?, label: String, selected: Boolean = false)

Creates a PillGroupItem with the provided parameters

Properties

Link copied to clipboard
var iconId: Int?

The drawable resource for the icon

Link copied to clipboard

The position of the icon in the pill

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

The painter for the thumbnail

Link copied to clipboard
val selected: Boolean = false

The state of the pill

Functions

Link copied to clipboard
fun deepCopy(key: Any? = this.key, label: String = this.label, selected: Boolean = this.selected, iconId: Int? = this.iconId, painter: Painter? = this.painter, iconPosition: IconPosition.Horizontal = this.iconPosition): PillGroupItem
Link copied to clipboard
Link copied to clipboard