OudsSwitchItem

fun OudsSwitchItem(checked: Boolean, label: String, onCheckedChange: (Boolean) -> Unit?, modifier: Modifier = Modifier, helperText: String? = null, icon: OudsControlItem.Icon? = null, divider: Boolean = false, reversed: Boolean = false, enabled: Boolean = true, readOnly: Boolean = false, error: Boolean = false, interactionSource: MutableInteractionSource? = null)

Switches allow the user to toggle between two states, typically "on" and "off". It is represented as a slider that changes its position or color to indicate the current state. Switches are used to enable or disable features, options, or settings in an intuitive and visual manner.

The switch item variant can function as a simple input with a label, or it can be combined with optional elements such as helper text, a divider, or an icon, allowing it to suit various use cases. It can be used in a list as a list item or as a single element to validate general conditions for example.

The OUDS switch item layout contains an OudsSwitch. By clicking on the switch item, the user changes the selected state of its switch.

In most cases, OUDS switch items span the entire width of the screen. Thus an horizontal padding of OudsTheme.grids.margin is applied to the content. This behaviour can be disabled by calling com.orange.ouds.core.utilities.edgeToEdgePadding modifier with enabled parameter set to false.

Parameters

checked

Controls checked state of the item's switch.

label

The main label of the switch item.

onCheckedChange

Callback invoked on switch item click. If null, then this is passive and relies entirely on a higher-level component to control the checked state.

modifier

Modifier applied to the layout of the switch item.

helperText

Optional text displayed below the label.

icon

Optional icon displayed in the item. By default, it has a trailing position. If reversed is set to true, it is displayed as a leading element.

divider

Controls the display of a divider at the bottom of the switch item.

reversed

When false, the switch has a leading position and the optional icon has a trailing position. Otherwise, it is reversed.

enabled

Controls the enabled state of the switch item. When false, the switch, the texts and the optional icon are disabled, and the item will not be clickable.

readOnly

Controls the read only state of the switch item. When true the item's switch is disabled but the texts and the icon remain in enabled color. Note that if it is set to true and enabled is set to false, the switch item will be displayed in disabled state.

error

Controls the error state of the switch item.

interactionSource

Optional hoisted MutableInteractionSource for observing and emitting Interactions for the item's switch. Note that if null is provided, interactions will still happen internally.

See also

If you want to use a standalone switch.

Samples

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.orange.ouds.core.component.OudsSwitchItem
import com.orange.ouds.core.utilities.OudsPreview

fun main() { 
   //sampleStart 
   OudsPreview {
    var checked by remember { mutableStateOf(true) }

    OudsSwitchItem(
        checked = checked,
        label = "Notifications",
        helperText = "Display app notifications in the notification center",
        onCheckedChange = { value -> checked = value },
        divider = false
    )
} 
   //sampleEnd
}