Icon 圖示
圖示元件。按本機圖形體系把圖示名解析為字形渲染,支援尺寸與語義色調。
契約源:
lh-ui-core/specs/icon.json· 黃金用例:lh-ui-core/cases/icon.json(5 條,已翻譯為 hypium 測試)
端側落點說明
鴻蒙端當前用 unicode 字形佔位(LhIconTokens.glyphFor),生產環境應替換為 SymbolGlyph / 矢量資產;這與 button 的 Text('◆') 佔位策略一致。已登記圖示名見下方「圖示名」一節。
尺寸
三檔尺寸映射到 icon.size 令牌。
HTML 模擬預覽(鴻蒙 / ArkUI 外觀),非真機渲染
typescript
LhIcon({ name: 'search', size: LhIconSize.Large })色調
tone 決定字形顏色,與語義色令牌一一對應;預設色調取 color.text.primary。
HTML 模擬預覽(鴻蒙 / ArkUI 外觀),非真機渲染
圖示名
glyphFor 當前登記的圖示名與字形:search ⌕、refresh ↻、check ✓、close ✕、 warning ⚠、info ℹ、back ←、more ⋯、star ★、edit ✎、delete ⌫、 plus +、minus -、arrow →。未登記名回退 ◆。
HTML 模擬預覽(鴻蒙 / ArkUI 外觀),非真機渲染
API
Props
| 屬性 | 說明 | 型別 | 預設值 |
|---|---|---|---|
name | 圖示名(本機圖形體系解析,未登記名回退 ◆) | string | '' |
size | 圖示尺寸,映射到 icon.size 令牌 | LhIconSize | Medium |
tone | 語義色調,決定字形顏色 | LhIconTone | Default |
onClick | 點選回呼 | () => void | 空函式 |
LhIconSize
| 值 | size |
|---|---|
Small | icon.size.small(16vp) |
Medium | icon.size.medium(20vp) |
Large | icon.size.large(24vp) |
LhIconTone
| 值 | 字形色 |
|---|---|
Default | color.text.primary |
Primary | color.primary.default |
Success | color.success.default |
Warning | color.warning.default |
Danger | color.danger.default |
Info | color.info.default |
Regular | color.text.regular |
Secondary | color.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。

