PillGroup
Pill Group component allows Pills to be combined together inside a Row to achieve group-like behaviour. PillGroup implements the fixed-width container behaviour and wrap pills onto new rows, similar to a paragraph of text. The container height can be controlled by determining a maximum number of visible pills. When the number of maximum visible pills is set, an overflow button allows users to reveal the remaining content. Actions bound to the overflow button can vary.
Parameters
A list of PillGroupItems to be displayed in the same selectable group.
Modifier to be applied to the radio button layout
PillSize defines the size of the pills. The default value is PillSize.Medium.
The horizontal alignment of the pills.
A maximum number of visible pills that should be displayed before showing overflow button.
label to be display in the last pill button when state is PillGroupState.Collapsed
current PillGroupState of the group. it determines if the group is either Expanded or Collapsed
if the PillGroup is collapsed and you click the show more button, this callback is invoked.
Will be called when the user clicks a Pill.
See also
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
SkapaThemeM3(darkTheme = isSystemInDarkTheme()) {
val items = listOf(
PillGroupItem(null, "Functionality", true),
PillGroupItem(null, "John Doe", painterResource(R.drawable.ic_skapa_fallback_image), true),
PillGroupItem(null, "Pet-friendly", R.drawable.ic_skapa_fallback_image, iconPosition = IconPosition.Horizontal.Trailing),
PillGroupItem(null, "Accessibility"),
PillGroupItem(null, "Design", R.drawable.ic_skapa_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
}