Skip to content

Button ​

A basic action button. It triggers an immediate action and supports type, size, loading, disabled, icon, and a Chinese-style pattern background.

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

Types ​

Six types determine the background and text color.

9:41Button types

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

kotlin
LhButton(type = LhButtonType.Primary, lhOnClick = {}) { Text("主要按钮") }

Sizes ​

Three sizes map to the button.height / paddingHorizontal / fontSize / iconSize tokens.

9:41Button sizes

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

States ​

Neither disabled nor loading triggers lhOnClick; when both are set, disabled wins (golden case disabled-precedes-loading).

9:41Button states

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

Icons and pattern background ​

Icon names resolve against the local icon system (LhButtonIcons, currently supporting search / refresh / check / close; unregistered names draw nothing). The pattern background consumes the color.decoration token — it is layered above the background color but below the text, so it does not affect contrast.

9:41Icons & patterns

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

Light and dark theme ​

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

9:41Dark buttons

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

API ​

Props ​

PropDescriptionTypeDefault
lhOnClickTap callback; not triggered when disabled or loading is true() -> Unit—
modifierModifierModifierModifier
typeButton type; determines the background and text colorLhButtonTypeDefault
lhSizeButton size; maps to the size tokensLhButtonSizeMedium
disabledWhether the button is disabledBooleanfalse
loadingWhether the button is loading (shows an indicator and does not trigger lhOnClick)Booleanfalse
iconIcon name (resolved by the local icon system)String?null
bgPatternWhether to draw the Chinese-style background patternBooleanfalse
contentButton text content (the spec's default slot)@Composable () -> Unit—

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 (32dp)button.paddingHorizontal.small (16dp)button.fontSize.small (13sp)button.iconSize.small (16dp)
Mediumbutton.height.medium (40dp)button.paddingHorizontal.medium (20dp)button.fontSize.medium (14sp)button.iconSize.medium (18dp)
Largebutton.height.large (48dp)button.paddingHorizontal.large (24dp)button.fontSize.large (16sp)button.iconSize.large (20dp)

The disabled state overrides: background color.disabled.bg, text color.disabled.text, border color.disabled.border.

Token reference ​

Tokens consumed by the button (aligned one-to-one with the tokenRefs of specs/button.json):

TokenUsage
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)
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}The three disabled colors
color.decorationPattern color
shadow.lighterDefault-type elevation
motion.duration.fast / motion.easing.easeInOutPress-feedback animation

Golden case reference ​

How the 8 assertions of cases/button.json map to local tests:

case idAssertionLocal test
click-emits-onclickA tap triggers onClick exactly onceLhButtonTest.click_emits_onClick (Compose UI Test)
disabled-blocks-clickThe disabled state does not triggerLhButtonTest.disabled_blocks_click
loading-blocks-clickThe loading state does not triggerLhButtonTest.loading_blocks_click
disabled-precedes-loadingDisabled winsLhButtonTest.disabled_precedes_loading_blocks_click + LhButtonDefaultsTest.disabled_precedes_loading
default-type-renders-textThe default type renders textLhButtonDefaultsTest.default_type_uses_neutral_tokens
primary-type-uses-primary-tokensThe primary type consumes primary tokensLhButtonDefaultsTest.primary_type_uses_primary_tokens
small-size-uses-small-tokensSmall consumes the small size tokensLhButtonDefaultsTest.small_size_uses_small_tokens
bgpattern-uses-decoration-tokenThe pattern background consumes the decoration colorLhButtonDefaultsTest.bgPattern_uses_decoration_token
icon-renders-icon-commandA registered icon name renders a vector; an unregistered name draws nothingLhButtonDefaultsTest.icon_renders_registered_vector + unknown_icon_name_resolves_to_null
bash
./gradlew :components:button:test                        # JVM part
./gradlew :components:button:connectedAndroidTest        # Interaction part (requires a device)

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