UX4G Logo
Components

Checkbox

Tri-state selection controls featuring custom sizes, helper/error/warning/success validation descriptions, required flags, and disabled states

The UX4G Checkbox suite provides accessible multi-selection and declaration controls supporting boolean (true/false) and indeterminate (null) tri-state values, context validation descriptions, and required field asterisks:

  1. Interactive Tri-State: Supports Checked (true), Unchecked (false), and Indeterminate (null).
  2. Context Validation: Built-in description variants (Helper, Error, Warning, Success) for form feedback.
  3. Required Field Support: Automatic red asterisk indicator (*) appended to the label with isRequired = true.
  4. Preset Sizes: Standardized dimension tokens (Small 16dp, Medium 20dp, Large 24dp).
  5. Disabled States: Compliant muted accessibility states for non-interactive forms.

Import from com.ux4g.designsystemv1.components.Ux4gCheckbox.


Interactive Preview

Ux4gCheckbox - States & LabelsJetpack Compose
UX4G Checkbox Preview

Kotlin Usage

Checkbox Showcase Example
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ux4g.designsystemv1.components.Ux4gCheckbox
import com.ux4g.designsystemv1.components.Ux4gCheckboxDescriptionVariant
import com.ux4g.designsystemv1.components.Ux4gCheckboxSize
import com.ux4g.designsystemv1.foundation.Ux4gColors
import com.ux4g.designsystemv1.foundation.Ux4gIcons
import com.ux4g.designsystemv1.foundation.defaultTypography

@Composable
fun CheckboxShowcaseScreen() {
    Surface(color = Ux4gColors.white) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .padding(16.dp),
            verticalArrangement = Arrangement.spacedBy(16.dp)
        ) {
            // 1. Medium Checked with Helper
            var val1 by remember { mutableStateOf<Boolean?>(true) }
            Ux4gCheckbox(
                value = val1,
                onValueChange = { val1 = it },
                label = "Medium Checked",
                size = Ux4gCheckboxSize.Medium,
                description = "This is a helper description",
                descriptionVariant = Ux4gCheckboxDescriptionVariant.Helper
            )

            // 2. Large Unchecked Required with Error
            var val2 by remember { mutableStateOf<Boolean?>(false) }
            Ux4gCheckbox(
                value = val2,
                onValueChange = { val2 = it },
                label = "Large Unchecked Required",
                size = Ux4gCheckboxSize.Large,
                isRequired = true,
                description = "This field is required",
                descriptionVariant = Ux4gCheckboxDescriptionVariant.Error
            )

            // 3. Small Indeterminate with Warning
            var val3 by remember { mutableStateOf<Boolean?>(null) }
            Ux4gCheckbox(
                value = val3,
                onValueChange = { val3 = it },
                label = "Small Indeterminate Warning",
                size = Ux4gCheckboxSize.Small,
                description = "This is a warning",
                descriptionVariant = Ux4gCheckboxDescriptionVariant.Warning,
                trailingIcon = Ux4gIcons.Settings
            )

            // 4. Medium Success State
            var val4 by remember { mutableStateOf<Boolean?>(true) }
            Ux4gCheckbox(
                value = val4,
                onValueChange = { val4 = it },
                label = "Medium Success",
                size = Ux4gCheckboxSize.Medium,
                description = "Successfully validated",
                descriptionVariant = Ux4gCheckboxDescriptionVariant.Success
            )

            // 5. Disabled Non-Interactive States
            Text(
                text = "Disabled States",
                style = defaultTypography.hS_default,
                color = Ux4gColors.neutral900
            )

            Ux4gCheckbox(
                value = false,
                onValueChange = {},
                label = "Disabled Unchecked",
                size = Ux4gCheckboxSize.Medium,
                isRequired = true,
                enabled = false
            )

            Ux4gCheckbox(
                value = true,
                onValueChange = {},
                label = "Disabled Checked",
                size = Ux4gCheckboxSize.Medium,
                isRequired = true,
                enabled = false
            )

            Ux4gCheckbox(
                value = null,
                onValueChange = {},
                label = "Disabled Indeterminate",
                size = Ux4gCheckboxSize.Medium,
                isRequired = true,
                enabled = false
            )
        }
    }
}

Parameters

Ux4gCheckbox Props

PropTypeDescriptionDefault
value *Boolean?Tri-state value: true (Checked), false (Unchecked), null (Indeterminate).—
onValueChange *(Boolean?) -> UnitCallback invoked when citizen taps the checkbox.—
modifierModifierCompose layout modifier applied to outer row.Modifier
labelString?Primary label text displayed next to checkbox box.null
descriptionString?Secondary helper or validation message displayed below label.null
sizeUx4gCheckboxSizeCheckbox box & typography dimension preset: Small, Medium, Large.Ux4gCheckboxSize.Medium
isRequiredBooleanWhen true, appends red asterisk (*) to the label.false
hasErrorBooleanForces checkbox border into red error color state.false
descriptionVariantUx4gCheckboxDescriptionVariantVisual feedback tone: Helper, Error, Warning, Success.Ux4gCheckboxDescriptionVariant.Helper
enabledBooleanWhether checkbox responds to citizen touch interaction.true
trailingIconUx4gIcon?Optional icon composable displayed after label text.null
checkedIconUx4gIcon?Custom icon replacing default white checkmark tick.null
indeterminateIconUx4gIcon?Custom icon replacing default horizontal minus bar.null
interactionSourceMutableInteractionSourceInteraction state tracker for ripple touch effects.remember { MutableInteractionSource() }

Ux4gCheckboxSize Enum

TokenBox DimensionsTypography Style
Small16.dp x 16.dpLabel Medium (12.sp)
Medium20.dp x 20.dpLabel Large (14.sp)
Large24.dp x 24.dpLabel XL (16.sp)

Ux4gCheckboxDescriptionVariant Enum

VariantText ColorIntended Context
HelperNeutral Gray (#374151)General guidance and supplementary explanation.
ErrorRed (#DC2626)Mandatory checkbox missing, validation failed.
WarningOrange (#EA580C)Cautionary guidance (e.g. battery drain, permission note).
SuccessGreen (#16A34A)Successful Aadhaar/consent verification.

On this page