Skip to content

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.

9:41Text sizes

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

typescript
LhText({ content: 'Title text', level: LhTextLevel.Large })

Font weight ​

weight maps to the typography.fontWeight.<weight> tokens (primary 400 / bold 600).

9:41Text weights

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.

9:41Text tones

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.

9:41Text alignment

Start start (default)

Center center

End end

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

typescript
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).

9:41Dark text

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 ​

PropDescriptionTypeDefault
contentText content (the spec's default slot)string''
levelFont-size level, maps to typography.fontSize.<level>LhTextLevelBase
weightFont weight, maps to typography.fontWeight.<weight>LhTextWeightPrimary
toneText color tone, maps to color.text.<tone> or color.selectedLhTextTonePrimary
alignHorizontal alignment (effective within the line box width)LhTextAlignStart

LhTextLevel ​

ValuefontSize
ExtraLargetypography.fontSize.extraLarge (20)
Largetypography.fontSize.large (18)
Mediumtypography.fontSize.medium (16)
Basetypography.fontSize.base (14)
Smalltypography.fontSize.small (13)
ExtraSmalltypography.fontSize.extraSmall (12)

LhTextWeight ​

ValuefontWeight
Primarytypography.fontWeight.primary (400)
Boldtypography.fontWeight.bold (600)

LhTextTone ​

ValueText color
Primarycolor.text.primary
Regularcolor.text.regular
Secondarycolor.text.secondary
Placeholdercolor.text.placeholder
Disabledcolor.text.disabled
Selectedcolor.selected

LhTextAlign ​

ValueDevice-side mapping
StartTextAlign.Start
CenterTextAlign.Center
EndTextAlign.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):

TokenPurpose
typography.fontSize.{extraLarge,large,medium,base,small,extraSmall}Six font sizes
typography.fontWeight.{primary,bold}Two font weights
typography.lineHeight.primaryLine height (layout height = font size × line height)
color.text.{primary,regular,secondary,placeholder,disabled}Five text color tones
color.selectedSelected-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 idAssertionLocal test
default-level-uses-base-tokensDefault level consumes the base typography tokensdefault_level_uses_base_tokens
large-level-uses-large-tokenThe large font-size token applies and base is not misusedlarge_level_uses_large_token
bold-weight-uses-bold-tokenThe bold font-weight token applies and primary is not misusedbold_weight_uses_bold_token
secondary-tone-uses-text-secondaryThe secondary text-color token appliessecondary_tone_uses_text_secondary
render-emits-single-text-commandThe command stream contains exactly one TEXT commandresolve_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.

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