Skip to content

Icon 圖示 ​

矢量圖示。透過邏輯名對應到平台的系統符號(iOS 端為 SF Symbol),尺寸與色調全部走令牌。

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

色調 ​

tone 決定圖示顏色。default 跟隨主要文字色,regular / secondary 取對應層級文字色,其餘取語義色。

9:41Icon 色調

HTML 模擬預覽(iOS / SwiftUI 外觀),非真機渲染;真機繪製的是 SF Symbol 矢量

swift
LhIcon(name: "star", tone: .primary)

尺寸 ​

三檔尺寸對應到 icon.size 令牌。

9:41Icon 尺寸

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

圖示名對應 ​

name 是與 web 血脈對齊的邏輯名,端側經 LhIconMap.symbol(for:) 對應到 SF Symbol:

邏輯名SF Symbol
star / search / check / closestar / magnifyingglass / checkmark / xmark
arrow-up / arrow-down / arrow-left / arrow-rightarrow.up / arrow.down / arrow.left / arrow.right
refresh / plus / minus / eye / linkarrow.clockwise / plus / minus / eye / link

未登入的名稱不繪製(回傳 nil),不會崩潰。

swift
LhIcon(name: "search", lhSize: .large, tone: .secondary) {
  // lhOnClick
}

API ​

Props ​

屬性說明類型預設值
name圖示邏輯名(經 LhIconMap 對應 SF Symbol)String—
lhSize圖示尺寸,對應到尺寸令牌LhIconSize.medium
tone圖示色調,對應到文字/語義色令牌LhIconTone.default
lhOnClick點選回呼;未傳則不回應點選(() -> Void)?nil

LhIconSize ​

值尺寸
.smallicon.size.small(16pt)
.mediumicon.size.medium(20pt)
.largeicon.size.large(24pt)

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,regular,secondary}文字色調
color.{primary,success,warning,danger,info}.default語義色調

黃金用例對照 ​

case id斷言本地測試
click-emits-onclick點選觸發 lhOnClick 一次View 層 onTapGesture(手勢斷言需模擬器,見 #Preview)
default-tone-uses-text-primary預設色調取主要文字色testDefaultToneUsesTextPrimary
primary-tone-uses-primary-token主色調取主色令牌testPrimaryToneUsesPrimaryToken
small-size-uses-small-token小號取 small 尺寸令牌testSmallSizeUsesSmallToken
render-emits-icon-command僅繪製一條圖示指令testRegisteredIconResolvesToSymbol / testUnknownIconReturnsNilSymbol

另有暗色專項:testDarkColorsComeFromDarkTokens / testDimensionsAreIdenticalInDarkMode。

bash
swift test --filter LhIconTests    # macOS 宿主即可執行,無需模擬器