Skip to content

快速開始 ​

最小範例 ​

typescript
import { LhButton, LhButtonType, LhTheme } from '@lhgb/lh-ui-harmony'

@Entry
@Component
struct Demo {
  aboutToAppear(): void {
    LhTheme.apply(false) // 注入明色板;切暗色傳 true
  }

  build() {
    Column() {
      LhButton({
        onClick: () => { /* 處理點選 */ },
        type: LhButtonType.Primary,
        text: '主要按鈕',
      })
    }
  }
}

LhTheme.apply(isDark) 把色板序列化進 AppStorage,所有 Lh 元件自動消費;不呼叫時回退明色板。

類型與尺寸 ​

typescript
// 六種類型
LhButton({ onClick: () => {}, text: '預設' })                        // Default
LhButton({ onClick: () => {}, type: LhButtonType.Primary, text: '主要' })
LhButton({ onClick: () => {}, type: LhButtonType.Success, text: '成功' })
LhButton({ onClick: () => {}, type: LhButtonType.Warning, text: '警告' })
LhButton({ onClick: () => {}, type: LhButtonType.Danger, text: '危險' })
LhButton({ onClick: () => {}, type: LhButtonType.Info, text: '資訊' })

// 三種尺寸
LhButton({ onClick: () => {}, size: LhButtonSize.Small, text: '小型' })
LhButton({ onClick: () => {}, size: LhButtonSize.Medium, text: '中型' })
LhButton({ onClick: () => {}, size: LhButtonSize.Large, text: '大型' })

狀態 ​

typescript
// 停用:不回應點選(.enabled 攔截),呈現停用樣式
LhButton({ onClick: () => {}, disabled: true, text: '停用' })

// 載入中:顯示指示器,不觸發 onClick
LhButton({ onClick: () => {}, loading: true, text: '載入中' })

// 兩者共存:按停用優先處理(黃金用例 disabled-precedes-loading)
LhButton({ onClick: () => {}, disabled: true, loading: true, text: '停用優先' })

圖示與花紋底 ​

typescript
// 圖示名按本機圖示體系解析(SymbolGlyph 映射見 LhButtonTokens.iconFor,未登記名不繪製)
LhButton({ onClick: () => {}, type: LhButtonType.Primary, icon: 'search', text: '搜尋' })

// 國風花紋底紋(消費 color.decoration 令牌)
LhButton({ onClick: () => {}, type: LhButtonType.Primary, bgPattern: true, text: '花紋底' })

明暗主題 ​

typescript
LhTheme.apply(true)  // 全域切暗色;所有元件下次外觀解析時自動跟隨

元件範例預覽 ​

原生 UI 無法在瀏覽器即時渲染,本站用內嵌靜態 HTML 手機框模擬器展示外觀:

9:41lh-ui-harmony

鴻蒙(ArkUI)外觀的 HTML 模擬預覽,非真機渲染;樣式值全部取自 core 令牌快照,與真機同源同值。真機外觀以 entry 演示應用與裝置截圖為準。

模擬器的暗色與站台聯動:右上角切換主題,手機框內顏色即變(暗色令牌由 core 預先計算)。