Skip to content

Button ​

A basic action button. It triggers an immediate action and supports types, sizes, loading, disabled, icons, and a Chinese-style pattern background.

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

Types ​

Six types determine the background and text colors.

9:41Button types

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

swift
LhButton(lhOnClick: {}, type: .primary, text: "Primary")

Sizes ​

Three sizes map to the button.height / paddingHorizontal / fontSize / iconSize tokens. The iOS shape uses a capsule corner radius (the radius.round token).

9:41Button sizes

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

States ​

Neither the disabled nor the loading state fires lhOnClick; when both are present, disabled wins (golden case disabled-precedes-loading).

9:41Button states

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

Icon and pattern background ​

Icon names resolve against the local icon system (LhButtonStyle.icon(for:) maps to SF Symbols: search → magnifyingglass, refresh → arrow.clockwise, check → checkmark, close → xmark; unregistered names are not drawn). The pattern background consumes the color.decoration token and Canvas-draws 45° diagonal lines, layered under the background color and over the text without affecting contrast.

9:41Icon & pattern

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

Light and dark themes ​

Toggle the site theme in the top-right corner and the button colors inside the simulator phone frame change; on a device, switch with LhTheme(isDark: true).

9:41Dark buttons

HTML mock preview (iOS / SwiftUI appearance), not an on-device render; light/dark values are all taken from the core token snapshot

API ​

Props ​

PropDescriptionTypeDefault
lhOnClickTap callback; not fired when disabled or loading is true() -> Void—
typeButton type, determines the background and text colorsLhButtonType.default
lhSizeButton size, mapped to the size tokensLhButtonSize.medium
disabledWhether disabledBoolfalse
loadingWhether loading (shows an indicator, does not fire lhOnClick)Boolfalse
iconIcon name (resolved through the SF Symbol mapping)String?nil
bgPatternWhether to draw the Chinese-style decorative patternBoolfalse
label / textButton text content (the spec's default slot)Text / string—

LhButtonType ​

ValueBackgroundText color
.defaultcolor.background.defaultcolor.text.primary
.primarycolor.primary.defaultcolor.onPrimary
.successcolor.success.defaultcolor.onPrimary
.warningcolor.warning.defaultcolor.onPrimary
.dangercolor.danger.defaultcolor.onPrimary
.infocolor.info.defaultcolor.onPrimary

LhButtonSize ​

ValueheightpaddingHorizontalfontSizeiconSize
.smallbutton.height.small (32pt)button.paddingHorizontal.small (16pt)button.fontSize.small (13pt)button.iconSize.small (16pt)
.mediumbutton.height.medium (40pt)button.paddingHorizontal.medium (20pt)button.fontSize.medium (14pt)button.iconSize.medium (18pt)
.largebutton.height.large (48pt)button.paddingHorizontal.large (24pt)button.fontSize.large (16pt)button.iconSize.large (20pt)

Disabled-state overrides: background color.disabled.bg, text color.disabled.text, border color.disabled.border.

Token Reference ​

Tokens consumed by the button (aligned entry by entry with tokenRefs in specs/button.json):

TokenPurpose
button.height.{small,medium,large}Three heights
button.paddingHorizontal.{small,medium,large}Three horizontal paddings
button.fontSize.{small,medium,large}Three font sizes
button.iconSize.{small,medium,large}Three icon sizes
button.borderRadius / button.borderWidthCorner radius (follows radius.base) and border width
button.fontWeightFont weight (follows typography.fontWeight.primary, mapped to Font.Weight on the end)
color.primary.default / color.onPrimaryPrimary-type background / text
color.{success,warning,danger,info}.defaultSemantic-type backgrounds
color.background.default / color.text.primary / color.border.baseDefault-type background / text / border
color.disabled.{bg,text,border}Three disabled colors
color.decorationPattern color
shadow.lighterDefault elevation (LhShadow carrier)
spacing.xsGap between icon and text

Golden Case Mapping ​

How the 8 assertions in cases/button.json map to XCTest:

case idAssertionLocal test
click-emits-onclickThe gate passes it through (interactive)LhButtonTests.testEnabledButtonIsInteractive
disabled-blocks-clickThe disabled state is not interactivetestDisabledIsNotInteractive
loading-blocks-clickThe loading state is not interactivetestLoadingIsNotInteractive
disabled-precedes-loadingDisabled wins, with the disabled styletestDisabledPrecedesLoading
default-type-renders-textThe default type uses a neutral background / texttestDefaultTypeUsesNeutralTokens
primary-type-uses-primary-tokensThe primary type consumes the primary tokenstestPrimaryTypeUsesPrimaryTokens
small-size-uses-small-tokensThe small size consumes the small size tokenstestSmallSizeUsesSmallTokens
bgpattern-uses-decoration-tokenThe pattern background consumes the decoration colortestBgPatternUsesDecorationToken

Plus dedicated dark-mode tests: testDarkColorsComeFromDarkTokens / testDisabledInDarkUsesDarkDisabledTokens / testDimensionsAreIdenticalInDarkMode.

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

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