Text
Text display primitive: consumes global typography tokens and supports font-size levels, font weights, color tones, and alignment.
Spec source:
lh-ui-core/specs/text.json· Golden cases:lh-ui-core/cases/text.json(5 cases, translated into hypium tests)
Font-size levels
level maps to the typography.fontSize.<level> tokens; the default is base.
Extra large extraLarge
Large large
Medium medium
Base base (default)
Small small
Extra small extraSmall
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
LhText({ content: 'Title text', level: LhTextLevel.Large })Font weight
weight maps to the typography.fontWeight.<weight> tokens (primary 400 / bold 600).
Regular primary (default)
Bold bold
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
Color tones
tone maps to the color.text.<tone> tokens; selected uses color.selected.
Primary primary (default)
Regular regular
Secondary secondary
Placeholder placeholder
Disabled disabled
Selected selected
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
Alignment and line height
align decides the horizontal placement of the text within the line box (not a design token; it maps to a framework enum). The line height is always typography.lineHeight.primary, and the layout height = font size × line height.
Start start (default)
Center center
End end
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
LhText({ content: 'End aligned', align: LhTextAlign.End })Light and dark themes
Toggle the site theme in the top-right corner and the text colors inside the simulator phone frame change; on a real device, switch with LhTheme.apply(true).
Large title
Body in primary color
Secondary description
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 |
|---|---|---|---|
content | Text content (the spec's default slot) | string | '' |
level | Font-size level, maps to typography.fontSize.<level> | LhTextLevel | Base |
weight | Font weight, maps to typography.fontWeight.<weight> | LhTextWeight | Primary |
tone | Text color tone, maps to color.text.<tone> or color.selected | LhTextTone | Primary |
align | Horizontal alignment (effective within the line box width) | LhTextAlign | Start |
LhTextLevel
| Value | fontSize |
|---|---|
ExtraLarge | typography.fontSize.extraLarge (20) |
Large | typography.fontSize.large (18) |
Medium | typography.fontSize.medium (16) |
Base | typography.fontSize.base (14) |
Small | typography.fontSize.small (13) |
ExtraSmall | typography.fontSize.extraSmall (12) |
LhTextWeight
| Value | fontWeight |
|---|---|
Primary | typography.fontWeight.primary (400) |
Bold | typography.fontWeight.bold (600) |
LhTextTone
| Value | Text color |
|---|---|
Primary | color.text.primary |
Regular | color.text.regular |
Secondary | color.text.secondary |
Placeholder | color.text.placeholder |
Disabled | color.text.disabled |
Selected | color.selected |
LhTextAlign
| Value | Device-side mapping |
|---|---|
Start | TextAlign.Start |
Center | TextAlign.Center |
End | TextAlign.End |
Token reference
Tokens consumed by text (aligned one-to-one with specs/text.json's tokenRefs — all of them are global tokens; text has no component-level tokens):
| Token | Purpose |
|---|---|
typography.fontSize.{extraLarge,large,medium,base,small,extraSmall} | Six font sizes |
typography.fontWeight.{primary,bold} | Two font weights |
typography.lineHeight.primary | Line height (layout height = font size × line height) |
color.text.{primary,regular,secondary,placeholder,disabled} | Five text color tones |
color.selected | Selected-state text color |
Golden case reference
How the 5 assertions in cases/text.json map onto hypium tests (entry/src/test/Text.test.ets):
| case id | Assertion | Local test |
|---|---|---|
default-level-uses-base-tokens | Default level consumes the base typography tokens | default_level_uses_base_tokens |
large-level-uses-large-token | The large font-size token applies and base is not misused | large_level_uses_large_token |
bold-weight-uses-bold-token | The bold font-weight token applies and primary is not misused | bold_weight_uses_bold_token |
secondary-tone-uses-text-secondary | The secondary text-color token applies | secondary_tone_uses_text_secondary |
render-emits-single-text-command | The command stream contains exactly one TEXT command | resolve_produces_single_complete_text_style |
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.

