Skip to content

Text テキスト ​

テキスト表示のプリミティブです。グローバルなタイポグラフィトークンを消費し、フォントサイズレベル、フォントの太さ、色調、整列をサポートします。

契約元: lh-ui-core/specs/text.json · ゴールデンケース: lh-ui-core/cases/text.json(5 件、hypium テストに翻訳済み)

フォントサイズレベル ​

level は typography.fontSize.<level> トークンに対応し、デフォルトは base です。

9:41Text フォントサイズ

特大 extraLarge

大 large

中 medium

ベース base(デフォルト)

小 small

特小 extraSmall

HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません

typescript
LhText({ content: 'タイトルのテキスト', level: LhTextLevel.Large })

フォントの太さ ​

weight は typography.fontWeight.<weight> トークンに対応します(primary 400 / bold 600)。

9:41Text フォントの太さ

レギュラー primary(デフォルト)

太字 bold

HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません

色調 ​

tone は color.text.<tone> トークンに対応します。selected は color.selected を取ります。

9:41Text 色調

プライマリ primary(デフォルト)

レギュラー regular

セカンダリ secondary

プレースホルダー placeholder

無効 disabled

選択中 selected

HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません

整列と行の高さ ​

align は行ボックスの幅のなかでのテキストの水平位置を決定します(デザイントークンではなく、フレームワークの列挙型へのマッピングです)。行の高さは常に typography.lineHeight.primary を取り、layout の高さ = フォントサイズ × 行の高さとなります。

9:41Text 整列

左寄せ start(デフォルト)

中央寄せ center

右寄せ end

HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません

typescript
LhText({ content: '右寄せ', align: LhTextAlign.End })

ライト / ダークテーマ ​

サイト右上のテーマを切り替えると、シミュレーターのスマートフォンフレーム内のテキストの色が即座に変わります。実機では LhTheme.apply(true) で切り替えます。

9:41ダークテキスト

大見出し

本文のメインカラー

二次的な説明

HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません。明 / 暗の値はすべて core トークンのスナップショットから取得

API ​

Props ​

プロパティ説明型デフォルト値
contentテキストの内容(spec の default スロット)string''
levelフォントサイズレベル。typography.fontSize.<level> に対応LhTextLevelBase
weightフォントの太さ。typography.fontWeight.<weight> に対応LhTextWeightPrimary
toneテキストの色調。color.text.<tone> または color.selected に対応LhTextTonePrimary
align水平方向の整列(行ボックスの幅のなかで有効)LhTextAlignStart

LhTextLevel ​

値fontSize
ExtraLargetypography.fontSize.extraLarge(20)
Largetypography.fontSize.large(18)
Mediumtypography.fontSize.medium(16)
Basetypography.fontSize.base(14)
Smalltypography.fontSize.small(13)
ExtraSmalltypography.fontSize.extraSmall(12)

LhTextWeight ​

値fontWeight
Primarytypography.fontWeight.primary(400)
Boldtypography.fontWeight.bold(600)

LhTextTone ​

値テキストの色
Primarycolor.text.primary
Regularcolor.text.regular
Secondarycolor.text.secondary
Placeholdercolor.text.placeholder
Disabledcolor.text.disabled
Selectedcolor.selected

LhTextAlign ​

値端側のマッピング
StartTextAlign.Start
CenterTextAlign.Center
EndTextAlign.End

トークン对照 ​

テキストが消費するトークン(specs/text.json の tokenRefs と 1 対 1 で対応。すべてグローバルトークンであり、 text にはコンポーネントレベルのトークンはありません):

トークン用途
typography.fontSize.{extraLarge,large,medium,base,small,extraSmall}6 段階のフォントサイズ
typography.fontWeight.{primary,bold}2 段階のフォントの太さ
typography.lineHeight.primary行の高さ(layout の高さ = フォントサイズ × 行の高さ)
color.text.{primary,regular,secondary,placeholder,disabled}5 段階のテキストの色調
color.selected選択中のテキスト色

ゴールデンケース对照 ​

cases/text.json の 5 件のアサーションと hypium テストの対応関係(entry/src/test/Text.test.ets):

case idアサーションローカルのテスト
default-level-uses-base-tokensデフォルトレベルが base のタイポグラフィトークンを消費default_level_uses_base_tokens
large-level-uses-large-tokenlarge のフォントサイズトークンが効き、base が誤用されないlarge_level_uses_large_token
bold-weight-uses-bold-tokenbold の太さトークンが効き、primary が誤用されないbold_weight_uses_bold_token
secondary-tone-uses-text-secondarysecondary のテキスト色トークンが効くsecondary_tone_uses_text_secondary
render-emits-single-text-commandコマンドストリームに TEXT コマンドが 1 つだけresolve_produces_single_complete_text_style

このほかダーク専用として dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode があります。 実行方法: DevEco Studio で entry/src/test を右クリック → Run Tests。

lh-ui ネイティブ血脈 · HarmonyOS 端(ArkTS + ArkUI)