Switch

fun Switch(checked: Boolean, modifier: Modifier = Modifier, enabled: Boolean = true, variant: SwitchVariant = SwitchVariant.Emphasised, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, onCheckedChange: (Boolean) -> Unit?)(source)

Switch is a binary control for turning a setting or feature 'on' or 'off' with immediate effect.

A switch's value always represents the current state of a setting or feature. Changing the switch value directly alters the application as soon as the value changes. It's built on top of androidx.compose.material.Switch and comes with predefined appearance based on Skapa design and guidelines.

A switch should be associated with a label. If a switch is used without one, it must strongly connect to another element that represents the value being selected.

Parameters

checked

whether or not this component is checked.

modifier

Modifier to be applied to the switch layout.

enabled

whether the component is enabled or grayed out.

variant

SwitchVariant defines the button style from Skapa Switch Variants. The default value is SwitchVariant.Emphasised.

interactionSource

The MutableInteractionSource representing the stream of Interactions for this Switch. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Switch in different Interactions.

onCheckedChange

callback to be invoked when Switch is being clicked, therefore the change of checked state is requested. If null, then this is passive and relies entirely on a higher-level component to control the "checked" state.

See also

Samples

var state by rememberSaveable { mutableStateOf(true) }
Switch(state) { state = it }

fun Switch(label: String, checked: Boolean, modifier: Modifier = Modifier, enabled: Boolean = true, variant: SwitchVariant = SwitchVariant.Emphasised, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, onCheckedChange: (Boolean) -> Unit?)(source)

Switch is a binary control for turning a setting or feature 'on' or 'off' with immediate effect.

A switch's value always represents the current state of a setting or feature. Changing the switch value directly alters the application as soon as the value changes. It's built on top of androidx.compose.material.Switch and comes with predefined appearance based on Skapa design and guidelines.

A switch should be associated with a label. If a switch is used without one, it must strongly connect to another element that represents the value being selected.

Parameters

label

The text to be displayed together with Switch component.

checked

whether or not this component is checked.

modifier

Modifier to be applied to the switch layout.

enabled

whether the component is enabled or grayed out.

variant

SwitchVariant defines the button style from Skapa Switch Variants. The default value is SwitchVariant.Emphasised.

interactionSource

The MutableInteractionSource representing the stream of Interactions for this Switch. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Switch in different Interactions.

onCheckedChange

callback to be invoked when Switch is being clicked, therefore the change of checked state is requested. If null, then this is passive and relies entirely on a higher-level component to control the "checked" state.

See also

Samples

SkapaTheme2(isSystemInDarkTheme()) {
    Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
        var state by rememberSaveable { mutableStateOf(true) }
        Switch(label = "Switch Label", checked = state, variant = SwitchVariant.Emphasised) { state = it }
        Switch(label = "Switch Label", checked = state, variant = SwitchVariant.Subtle) { state = it }
        Switch(
            label = "When a Switch label exceeds one line the text overflows onto a second",
            checked = state,
            variant = SwitchVariant.Subtle
        ) { state = it }
        Switch(checked = true, enabled = false, variant = SwitchVariant.Emphasised) { state = it }
        Switch(checked = false, enabled = false, variant = SwitchVariant.Emphasised) { state = it }
        Switch(checked = true, enabled = false, variant = SwitchVariant.Subtle) { state = it }
        Switch(checked = false, enabled = false, variant = SwitchVariant.Subtle) { state = it }
    }
}