Skip to content

Switch ​

A two-state toggle with a capsule track and a circular thumb, supporting a loading-state placeholder.

Spec source: lh-ui-core/specs/switch.json · Golden cases: cases/switch.json (6 cases, translated into JVM unit tests + Compose UI Test)

States ​

When on, the track takes the primary color; when off, it takes the border color. The thumb diameter = height - 2 × switch.gap, and the slide animation uses motion.duration.base.

9:41Switch
Off
On
Disabled (off)
Disabled (on)
Loading (a spinner is shown in the thumb position; taps are ignored)

HTML mock preview (Android / Compose look), not an on-device render

kotlin
var on by remember { mutableStateOf(false) }
LhSwitch(checked = on, onChange = { on = it })

Sizes ​

Three sizes map to the switch.width / switch.height tokens.

9:41Switch sizes

HTML mock preview (Android / Compose look), not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
checkedWhether the switch is on (required)Boolean—
onChangeState change callback, carrying the new state(Boolean) -> Unit—
disabledWhether the switch is disabledBooleanfalse
loadingWhether the switch is loading (a spinner is shown in the thumb position; taps are ignored)Booleanfalse
lhSizeSizeLhSwitchSizeMedium
modifierModifierModifierModifier

LhSwitchSize ​

Valuewidthheight
Smallswitch.width.small (36dp)switch.height.small (20dp)
Mediumswitch.width.medium (44dp)switch.height.medium (24dp)
Largeswitch.width.large (52dp)switch.height.large (28dp)

The track is a capsule (corner radius is half the height); the tap target is the track area — a tap toggles the state and fires onChange.

Token reference ​

TokenUsage
switch.width.{small,medium,large}Three track widths
switch.height.{small,medium,large}Three track heights
switch.gapPadding between the thumb and the track (thumb diameter = height - 2 × gap)
color.primary.defaultOn-track color
color.border.baseOff-track color
color.onPrimaryThumb color
color.disabled.{bg,text}Disabled track / thumb colors
motion.duration.base / motion.easing.easeInOutThumb slide animation
loading.strokeWidthLoading ring stroke width (reused)

Golden case reference ​

case idAssertionLocal test
tap-toggles-and-emits-onchangeA tap toggles the state and emits onChangeLhSwitchTest.tap_unchecked_emits_true (Compose UI Test)
tap-checked-turns-offTapping the on state turns it offLhSwitchTest.tap_checked_emits_false
disabled-blocks-changeThe disabled state does not triggerLhSwitchTest.disabled_blocks_change
loading-blocks-changeThe loading state does not triggerLhSwitchTest.loading_blocks_change
checked-uses-primary-tokenOn consumes the primary tokenLhSwitchDefaultsTest.checked_uses_primary_token
unchecked-uses-border-tokenOff consumes the border tokenLhSwitchDefaultsTest.unchecked_uses_border_token
bash
./gradlew :components:switch:test                             # JVM part
./gradlew :components:switch:connectedAndroidTest            # Interaction part (requires a device)

lh-ui native bloodline · Android (Kotlin + Compose)