基本的なテキストプリミティブ。
<Text>The quick brown fox jumps over the lazy dog.</Text>
このコンポーネントはspan
要素に基づいており、共通のマージンプロパティをサポートしています。
プロパティ | 型 | デフォルト |
---|---|---|
as | "span" | "div" | "label" | "p" | "span" |
asChild | boolean | デフォルト値なし |
size | Responsive<enum> | デフォルト値なし |
weight | Responsive<"light" | "regular" | "medium" | "bold"> | デフォルト値なし |
align | Responsive<"left" | "center" | "right"> | デフォルト値なし |
trim | Responsive<"normal" | "start" | "end" | "both"> | デフォルト値なし |
truncate | boolean | デフォルト値なし |
wrap | Responsive<"wrap" | "nowrap" | "pretty" | "balance"> | デフォルト値なし |
color | enum | デフォルト値なし |
highContrast | boolean | デフォルト値なし |
as
プロパティを使用して、テキストをp
、label
、div
、またはspan
としてレンダリングします。このプロパティは純粋にセマンティックなものであり、視覚的な外観は変更しません。
これは段落要素です。
<Text as="p">This is a <Strong>paragraph</Strong> element.</Text>
<Text as="label">This is a <Strong>label</Strong> element.</Text>
<Text as="div">This is a <Strong>div</Strong> element.</Text>
<Text as="span">This is a <Strong>span</Strong> element.</Text>
size
プロパティを使用してテキストサイズを制御します。このプロパティは、正しい行の高さと修正された文字間隔も提供します。テキストサイズが大きくなるにつれて、相対的な行の高さと文字間隔が小さくなります。
<Flex direction="column" gap="3">
<Text size="1">The quick brown fox jumps over the lazy dog.</Text>
<Text size="2">The quick brown fox jumps over the lazy dog.</Text>
<Text size="3">The quick brown fox jumps over the lazy dog.</Text>
<Text size="4">The quick brown fox jumps over the lazy dog.</Text>
<Text size="5">The quick brown fox jumps over the lazy dog.</Text>
<Text size="6">The quick brown fox jumps over the lazy dog.</Text>
<Text size="7">The quick brown fox jumps over the lazy dog.</Text>
<Text size="8">The quick brown fox jumps over the lazy dog.</Text>
<Text size="9">The quick brown fox jumps over the lazy dog.</Text>
</Flex>
サイズ2~4は、長文コンテンツに適しています。
タイポグラフィの目標は、美しさを最大化し、読みやすく快適にするために、フォントサイズ、行の高さ、行の幅を比例的に関連付けることです。問題は、どの比率が最良の結果をもたらすかということです。黄金比は、美しさと実用性が交差する自然の中でよく観察されます。この「神聖な」比率を使用して、タイポグラフィのこれらの属性を強化できる可能性があります。
タイポグラフィの目標は、美しさを最大化し、読みやすく快適にするために、フォントサイズ、行の高さ、行の幅を比例的に関連付けることです。問題は、どの比率が最良の結果をもたらすかということです。黄金比は、美しさと実用性が交差する自然の中でよく観察されます。この「神聖な」比率を使用して、タイポグラフィのこれらの属性を強化できる可能性があります。
タイポグラフィの目標は、美しさを最大化し、読みやすく快適にするために、フォントサイズ、行の高さ、行の幅を比例的に関連付けることです。問題は、どの比率が最良の結果をもたらすかということです。黄金比は、美しさと実用性が交差する自然の中でよく観察されます。この「神聖な」比率を使用して、タイポグラフィのこれらの属性を強化できる可能性があります。
<Text as="p" mb="5" size="4">
The goal of typography is to relate font size, line height, and line width in a proportional way that maximizes beauty and makes reading easier and more pleasant. The question is: What proportion(s) will give us the best results? The golden ratio is often observed in nature where beauty and utility intersect; perhaps we can use this “divine” proportion to enhance these attributes in our typography.
</Text>
<Text as="p" mb="5" size="3">
The goal of typography is to relate font size, line height, and line width in a proportional way that maximizes beauty and makes reading easier and more pleasant. The question is: What proportion(s) will give us the best results? The golden ratio is often observed in nature where beauty and utility intersect; perhaps we can use this “divine” proportion to enhance these attributes in our typography.
</Text>
<Text as="p" size="2" color="gray">
The goal of typography is to relate font size, line height, and line width in a proportional way that maximizes beauty and makes reading easier and more pleasant. The question is: What proportion(s) will give us the best results? The golden ratio is often observed in nature where beauty and utility intersect; perhaps we can use this “divine” proportion to enhance these attributes in our typography.
</Text>
サイズ1~3は、UIラベルに適しています。
<Grid align="center" columns="2" gap="5" p="3">
<Flex direction="column">
<Text size="3" weight="bold">
Get started
</Text>
<Text color="gray" size="2">
Start your next project in minutes
</Text>
</Flex>
<Flex direction="column">
<Text size="2" weight="bold">
Get started
</Text>
<Text color="gray" size="2">
Start your next project in minutes
</Text>
</Flex>
<Flex direction="column">
<Text size="2" weight="bold">
Get started
</Text>
<Text color="gray" size="1">
Start your next project in minutes
</Text>
</Flex>
<Flex direction="column">
<Text size="1" weight="bold">
Get started
</Text>
<Text color="gray" size="1">
Start your next project in minutes
</Text>
</Flex>
</Grid>
weight
プロパティを使用して、テキストの太さを設定します。
<Text weight="regular" as="div">
The quick brown fox jumps over the lazy dog.
</Text>
<Text weight="medium" as="div">
The quick brown fox jumps over the lazy dog.
</Text>
<Text weight="bold" as="div">
The quick brown fox jumps over the lazy dog.
</Text>
align
プロパティを使用して、テキストの配置を設定します。
<Text align="left" as="div">Left-aligned</Text>
<Text align="center" as="div">Center-aligned</Text>
<Text align="right" as="div">Right-aligned</Text>
trim
プロパティを使用して、テキストボックスの先頭、末尾、または両側の先頭のスペースをトリムします。
このプロパティは、今後のハーフリーディングコントロール仕様と同様に動作しますが、クロスブラウザサポートのために、一般的なネガティブマージン回避策を内部で使用します。
<Flex direction="column" gap="3">
<Text
trim="normal"
style={{
background: 'var(--gray-a2)',
borderTop: '1px dashed var(--gray-a7)',
borderBottom: '1px dashed var(--gray-a7)',
}}
>
Without trim
</Text>
<Text
trim="both"
style={{
background: 'var(--gray-a2)',
borderTop: '1px dashed var(--gray-a7)',
borderBottom: '1px dashed var(--gray-a7)',
}}
>
With trim
</Text>
</Flex>
先頭をトリミングすることは、カードやその他の「箱型」コンポーネントの垂直方向の間隔を調整する際に役立ちます。そうしないと、パディングは上下が側面よりも大きく見えます。
<Flex direction="column" gap="3">
<Box
style={{
background: 'var(--gray-a2)',
border: '1px dashed var(--gray-a7)',
}}
p="4"
>
<Heading mb="1" size="3">
Without trim
</Heading>
<Text>
The goal of typography is to relate font size, line height, and line width
in a proportional way that maximizes beauty and makes reading easier and
more pleasant.
</Text>
</Box>
<Box
p="4"
style={{
background: 'var(--gray-a2)',
border: '1px dashed var(--gray-a7)',
}}
>
<Heading mb="1" size="3" trim="start">
With trim
</Heading>
<Text trim="end">
The goal of typography is to relate font size, line height, and line width
in a proportional way that maximizes beauty and makes reading easier and
more pleasant.
</Text>
</Box>
</Flex>
デフォルトのトリム値は、Radix Themesで使用されるシステムフォントスタック用に構成されています。カスタムフォントを使用している場合は、対応するCSS変数を使用してトリム値を調整できます。
.radix-themes {
--default-leading-trim-start: 0.42em;
--default-leading-trim-end: 0.36em;
--heading-leading-trim-start: 0.42em;
--heading-leading-trim-end: 0.36em;
}
truncate
プロパティを使用して、テキストがコンテナからオーバーフローしたときに省略記号でテキストを切り捨てます。
<Flex maxWidth="300px">
<Text truncate>
The goal of typography is to relate font size, line height, and line width
in a proportional way that maximizes beauty and makes reading easier and
more pleasant.
</Text>
</Flex>
wrap
プロパティを使用して、テキストの折り返しを制御します。
<Flex maxWidth="270px">
<Text wrap="nowrap">
The goal of typography is to relate font size, line height, and line width
in a proportional way that maximizes beauty and makes reading easier and
more pleasant.
</Text>
</Flex>
<Flex maxWidth="270px">
<Text wrap="balance">
The goal of typography is to relate font size, line height, and line width
in a proportional way that maximizes beauty and makes reading easier and
more pleasant.
</Text>
</Flex>
<Flex maxWidth="270px">
<Text wrap="pretty">
The goal of typography is to relate font size, line height, and line width
in a proportional way that maximizes beauty and makes reading easier and
more pleasant.
</Text>
</Flex>
text-wrap: pretty
は実験的な値であり、 まだすべてのブラウザでサポートされていません。ただし、サポートしているブラウザのプログレッシブエンハンスメントとして扱うことができます。
color
プロパティを使用して、特定の色を割り当てます。テキストの色は、一般的な背景色に対して少なくともLc 60 APCAコントラストを達成するように設計されています。
<Flex direction="column">
<Text color="indigo">The quick brown fox jumps over the lazy dog.</Text>
<Text color="cyan">The quick brown fox jumps over the lazy dog.</Text>
<Text color="orange">The quick brown fox jumps over the lazy dog.</Text>
<Text color="crimson">The quick brown fox jumps over the lazy dog.</Text>
</Flex>
highContrast
プロパティを使用して、背景との色のコントラストを上げることができます。
<Flex direction="column">
<Text color="gray">The quick brown fox jumps over the lazy dog.</Text>
<Text color="gray" highContrast>
The quick brown fox jumps over the lazy dog.
</Text>
</Flex>
書式設定コンポーネントを使用して Text
を構成し、コンテンツに強調と構造を追加します。
見てください、こんなに役立つリンク、イタリック強調、コンピュータのコード
、そしてホットキーの組み合わせまで テキスト内の ⇧⌘A。
<Text as="p">
Look, such a helpful <Link href="#">link</Link>, an <Em>italic emphasis</Em>,
a piece of computer <Code>code</Code>, and even a hotkey combination{' '}
<Kbd>⇧⌘A</Kbd> within the text.
</Text>
Text
を Checkbox
、RadioGroup
、または Switch
のようなフォームコントロールと組み合わせて使用すると、テキストが複数行の場合でも、コントロールがテキストの最初の行の中央に自動的に配置されます。
<Box maxWidth="300px">
<Text as="label" size="3">
<Flex gap="2">
<Checkbox defaultChecked /> I understand that these documents are
confidential and cannot be shared with a third party.
</Flex>
</Text>
</Box>