Skip to content

Checkbox ​

A controlled checkbox. @Binding var checked provides two-way binding; it supports three states (checked / unchecked / indeterminate).

Spec source: lh-ui-core/specs/checkbox.json · Golden cases: lh-ui-core/cases/checkbox.json (6 entries, translated into XCTest, runnable on the macOS host)

States ​

The checked state is a solid primary-colored square with a white check mark; the indeterminate state is a solid primary-colored square with a white dash; the unchecked state is an empty outlined box.

9:41Checkbox states
UncheckedChecked
IndeterminateDisabled

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

swift
@State private var checked = false

LhCheckbox(checked: $checked, label: "Checked") { newValue in
  // onChange
}

Sizes ​

Three sizes map to the checkbox.size tokens; the check stroke width comes from checkbox.checkWidth, and the indeterminate dash width is the box size times checkbox.dashScale (50%).

9:41Checkbox sizes
SmallMediumLarge

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

Indeterminate state ​

When indeterminate = true, a dash is shown instead of a check mark; a tap always flips it to checked (golden case indeterminate-becomes-checked), rather than toggling.

swift
@State private var checked = false

LhCheckbox(checked: $checked, label: "Select all", indeterminate: somePartial) { _ in }

API ​

Props ​

PropDescriptionTypeDefault
checkedChecked state (controlled two-way binding)Bool—
indeterminateWhether indeterminate (shows a dash; a tap turns it checked)Boolfalse
disabledWhether disabled (does not fire onChange)Boolfalse
lhSizeCheckbox size, mapped to the size tokensLhCheckboxSize.medium
labelText labelString""
onChangeState-change callback; the payload is the new value((Bool) -> Void)?nil

LhCheckboxSize ​

ValueSize
.smallcheckbox.size.small (16pt)
.mediumcheckbox.size.medium (20pt)
.largecheckbox.size.large (24pt)

Colors ​

StateBox backgroundMark color
UncheckedTransparent + color.border.base border (checkbox.borderWidth)—
Checked / indeterminatecolor.primary.defaultcolor.onPrimary
Disabledcolor.disabled.bg + color.disabled.border bordercolor.disabled.text

Token Reference ​

TokenPurpose
checkbox.size.{small,medium,large}Three sizes
checkbox.borderRadius / checkbox.borderWidthCorner radius (follows radius.small) and border width
checkbox.checkWidthCheck-mark stroke width
checkbox.dashScaleRatio of the indeterminate dash to the box (50%)
checkbox.gapGap between the box and the text (follows spacing.sm)
color.primary.default / color.onPrimaryChecked background / mark color
color.border.baseUnchecked border color
color.disabled.{bg,border,text}Three disabled colors

Golden Case Mapping ​

case idAssertionLocal test
tap-toggles-and-emits-onchangeA tap flips the state and fires onChange(true)testTapTogglesAndEmitsOnChange
tap-checked-unchecksTapping a checked box unchecks ittestTapCheckedUnchecks
disabled-blocks-changeThe disabled state does not fire onChangetestDisabledBlocksChange
checked-uses-primary-tokensThe checked state consumes primary and onPrimarytestCheckedUsesPrimaryTokens
unchecked-uses-border-tokenThe unchecked state consumes the border tokentestUncheckedUsesBorderToken
indeterminate-becomes-checkedTapping the indeterminate state always yields checkedtestIndeterminateBecomesChecked

Plus dedicated tests: testSizeUsesSizeTokens / testStrokeUsesCheckboxTokens / testDarkColorsComeFromDarkTokens / testDisabledInDarkUsesDarkDisabledTokens / testDimensionsAreIdenticalInDarkMode / testCheckboxViewInitAcceptsConstant.

bash
swift test --filter LhCheckboxTests    # Runs on the macOS host, no simulator required

lh-ui native bloodline · iOS (Swift + SwiftUI)