SegmentedSwitch
fun SegmentedSwitch(onOptionClick: (selectedIndex: Int) -> Unit, optionOne: @Composable () -> Unit, optionTwo: @Composable () -> Unit, selectedIndex: Int?, modifier: Modifier = Modifier, label: @Composable () -> Unit = {}, error: @Composable () -> Unit? = null, info: @Composable () -> Unit? = null)
A segmented switch displaying two options.
Renders a segmented switch displaying optionOne and optionTwo. Modify via custom passed modifier. An information or error footer can be added to the field.
Example:
var selectedIndex by remember { mutableStateOf<Int?>(null) }
SegmentedSwitch(
optionOne = { Text("Off") },
optionTwo = { Text("On") },
selectedIndex = selectedIndex,
onOptionClick = { index -> selectedIndex = index },
label = { Text("Feature") },
info = { Text("This is contextual information.") },
)
Content copied to clipboard
fun SegmentedSwitch(onOptionClick: (selectedIndex: Int) -> Unit, options: List<@Composable () -> Unit>, selectedIndex: Int?, modifier: Modifier = Modifier, label: @Composable () -> Unit = {}, error: @Composable () -> Unit? = null, info: @Composable () -> Unit? = null)
A segmented switch displaying multiple options.
Renders a segmented switch displaying options. Modify via custom passed modifier. An information or error footer can be added to the field.
Example:
var selectedIndex by remember { mutableStateOf<Int?>(null) }
SegmentedSwitch(
options = listOf(
{ Text("First") },
{ Text("Second") },
{ Text("Third") },
),
selectedIndex = selectedIndex,
onOptionClick = { index -> selectedIndex = index },
label = { Text("Options") },
error = if (selectedIndex == null) {
{ Text("Please select an option.") }
} else {
null
},
)
Content copied to clipboard