StylishConnectedSegmentedControl

fun <T> StylishConnectedSegmentedControl(options: List<StylishSegmentedOption<T>>, selectedValue: T, onSelectedChange: (T) -> Unit, modifier: Modifier = Modifier, labelStyle: TextStyle = MaterialTheme.typography.labelLarge, labelMaxLines: Int = 1, labelOverflow: TextOverflow = TextOverflow.Ellipsis, selectedColors: ButtonColors = ButtonDefaults.buttonColors( containerColor = MaterialTheme.colorScheme.primary, contentColor = MaterialTheme.colorScheme.onPrimary, ), defaultColors: ButtonColors = ButtonDefaults.buttonColors( containerColor = MaterialTheme.stylishComponentColors.groupedContainer, contentColor = MaterialTheme.colorScheme.onSurface, ), spacing: Dp = StylishTheme.dimensions.connectedSpacing)

A connected segmented control for mutually exclusive selection among a small set of options.

Renders a horizontally joined row of segment buttons where exactly one segment is visually highlighted at a time. Use this when the user must pick one mode or view from two-to-five alternatives (e.g. list vs. grid). Internally composes StylishConnectedButtonRow and maps each StylishSegmentedOption to a StylishConnectedButtonItem; a custom button renderer animates each segment's container/content colors when the selection changes, so the highlight cross-fades instead of snapping.

Parameters

options

The selectable segments. Each StylishSegmentedOption carries a value, a display label, an enabled flag, and optional leadingContent/trailingContent icon slots rendered before/after the label.

selectedValue

The currently selected value. The segment whose StylishSegmentedOption.value equals this is rendered with selectedColors.

onSelectedChange

Callback invoked with the tapped segment's value.

labelStyle

TextStyle for each segment label. Defaults to MaterialTheme.typography.labelLarge.

labelMaxLines

Maximum lines for each segment label. Defaults to 1.

labelOverflow

TextOverflow strategy when a label exceeds labelMaxLines. Defaults to TextOverflow.Ellipsis.

selectedColors

ButtonColors applied to the active segment. Defaults to MaterialTheme.colorScheme.primary container with MaterialTheme.colorScheme.onPrimary content.

defaultColors

ButtonColors applied to inactive segments. Defaults to MaterialTheme.stylishComponentColors.groupedContainer container with MaterialTheme.colorScheme.onSurface content.

spacing

Horizontal gap between joined segments. Defaults to StylishTheme.dimensions.connectedSpacing (typically 3.dp).

See also