Text
提供统一字号、字重、色调、行高与字距词汇的被动排版文本组件。
用于包裹纯文本与行内内容的被动排版组件,统一规范字号、色调、字重、字体族、行高、字距、斜体与装饰线词汇,具体排版效果由各风格组件呈现。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
将于 0.3.0-rc.1 及后续版本中提供(CLI 目标为 base-text)。可从 @proto.ui/prototypes-base/text 或包根导入 textRoot(以及 asTextRoot、TextRootProps、TextRootExposes)。
import * as React from 'react';import { createReactAdapter } from '@proto.ui/adapter-react';import { textRoot } from '@proto.ui/prototypes-base/text';
const Text = createReactAdapter(React)(textRoot, { rootTag: 'span' });
export function SectionTitle() { return ( <h1> <Text size="4xl" font="heading" weight="semibold" leading="tight" tracking="tight"> Account settings </Text> </h1> );}语义包裹与属性规则
Section titled “语义包裹与属性规则”- 保留原生语义元素:
rootTag: 'span'为 Web Adapter 选项;文档结构与交互语义继续保留在外层原生<h1>、<p>、<label>(htmlFor)或<a>(href、target、download)上,Text本身不添加焦点停靠点或点击事件。 - 颜色继承:在
solid或accent等深色Surface内部使用带样式的Text时,设置tone="inherit"可继承外层前景色以保持对比度。 - 字号与行高:移除属性时恢复默认值;初始传入非法
size回退为'base',已有合法值后再传入非法值则保持当前有效值。设置leading="size"时采用当前字号内建的行高(在 Shadcn 与 Brutalist 中,xs至5xl分别对应1rem、1.25rem、1.5rem、1.75rem、1.75rem、2rem、2.25rem、2.5rem、1);leading="tighter"对应1.1,tracking="tighter"对应-0.05em。
| 属性 | 类型 | 默认值 |
|---|---|---|
size | 'xs' 'sm' 'base' 'lg' 'xl' '2xl' '3xl' '4xl' '5xl' | base |
tone | 'default' 'muted' 'inherit' | default |
weight | 'normal' 'medium' 'semibold' 'bold' | normal |
font | 'body' 'heading' 'mono' | body |
leading | 'size' 'tighter' 'tight' 'snug' 'normal' 'relaxed' | normal |
tracking | 'normal' 'tight' 'tighter' | normal |
emphasis | 'normal' 'italic' | normal |
decoration | 'none' 'underline' 'line-through' | none |
组件不包含额外暴露状态、方法或事件,通过默认插槽保留传入的子元素。