文本
对齐目标:@astryxdesign/core v0.7.1 · Text
Body: The bulk of content Large: Emphasized content Label: Form and chart labels Supporting: Helper text Code: const x = 42;
使用方法 #
Text 用于渲染正文、辅助说明、表单标签等文字内容,type 提供了一套预设的字号、字重和行高组合,让整站文字风格保持一致。从独立入口导入即可,结构样式会随组件自动加载:
Vue
<script setup lang="ts">
import { Text } from '@astryx-vue/core/Text'
</script>
<template>
<Text type="body">
正文内容
</Text>
<Text type="supporting">
辅助说明
</Text>
</template>解剖
| 部分 | 说明 |
|---|---|
| 文本 | 多态文本元素,用主题里的字体渲染放进来的内容。 |
| 标题 | Text 上的 Heading。把放进来的内容渲染成语义上的 h1 到 h6。 |
| 截断提示 | 只有 Text 或 Heading 被测出已经截断,并且打开了截断提示时,才出现的 Tooltip 表面。 |
最佳实践 #
| 指引 | 实践 |
|---|---|
| 推荐 | 通过 type 表达文字的语义层级:large 用于强调性内容,supporting 用于辅助说明,label 用于表单标签。 |
| 推荐 | 需要块级布局时,把 as 设为 p 或将 display 设为 block,默认的行内元素不利于控制间距。 |
| 推荐 | 对可能超出容器的长文本设置 maxLines,超出部分会自动截断并显示省略号,避免撑破布局。 |
| 避免 | 用 Text 充当标题:标题请使用 Heading 组件,才能保证文档大纲对辅助技术可见。 |
| 避免 | 在同一小段文字中混用过多 type 和 size:样式变化过多会打断阅读节奏。 |
示例 #
文本 — 颜色
Primary — Default for headings and body textSecondary — Supporting details and metadataAccent — Links, emphasis, and accent-colored textDisabled — Unavailable or inactive contentPlaceholder — Empty field hints
primary、secondary、accent、disabled、placeholder 五种颜色,各自对应正文、辅助信息、强调、不可用内容和占位提示。
文本 — 标题层级
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Heading 从 h1 排到 h6,字号随层级下降。
文本 — 行内混排
Design tokens are themeable and shared across every surface.
默认是行内元素,所以正文和等宽代码可以排在同一行里。
文本 — 截断
1 line
The design system provides a consistent set of typography tokens, spacing scales, and color palettes that ensure every surface in the product feels cohesive regardless of which team built it.
2 lines
The design system provides a consistent set of typography tokens, spacing scales, and color palettes that ensure every surface in the product feels cohesive regardless of which team built it.
3 lines
The design system provides a consistent set of typography tokens, spacing scales, and color palettes that ensure every surface in the product feels cohesive regardless of which team built it.
在限宽容器里用 maxLines 把文字收成一行、两行或三行,超出的部分以省略号结尾。
文本 — 文本类型
Body textBody text for paragraphs and general content
Large textLarge text for introductions and callouts
Label textLabel text for form fields and section titles
Supporting textSupporting text for captions and metadata
Code textconst theme = defineTheme({})
StrikethroughBody text with strikethrough decoration
Tabular numbers1,234.56 78.90 100,000.00
body、large、label、supporting、code 五种语义类型,以及删除线和等宽数字。
文本 — 字重
NormalMediumSemiboldBold
normal、medium、semibold、bold 四种字重。normal 与 regular 是同一档。
文本 — 断词
Break-word (default for multi-line)
This is a verylongunbreakableword for a break-word example
Break-all (default for single-line)
Breaks anywhere: abcdefghijklmnopqrstuvwxyz0123456789
一长串没有空格的文字,break-word 尽量在词的边界断开,break-all 则可以在任意字符处断开。
文本 — 换行
Wrap (default)
This text wraps normally at word boundaries when it reaches the edge.
Nowrap
This text does not wrap and will overflow its container.
Balance
This text is balanced for better visual appearance across lines.
Pretty
This text uses pretty wrap to avoid orphans at the end of paragraphs.
wrap、nowrap、balance、pretty 四种换行方式,都放在同样宽度的盒子里。