Skip to content

Icon 圖示 ​

圖示元件。按本機圖形體系把圖示名解析為字形渲染,支援尺寸與語義色調。

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

端側落點說明

鴻蒙端當前用 unicode 字形佔位(LhIconTokens.glyphFor),生產環境應替換為 SymbolGlyph / 矢量資產;這與 button 的 Text('◆') 佔位策略一致。已登記圖示名見下方「圖示名」一節。

尺寸 ​

三檔尺寸映射到 icon.size 令牌。

9:41Icon 尺寸
⌕⌕⌕

HTML 模擬預覽(鴻蒙 / ArkUI 外觀),非真機渲染

typescript
LhIcon({ name: 'search', size: LhIconSize.Large })

色調 ​

tone 決定字形顏色,與語義色令牌一一對應;預設色調取 color.text.primary。

9:41Icon 色調
✓ 預設✓ 主色✓ 成功
⚠ 警告✕ 危險ℹ 資訊
✓ 常規✓ 次要

HTML 模擬預覽(鴻蒙 / ArkUI 外觀),非真機渲染

圖示名 ​

glyphFor 當前登記的圖示名與字形:search ⌕、refresh ↻、check ✓、close ✕、 warning ⚠、info ℹ、back ←、more ⋯、star ★、edit ✎、delete ⌫、 plus +、minus -、arrow →。未登記名回退 ◆。

9:41已登記圖示
⌕↻✓✕⚠ℹ←⋯
★✎⌫+-→

HTML 模擬預覽(鴻蒙 / ArkUI 外觀),非真機渲染

API ​

Props ​

屬性說明型別預設值
name圖示名(本機圖形體系解析,未登記名回退 ◆)string''
size圖示尺寸,映射到 icon.size 令牌LhIconSizeMedium
tone語義色調,決定字形顏色LhIconToneDefault
onClick點選回呼() => void空函式

LhIconSize ​

值size
Smallicon.size.small(16vp)
Mediumicon.size.medium(20vp)
Largeicon.size.large(24vp)

LhIconTone ​

值字形色
Defaultcolor.text.primary
Primarycolor.primary.default
Successcolor.success.default
Warningcolor.warning.default
Dangercolor.danger.default
Infocolor.info.default
Regularcolor.text.regular
Secondarycolor.text.secondary

令牌對照 ​

令牌用途
icon.size.{small,medium,large}三檔尺寸
color.text.primary預設色調
color.text.regular / color.text.secondary常規 / 次要色調
color.{primary,success,warning,danger,info}.default語義色調

黃金用例對照 ​

cases/icon.json 的 5 條斷言與 hypium 測試的對應關係(entry/src/test/Icon.test.ets):

case id斷言本地測試
click-emits-onclick點選觸發回呼(端側為 onClick 屬性)glyph_maps_registered_name(端側按宣告式回呼對齊)
default-tone-uses-text-primary預設色調取主文字色default_tone_uses_text_primary
primary-tone-uses-primary-token主色調取主色令牌primary_tone_uses_primary_token
small-size-uses-small-token小號取 small 尺寸令牌small_size_uses_small_token
render-emits-icon-command渲染發射圖示命令端側無對應命令(宣告式渲染,字形映射見 glyph_maps_registered_name / glyph_falls_back_for_unknown_name)

另有暗色專項:dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode。 執行:DevEco Studio 右鍵 entry/src/test → Run Tests。