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.
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
LhButton({ onClick: () => {}, type: LhButtonType.Primary, text: 'Primary' })Sizes
Three sizes map to the button.height / paddingHorizontal / fontSize / iconSize tokens.
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).
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.
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).
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
| Prop | Description | Type | Default |
|---|---|---|---|
onClick | Tap callback; not fired when disabled or loading is true | () => void | Empty function |
type | Button type, determines background and text colors | LhButtonType | Default |
size | Button size, maps to the size tokens | LhButtonSize | Medium |
disabled | Whether disabled | boolean | false |
loading | Whether loading (shows an indicator and does not fire onClick) | boolean | false |
icon | Icon name (resolved by the local icon system) | string? | undefined |
bgPattern | Whether to draw a Chinese-style pattern background | boolean | false |
text | Button label (the spec's default slot) | string | '' |
LhButtonType
| Value | Background | Text color |
|---|---|---|
Default | color.background.default | color.text.primary |
Primary | color.primary.default | color.onPrimary |
Success | color.success.default | color.onPrimary |
Warning | color.warning.default | color.onPrimary |
Danger | color.danger.default | color.onPrimary |
Info | color.info.default | color.onPrimary |
LhButtonSize
| Value | height | paddingHorizontal | fontSize | iconSize |
|---|---|---|---|---|
Small | button.height.small (32vp) | button.paddingHorizontal.small (16vp) | button.fontSize.small (13) | button.iconSize.small (16) |
Medium | button.height.medium (40vp) | button.paddingHorizontal.medium (20vp) | button.fontSize.medium (14) | button.iconSize.medium (18) |
Large | button.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):
| Token | Purpose |
|---|---|
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.borderWidth | Corner radius (follows radius.base) and border width |
button.fontWeight | Font weight (follows typography.fontWeight.primary, mapped to FontWeight on the device side) |
color.primary.default / color.onPrimary | Primary-type background / text |
color.{success,warning,danger,info}.default | Semantic-type backgrounds |
color.background.default / color.text.primary / color.border.base | Default-type background / text / border |
color.disabled.{bg,text,border} | Three disabled-state colors |
color.decoration | Pattern stripe color |
shadow.lighter | Default 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 id | Assertion | Local test |
|---|---|---|
click-emits-onclick | Gate passes (interactive) | enabled_button_is_interactive |
disabled-blocks-click | Disabled state is not interactive | disabled_is_not_interactive |
loading-blocks-click | Loading state is not interactive | loading_is_not_interactive |
disabled-precedes-loading | Disabled wins + disabled style | disabled_precedes_loading |
default-type-renders-text | Default type uses a neutral background/text | default_type_uses_neutral_tokens |
primary-type-uses-primary-tokens | Primary type consumes primary tokens | primary_type_uses_primary_tokens |
small-size-uses-small-tokens | Small consumes the small size tokens | small_size_uses_small_tokens |
bgpattern-uses-decoration-token | Pattern background consumes the decoration color | bgpattern_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.

