CheckboxGroup

fun <T> CheckboxGroup(items: List<CheckboxGroupItem<T>>, modifier: Modifier = Modifier, groupName: String? = null, variant: CheckboxVariant = CheckboxVariant.Emphasised, required: RequiredLabel? = null, onItemChecked: (index: Int, item: CheckboxGroupItem<T>, checked: Boolean) -> Unit)(source)

Checkbox Group component allows Checkboxes to be combined together with a Text inside a Column to achieve group-like behaviour.

Parameters

items

A list of CheckboxGroupItem items to be displayed in the same selectable group.

modifier

Modifier to be applied to the layout of the checkbox

groupName

An informative and descriptive name to be displayed above the checkboxes.

variant

CheckboxVariant defines the button style from Skapa Checkbox Variants. The default value is CheckboxVariant.Subtle.

required

Whether the group is required to be selected. Will add a leading asterisk (*) and requires a contentDescription.

onItemChecked

callback to be invoked when a Checkbox is selected.

Type Parameters

T

The type of the key used to uniquely identify each checkbox item.

See also

Samples

val items = remember {
    mutableStateListOf(
        CheckboxGroupItem(key = 1, label = "Option 1", checked = true),
        CheckboxGroupItem(key = 2, label = "Option 2"),
        CheckboxGroupItem(key = 3, label = "Option 3", enabled = false),
        CheckboxGroupItem(key = 4, label = "Option 4", checked = true)
    )
}

SkapaTheme2(isSystemInDarkTheme()) {
    Column {
        CheckboxGroup(
            groupName = "Checkbox group",
            modifier = Modifier.fillMaxWidth(),
            items = items
        ) { index, item, checked ->
            items[index] = item.copy(checked = checked)
        }
        HelperText(label = "Error message", state = HelperTextState.Error)
        Spacer(modifier = Modifier.height(SkapaSpacing.space100))
        CheckboxGroup(
            groupName = "Checkbox group",
            modifier = Modifier.fillMaxWidth(),
            items = items
        ) { index, item, checked ->
            items[index] = item.copy(checked = checked)
        }
        HelperText(label = "Message", state = HelperTextState.Regular)
    }
}