Text 文本
文本展示原语:消费全局排版令牌,支持字号级别、字重、色调与对齐。
契约源:
lh-ui-core/specs/text.json· 黄金用例:lh-ui-core/cases/text.json(5 条,已翻译为 XCTest,macOS 宿主即可运行)
字号级别
level 映射到 typography.fontSize.<level> 令牌,默认 base。
特大 extraLarge
大 large
中 medium
基准 base(默认)
小 small
特小 extraSmall
HTML 模拟预览(iOS / SwiftUI 外观),非真机渲染
swift
LhText("标题文字", level: .large)字重
weight 映射到 typography.fontWeight.<weight> 令牌(primary 400 / bold 600)。
常规 primary(默认)
加粗 bold
HTML 模拟预览(iOS / SwiftUI 外观),非真机渲染
色调
tone 映射到 color.text.<tone> 令牌;selected 取 color.selected。
主要 primary(默认)
常规 regular
次要 secondary
占位 placeholder
禁用 disabled
选中 selected
HTML 模拟预览(iOS / SwiftUI 外观),非真机渲染
对齐与行高
lhAlign 在行盒宽度内对齐;行高始终取 typography.lineHeight.primary(字号 × 1.8)。
居中 center
右对齐 end
HTML 模拟预览(iOS / SwiftUI 外观),非真机渲染
swift
LhText("居中", lhAlign: .center)API
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
content | 文本内容(构造器第一个参数,spec 的 default 插槽) | String | "" |
level | 字号级别 | LhTextLevel | .base |
weight | 字重 | LhTextWeight | .primary |
tone | 文字色调 | LhTextTone | .primary |
lhAlign | 水平对齐方式 | LhTextAlign | .start |
LhTextLevel
| 值 | fontSize 令牌 |
|---|---|
.extraLarge | typography.fontSize.extraLarge(20pt) |
.large | typography.fontSize.large(18pt) |
.medium | typography.fontSize.medium(16pt) |
.base | typography.fontSize.base(14pt,默认) |
.small | typography.fontSize.small(13pt) |
.extraSmall | typography.fontSize.extraSmall(12pt) |
LhTextTone
| 值 | 文字色令牌 |
|---|---|
.primary | color.text.primary |
.regular | color.text.regular |
.secondary | color.text.secondary |
.placeholder | color.text.placeholder |
.disabled | color.text.disabled |
.selected | color.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 排版令牌 | LhTextTests.testDefaultLevelUsesBaseTokens |
large-level-uses-large-token | 大级别消费 large 字号令牌 | LhTextTests.testLargeLevelUsesLargeToken |
bold-weight-uses-bold-token | 粗体消费 bold 字重令牌 | LhTextTests.testBoldWeightUsesBoldToken |
secondary-tone-uses-text-secondary | 次要色调取次要文字色令牌 | LhTextTests.testSecondaryToneUsesTextSecondary |
render-emits-single-text-command | 渲染发出一条 TEXT 指令 | LhTextTests.testAllLevelsUseTheirTokens(令牌映射覆盖率) |
bash
swift test --filter LhTextTests
