Types
JsxChildren
翻訳してレンダリングできる JSX コンテンツの型定義
概要
JsxChildren は、翻訳対象のテキスト、要素、variables を含む JSX コンテンツを表します。
type JsxChildren = JsxChild | JsxChild[];構成
type JsxChild = string | JsxElement | Variable;| 種類 | 説明 |
|---|---|
string | プレーンテキストのコンテンツ |
JsxElement | 構造化要素 |
Variable | 動的プレースホルダー |
JSX 要素
type JsxElement = {
t?: string; // タグ名
i?: number; // id
d?: GTProp; // GT のプロパティ
c?: JsxChildren; // 子要素
};例
基本的な使い方
import { JsxChildren, Variable } from 'generaltranslation';
// シンプルなテキスト
const text: JsxChildren = "ようこそ!";
// 変数を使ったテキスト
const greeting: JsxChildren = [
"こんにちは、"
{ k: 'userName' } as Variable,
"!"
];構造化された要素
// div 要素
const divElement: JsxChildren = {
t: 'div',
c: ['ここにコンテンツ']
};
// タイトル付きリンク
const linkElement: JsxChildren = {
t: 'a',
d: { ti: 'ホームページへアクセス' },
c: ['こちらをクリック']
};関連型
JsxChild- 個々の子要素の型JsxElement- 要素の構造化定義
このガイドはいかがですか?