Skip to content

Text 文字 ​

文字展示原語:消費全局排版令牌,支援字號級別、字重、色調與對齊。

契約源:lh-ui-core/specs/text.json · 黃金用例:lh-ui-core/cases/text.json(5 條,已翻譯為 XCTest,macOS 宿主即可運行)

字號級別 ​

level 映射到 typography.fontSize.<level> 令牌,預設 base。

9:41Text

extraLarge

large

medium

base

small

extraSmall

HTML 模擬預覽(iOS / SwiftUI 外觀),非真機渲染

swift
LhText("Title text", level: .large)

字重 ​

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

9:41Text

primary

bold

HTML 模擬預覽(iOS / SwiftUI 外觀),非真機渲染

色調 ​

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

9:41Text

primary

regular

secondary

placeholder

disabled

selected

HTML 模擬預覽(iOS / SwiftUI 外觀),非真機渲染

對齊與行高 ​

lhAlign 在行盒寬度內對齊;行高始終取 typography.lineHeight.primary(字號 × 1.8)。

9:41Text

center

end

HTML 模擬預覽(iOS / SwiftUI 外觀),非真機渲染

swift
LhText("Centered", lhAlign: .center)

API ​

屬性說明類型預設值
content文字內容(建構器第一個參數,spec 的 default 插槽)String""
level字號級別LhTextLevel.base
weight字重LhTextWeight.primary
tone色調LhTextTone.primary
lhAlign對齊與行高LhTextAlign.start

LhTextLevel ​

屬性fontSize token
.extraLargetypography.fontSize.extraLarge (20pt)
.largetypography.fontSize.large (18pt)
.mediumtypography.fontSize.medium (16pt)
.basetypography.fontSize.base (14pt, default)
.smalltypography.fontSize.small (13pt)
.extraSmalltypography.fontSize.extraSmall (12pt)

LhTextTone ​

屬性text color token
.primarycolor.text.primary
.regularcolor.text.regular
.secondarycolor.text.secondary
.placeholdercolor.text.placeholder
.disabledcolor.text.disabled
.selectedcolor.selected

令牌對照 ​

TokenUsage
typography.fontSize.<level>six size levels
typography.fontWeight.{primary,bold}two weights
typography.lineHeight.primaryline height (font size × 1.8)
color.text.<tone> / color.selectedtext tones

黃金用例對照 ​

case id斷言本地測試
default-level-uses-base-tokensdefault level consumes the base typography tokensLhTextTests.testDefaultLevelUsesBaseTokens
large-level-uses-large-tokenlarge level consumes the large size tokenLhTextTests.testLargeLevelUsesLargeToken
bold-weight-uses-bold-tokenbold consumes the bold weight tokenLhTextTests.testBoldWeightUsesBoldToken
secondary-tone-uses-text-secondarysecondary tone takes the secondary text color tokenLhTextTests.testSecondaryToneUsesTextSecondary
render-emits-single-text-commandrender emits a single TEXT commandLhTextTests.testAllLevelsUseTheirTokens
bash
swift test --filter LhTextTests