Text テキスト
テキスト表示のプリミティブです。グローバルなタイポグラフィトークンを消費し、フォントサイズレベル、フォントの太さ、色調、整列をサポートします。
契約元:
lh-ui-core/specs/text.json· ゴールデンケース:lh-ui-core/cases/text.json(5 件、hypium テストに翻訳済み)
フォントサイズレベル
level は typography.fontSize.<level> トークンに対応し、デフォルトは base です。
特大 extraLarge
大 large
中 medium
ベース base(デフォルト)
小 small
特小 extraSmall
HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません
LhText({ content: 'タイトルのテキスト', level: LhTextLevel.Large })フォントの太さ
weight は typography.fontWeight.<weight> トークンに対応します(primary 400 / bold 600)。
レギュラー primary(デフォルト)
太字 bold
HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません
色調
tone は color.text.<tone> トークンに対応します。selected は color.selected を取ります。
プライマリ primary(デフォルト)
レギュラー regular
セカンダリ secondary
プレースホルダー placeholder
無効 disabled
選択中 selected
HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません
整列と行の高さ
align は行ボックスの幅のなかでのテキストの水平位置を決定します(デザイントークンではなく、フレームワークの列挙型へのマッピングです)。行の高さは常に typography.lineHeight.primary を取り、layout の高さ = フォントサイズ × 行の高さとなります。
左寄せ start(デフォルト)
中央寄せ center
右寄せ end
HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません
LhText({ content: '右寄せ', align: LhTextAlign.End })ライト / ダークテーマ
サイト右上のテーマを切り替えると、シミュレーターのスマートフォンフレーム内のテキストの色が即座に変わります。実機では LhTheme.apply(true) で切り替えます。
大見出し
本文のメインカラー
二次的な説明
HTML シミュレーションプレビュー(HarmonyOS / ArkUI の見た目)。実機レンダリングではありません。明 / 暗の値はすべて core トークンのスナップショットから取得
API
Props
| プロパティ | 説明 | 型 | デフォルト値 |
|---|---|---|---|
content | テキストの内容(spec の default スロット) | string | '' |
level | フォントサイズレベル。typography.fontSize.<level> に対応 | LhTextLevel | Base |
weight | フォントの太さ。typography.fontWeight.<weight> に対応 | LhTextWeight | Primary |
tone | テキストの色調。color.text.<tone> または color.selected に対応 | LhTextTone | Primary |
align | 水平方向の整列(行ボックスの幅のなかで有効) | LhTextAlign | Start |
LhTextLevel
| 値 | fontSize |
|---|---|
ExtraLarge | typography.fontSize.extraLarge(20) |
Large | typography.fontSize.large(18) |
Medium | typography.fontSize.medium(16) |
Base | typography.fontSize.base(14) |
Small | typography.fontSize.small(13) |
ExtraSmall | typography.fontSize.extraSmall(12) |
LhTextWeight
| 値 | fontWeight |
|---|---|
Primary | typography.fontWeight.primary(400) |
Bold | typography.fontWeight.bold(600) |
LhTextTone
| 値 | テキストの色 |
|---|---|
Primary | color.text.primary |
Regular | color.text.regular |
Secondary | color.text.secondary |
Placeholder | color.text.placeholder |
Disabled | color.text.disabled |
Selected | color.selected |
LhTextAlign
| 値 | 端側のマッピング |
|---|---|
Start | TextAlign.Start |
Center | TextAlign.Center |
End | TextAlign.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-token | large のフォントサイズトークンが効き、base が誤用されない | large_level_uses_large_token |
bold-weight-uses-bold-token | bold の太さトークンが効き、primary が誤用されない | bold_weight_uses_bold_token |
secondary-tone-uses-text-secondary | secondary のテキスト色トークンが効く | 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。

