Skip to content

Button ​

Basic action button. Triggers immediate actions and supports types, sizes, loading, disabled state, icons, and a Chinese-style pattern background.

Spec source: lh-ui-core/specs/button.json · Golden cases: lh-ui-core/cases/button.json (8 cases, translated into hypium tests)

Types ​

Six types determine the background and text colors.

9:41Button types

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

typescript
LhButton({ onClick: () => {}, type: LhButtonType.Primary, text: 'Primary' })

Sizes ​

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

9:41Button sizes

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

States ​

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

9:41Button states

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

Icon and pattern background ​

Icon names resolve against the local icon system (LhButtonTokens.iconFor; currently search / refresh / check / close are registered, and unregistered names draw nothing). The pattern background consumes the color.decoration token and Canvas-draws 45° diagonal stripes.

9:41Icon and pattern

HTML mockup preview (HarmonyOS / ArkUI 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 real device, switch with LhTheme.apply(true).

9:41Dark buttons

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render; light/dark values are all taken from a snapshot of the core tokens

API ​

Props ​

PropDescriptionTypeDefault
onClickTap callback; not fired when disabled or loading is true() => voidEmpty function
typeButton type, determines background and text colorsLhButtonTypeDefault
sizeButton size, maps to the size tokensLhButtonSizeMedium
disabledWhether disabledbooleanfalse
loadingWhether loading (shows an indicator and does not fire onClick)booleanfalse
iconIcon name (resolved by the local icon system)string?undefined
bgPatternWhether to draw a Chinese-style pattern backgroundbooleanfalse
textButton label (the spec's default slot)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 (32vp)button.paddingHorizontal.small (16vp)button.fontSize.small (13)button.iconSize.small (16)
Mediumbutton.height.medium (40vp)button.paddingHorizontal.medium (20vp)button.fontSize.medium (14)button.iconSize.medium (18)
Largebutton.height.large (48vp)button.paddingHorizontal.large (24vp)button.fontSize.large (16)button.iconSize.large (20)

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 specs/button.json's tokenRefs):

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 FontWeight on the device side)
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-state colors
color.decorationPattern stripe color
shadow.lighterDefault elevation (LhTokens.Shadow.lighter)

Golden case reference ​

How the 8 assertions in cases/button.json map onto hypium tests (entry/src/test/Button.test.ets):

case idAssertionLocal test
click-emits-onclickGate passes (interactive)enabled_button_is_interactive
disabled-blocks-clickDisabled state is not interactivedisabled_is_not_interactive
loading-blocks-clickLoading state is not interactiveloading_is_not_interactive
disabled-precedes-loadingDisabled wins + disabled styledisabled_precedes_loading
default-type-renders-textDefault type uses a neutral background/textdefault_type_uses_neutral_tokens
primary-type-uses-primary-tokensPrimary type consumes primary tokensprimary_type_uses_primary_tokens
small-size-uses-small-tokensSmall consumes the small size tokenssmall_size_uses_small_tokens
bgpattern-uses-decoration-tokenPattern background consumes the decoration colorbgpattern_uses_decoration_token

Plus dark-mode specifics: dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode. To run: in DevEco Studio, right-click entry/src/test → Run Tests.

lh-ui native bloodline · HarmonyOS (ArkTS + ArkUI)