Skip to content

Text 文本 ​

文本展示原语:消费全局排版令牌,支持字号级别、字重、色调与对齐。

契约源:lh-ui-core/specs/text.json · 黄金用例:cases/text.json(5 条:令牌映射翻译为 JVM 单测,渲染与单节点断言在 androidTest)

字号级别 ​

level 映射到 typography.fontSize.<level> 令牌,默认 base。

9:41Text 字号

特大 extraLarge

大 large

中 medium

基准 base(默认)

小 small

特小 extraSmall

HTML 模拟预览(Android / Compose 外观),非真机渲染

kotlin
LhText(content = "标题文字", level = LhTextLevel.large)

字重 ​

weight 映射到 typography.fontWeight.<weight> 令牌(primary 400 / bold 600)。

9:41Text 字重

常规 primary(默认)

加粗 bold

HTML 模拟预览(Android / Compose 外观),非真机渲染

色调 ​

tone 映射到 color.text.<tone> 令牌;selected 取 color.selected。

9:41Text 色调

主要 primary(默认)

常规 regular

次要 secondary

占位 placeholder

禁用 disabled

选中 selected

HTML 模拟预览(Android / Compose 外观),非真机渲染

对齐与行高 ​

lhAlign 在行盒宽度内对齐;行高始终取 typography.lineHeight.primary(字号 × 1.8)。

9:41Text 对齐

居中 center

右对齐 end

HTML 模拟预览(Android / Compose 外观),非真机渲染

kotlin
LhText(content = "居中", lhAlign = LhTextAlign.center)

API ​

Props ​

属性说明类型默认值
content文本内容(spec 的 default 插槽的字符串形态)String""
modifier修饰符ModifierModifier
level字号级别LhTextLevelBase
weight字重LhTextWeightPrimary
tone文字色调LhTextTonePrimary
lhAlign水平对齐方式LhTextAlignStart

LhTextLevel ​

值fontSize 令牌
ExtraLargetypography.fontSize.extraLarge(20sp)
Largetypography.fontSize.large(18sp)
Mediumtypography.fontSize.medium(16sp)
Basetypography.fontSize.base(14sp,默认)
Smalltypography.fontSize.small(13sp)
ExtraSmalltypography.fontSize.extraSmall(12sp)

LhTextTone ​

值文字色令牌
Primarycolor.text.primary
Regularcolor.text.regular
Secondarycolor.text.secondary
Placeholdercolor.text.placeholder
Disabledcolor.text.disabled
Selectedcolor.selected

令牌对照 ​

令牌用途
typography.fontSize.<level>六档字号
typography.fontWeight.{primary,bold}两档字重
typography.lineHeight.primary行高(字号 × 1.8)
color.text.<tone> / color.selected文字色调

黄金用例对照 ​

case id断言本地测试
default-level-uses-base-tokens默认级别消费 base 排版令牌LhTextDefaultsTest.default_level_uses_base_tokens / LhTextTest.default_level_renders_content
large-level-uses-large-token大级别消费 large 字号令牌LhTextDefaultsTest.large_level_uses_large_token / LhTextTest.large_level_renders_content
bold-weight-uses-bold-token粗体消费 bold 字重令牌LhTextDefaultsTest.bold_weight_uses_bold_token
secondary-tone-uses-text-secondary次要色调取次要文字色令牌LhTextDefaultsTest.secondary_tone_uses_text_secondary
render-emits-single-text-command渲染发出一条 TEXT 指令LhTextTest.renders_single_text_node(单节点断言)
bash
./gradlew :components:text:test                             # JVM 部分(令牌映射)
./gradlew :components:text:connectedAndroidTest             # 仪器部分(需设备)