Skip to content

Text 文字 ​

文字元件。按級別、字重、色調與對齊渲染單段文字,全部排版值取自 typography 令牌。

契約源:lh-ui-core/specs/text.json · 黃金用例:lh-ui-core/cases/text.json(5 條,已翻譯為 xUnit 測試)

級別 ​

六檔級別映射到 typography.fontSize.* 令牌;預設級別為 base。

9:41Text 級別
青花瓷 extraLarge
青花瓷 large
青花瓷 medium
青花瓷 base
青花瓷 small
青花瓷 extraSmall

HTML 模擬預覽(Windows / WinUI 3 外觀),非真機渲染

csharp
var text = new LhText
{
    Text = "青花瓷",
    Level = LhTextLevel.Large,
};

字重與色調 ​

Weight 映射到 typography.fontWeight.* 令牌;Tone 映射到 color.text.*(selected 取 color.selected)。

9:41字重與色調
加粗 bold
次要說明 secondary
佔位文字 placeholder
選取態 selected

HTML 模擬預覽(Windows / WinUI 3 外觀),非真機渲染

對齊 ​

Align 決定文字在行盒寬度內的水平定位(非設計令牌,映射到 WinUI 的 TextAlignment)。

9:41對齊
左對齊 start
置中 center
右對齊 end

HTML 模擬預覽(Windows / WinUI 3 外觀),非真機渲染

明暗主題 ​

切換站台右上角主題,模擬器手機框內的文字色即變;真機透過 LhTheme.Apply(true) 切換。

9:41暗色文字
常規文字 regular
次要說明 secondary

HTML 模擬預覽(Windows / WinUI 3 外觀),非真機渲染;明/暗值全部取自 core 令牌快照

API ​

屬性 ​

屬性說明型別預設值
Text文字內容(spec 的 default 插槽)string""
Level字級級別,映射到 typography.fontSize.*LhTextLevelBase
Weight字重,映射到 typography.fontWeight.*LhTextWeightPrimary
Tone文字色調,映射到 color.text.* / color.selectedLhTextToneRegular
Align水平對齊(映射到 TextAlignment)LhTextAlignStart

LhTextLevel ​

值字級令牌
ExtraLargetypography.fontSize.extraLarge(20epx)
Largetypography.fontSize.large(18epx)
Mediumtypography.fontSize.medium(16epx)
Basetypography.fontSize.base(14epx)
Smalltypography.fontSize.small(13epx)
ExtraSmalltypography.fontSize.extraSmall(12epx)

LhTextWeight ​

值字重令牌
Primarytypography.fontWeight.primary(400,端側映射 Normal)
Boldtypography.fontWeight.bold(600,端側映射 SemiBold)

LhTextTone ​

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

LhTextAlign ​

值WinUI 映射
StartTextAlignment.Left
CenterTextAlignment.Center
EndTextAlignment.Right

令牌對照 ​

令牌用途
typography.fontSize.{extraLarge…extraSmall}六檔字級
typography.fontWeight.{primary,bold}兩檔字重
typography.lineHeight.primary行高(行盒高度 = 字級 × 行高)
typography.fontFamily國風襯線字型棧
color.text.{primary,regular,secondary,placeholder,disabled}中性色調
color.selected選取態色調

黃金用例對照 ​

cases/text.json 的 5 條斷言與 xUnit 測試的對應關係(tests/LhTextTests.cs):

case id斷言本地測試
default-level-uses-base-tokens預設級別消費 base 排版令牌Default_Level_Uses_Base_Tokens
large-level-uses-large-token大級別消費 large 字級令牌Large_Level_Uses_Large_Token
bold-weight-uses-bold-token粗體消費 bold 字重令牌Bold_Weight_Uses_Bold_Token
secondary-tone-uses-text-secondary次要色調取次要文字色令牌Secondary_Tone_Uses_Text_Secondary
render-emits-single-text-command有且僅有一條 TEXT 指令Render_Emits_Single_Text_Command

另有暗色專項:Dark_Colors_Come_From_Dark_Tokens / Dimensions_Are_Identical_In_Dark_Mode。 執行:cd lh-ui-windows && dotnet test。