Skip to content

Switch ​

A switch. A pill-shaped track plus a circular thumb; tapping toggles it. It supports disabled and loading states.

Spec source: lh-ui-core/specs/switch.json · Golden cases: lh-ui-core/cases/switch.json (6 cases, translated into xUnit tests)

Basic usage ​

9:41Switch basics

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

csharp
var sw = new LhSwitch { Checked = true };
sw.Change += isChecked => { };

Sizes ​

Three sizes map to the switch.width / switch.height tokens; the thumb diameter = height - 2 × switch.gap.

9:41Switch sizes

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

States ​

Disabled and Loading both suppress taps; while Loading the thumb position is replaced by a primary-colored loading ring.

9:41Switch states

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
ChangeToggled-state callback; not fired when disabled or loadingevent Action<bool>—
CheckedWhether the switch is onboolfalse
DisabledWhether the switch is disabled (does not respond to taps and renders the disabled style)boolfalse
LoadingWhether the switch is loading (shows a loading ring at the thumb position and does not respond to taps)boolfalse
SizeSwitch size; maps to the switch.width / switch.height tokensLhSwitchSizeMedium

LhSwitchSize ​

Valuewidthheight
Smallswitch.width.small (40epx)switch.height.small (22epx)
Mediumswitch.width.medium (48epx)switch.height.medium (26epx)
Largeswitch.width.large (56epx)switch.height.large (30epx)

Token Reference ​

TokenUsage
switch.width.{small,medium,large}Three track widths
switch.height.{small,medium,large}Three track heights
switch.gapSpacing between the thumb and the track (thumb diameter = height - 2 × gap)
color.primary.defaultOn-state track color
color.border.baseOff-state track color
color.onPrimaryThumb color
color.disabled.bg / color.text.disabledDisabled track / thumb color

Golden Case Reference ​

How the 6 assertions of cases/switch.json map to xUnit tests (tests/LhSwitchTests.cs):

case idAssertionLocal test
tap-toggles-and-emits-onchangeA tap toggles and fires onChangeTap_Toggles_And_Emits_OnChange
tap-checked-turns-offA tap on the on state turns it offTap_Checked_Turns_Off
disabled-blocks-changeThe disabled state is not interactiveDisabled_Blocks_Change
loading-blocks-changeThe loading state is not interactiveLoading_Blocks_Change
checked-uses-primary-tokenThe on state consumes the primary tokenChecked_Uses_Primary_Token
unchecked-uses-border-tokenThe off state consumes the border tokenUnchecked_Uses_Border_Token

Plus dark-mode suites: Dark_Colors_Come_From_Dark_Tokens / Dimensions_Are_Identical_In_Dark_Mode. Run: cd lh-ui-windows && dotnet test.

lh-ui native bloodline · Windows (C# + WinUI 3)