Text
提供统一字号、字重、字体族、行高与色彩语义的 Shadcn 排版组件。
Text 继承 Base Text 的八项独立排版属性,使用 Shadcn 主题令牌管理字号、字重、行高、字距与前景色,同时把标题层级与交互语义交由外层原生元素承担。本页示例采用 Shadcn Rhea 风格。
<article class="flex max-w-xl flex-col gap-5">
<header class="flex flex-col gap-2">
<h1>
<proto-ui-shadcn-text
size="4xl"
font="heading"
weight="bold"
leading="tight"
tracking="tight"
>
Taxing Laughter: The Joke Tax Chronicles
</proto-ui-shadcn-text>
</h1>
<p>
<proto-ui-shadcn-text
size="xl"
tone="muted"
leading="relaxed"
>
Once upon a time, in a far-off land, a restless court looked
for a fairer way to fund the royal treasury.
</proto-ui-shadcn-text>
</p>
</header>
<h2 class="border-b border-border pb-2">
<proto-ui-shadcn-text
size="2xl"
font="heading"
weight="semibold"
leading="tight"
tracking="tight"
>
The King's Plan
</proto-ui-shadcn-text>
</h2>
<p>
<proto-ui-shadcn-text leading="relaxed">
The king thought long and hard, and finally proposed
</proto-ui-shadcn-text>
<a href="#examples">
<proto-ui-shadcn-text weight="medium" decoration="underline">
a brilliant plan
</proto-ui-shadcn-text>
</a>
<proto-ui-shadcn-text leading="relaxed">
: taxing every pun and one-liner told in the kingdom.
</proto-ui-shadcn-text>
</p>
<blockquote class="border-s-2 border-border ps-4">
<proto-ui-shadcn-text emphasis="italic" leading="relaxed">
"After all, everyone enjoys a good joke, so it is only fair
that they pay for the privilege."
</proto-ui-shadcn-text>
</blockquote>
<div class="flex flex-wrap items-center gap-2">
<code class="rounded bg-muted px-2 py-0.5">
<proto-ui-shadcn-text
size="sm"
font="mono"
weight="semibold"
leading="size"
>
@proto.ui/prototypes-shadcn/text
</proto-ui-shadcn-text>
</code>
<proto-ui-shadcn-text size="sm" tone="muted">
Shadcn Rhea · Geist & CJK fallback ready
</proto-ui-shadcn-text>
</div>
</article>先初始化你的应用,再添加 shadcn-text 组件(当前草案能力在工作区源码中提供):
此组件由工作区源码提供。请在应用中安装同一工作区提交构建的 CLI、Shadcn 原型包与目标适配器,用该 CLI 初始化项目,再运行本地命令生成组件封装。
npm exec -- proto-ui add wc shadcn-text
pnpm exec proto-ui add wc shadcn-text
将命令中的 wc 替换为 react、vue 或 vue2,即可生成对应框架的本地组件封装。
CLI 生成的组件可直接配合原生 h1–h4、p、blockquote、code、label 与 a 使用:
import { ShadcnTextRoot } from '../proto-ui/components/react';
export function SectionTitle() { return ( <h1> <ShadcnTextRoot size="4xl" font="heading" weight="bold" leading="tight" tracking="tight"> Account settings </ShadcnTextRoot> </h1> );}也可以直接从 @proto.ui/prototypes-shadcn/text 导入 shadcnTextRoot(提供 textRoot 与 ShadcnTextRoot 别名)并通过 Adapter 指定 rootTag: 'span',或按需启用内置的 SHADCN_TYPOGRAPHY 字体主题预设(Geist 搭配系统与 CJK 回退链;字体文件与授权由应用自行托管):
import { shadcnTextRoot, SHADCN_TYPOGRAPHY } from '@proto.ui/prototypes-shadcn/text';语义边界与排版细节
Section titled “语义边界与排版细节”- 外层原生语义:Text 本身不添加角色、焦点停靠点或点击事件;标题层级、
label(htmlFor/for)与链接(href、target、download)应由外层原生元素声明。 - 字号内建行高与紧凑刻度:
leading="size"保留所选字号的内建行高(xs1rem、sm1.25rem、base1.5rem、lg1.75rem、xl1.75rem、2xl2rem、3xl2.25rem、4xl2.5rem、5xl1);leading="tighter"对应1.1,tracking="tighter"对应-0.05em。 - 默认值与回退:移除属性即可恢复默认值;初始传入非法
size回退到base,已有合法值后更新为非法值则保留上一个有效值。 - 操作排版预设(
actionProfile):默认为'none',不会隐式订阅shadcn-style-scope;显式传入'rhea'或'luma'等预设时应用对应的操作行高(rhea/luma/vega/nova/maia/new-york-v4为1.25rem,lyra/sera为1rem,mira为1.625,sera额外启用大写与宽字距)。
字号与字重刻度
Section titled “字号与字重刻度”展示 5xl 至 xs 的完整排版刻度,以及 leading="tighter"、leading="size" 与 tracking="tighter" 的组合效果。
<div class="flex max-w-xl flex-col gap-3">
<h1>
<proto-ui-shadcn-text
size="5xl"
font="heading"
weight="bold"
leading="tighter"
tracking="tighter"
>
5xl · Display Title
</proto-ui-shadcn-text>
</h1>
<h1>
<proto-ui-shadcn-text
size="4xl"
font="heading"
weight="bold"
leading="tight"
tracking="tight"
>
4xl · Page Heading
</proto-ui-shadcn-text>
</h1>
<h2>
<proto-ui-shadcn-text
size="3xl"
font="heading"
weight="semibold"
leading="tight"
tracking="tight"
>
3xl · Section Heading
</proto-ui-shadcn-text>
</h2>
<h3>
<proto-ui-shadcn-text
size="2xl"
font="heading"
weight="semibold"
leading="snug"
tracking="tight"
>
2xl · Subsection Heading
</proto-ui-shadcn-text>
</h3>
<h4>
<proto-ui-shadcn-text
size="xl"
font="heading"
weight="semibold"
leading="size"
>
xl · Card Title
</proto-ui-shadcn-text>
</h4>
<p>
<proto-ui-shadcn-text
size="lg"
weight="semibold"
leading="size"
>
lg · Large Callout
</proto-ui-shadcn-text>
</p>
<p>
<proto-ui-shadcn-text
size="base"
weight="normal"
leading="normal"
>
base · Default body copy for paragraphs and descriptions.
</proto-ui-shadcn-text>
</p>
<small>
<proto-ui-shadcn-text size="sm" weight="medium" leading="size">
sm · Compact control label & metadata
</proto-ui-shadcn-text>
</small>
<small>
<proto-ui-shadcn-text size="xs" tone="muted" leading="size">
xs · Caption, badge, and keyboard hint
</proto-ui-shadcn-text>
</small>
</div>语义排版组合
Section titled “语义排版组合”展示导语(Lead)、大号强调、引文(emphasis="italic")、行内等宽代码(font="mono")、下划线链接(decoration="underline")、删除线(decoration="line-through")与表单辅助说明的常用组合。
<div class="flex max-w-xl flex-col gap-4">
<p>
<proto-ui-shadcn-text size="xl" tone="muted" leading="relaxed">
A modal dialog that interrupts the user with important content
and expects a response.
</proto-ui-shadcn-text>
</p>
<p>
<proto-ui-shadcn-text
size="lg"
weight="semibold"
leading="snug"
>
Are you absolutely sure?
</proto-ui-shadcn-text>
</p>
<blockquote class="border-s-2 border-border ps-4">
<proto-ui-shadcn-text emphasis="italic" leading="relaxed">
"Clear typography turns complex workflows into calm reading."
</proto-ui-shadcn-text>
</blockquote>
<div class="flex flex-wrap items-center gap-3">
<code class="rounded bg-muted px-2 py-0.5">
<proto-ui-shadcn-text
size="sm"
font="mono"
weight="semibold"
leading="size"
>
npx @proto.ui/cli add react shadcn-text
</proto-ui-shadcn-text>
</code>
<a href="#api">
<proto-ui-shadcn-text
size="sm"
weight="medium"
decoration="underline"
>
View API table
</proto-ui-shadcn-text>
</a>
<del>
<proto-ui-shadcn-text
size="sm"
tone="muted"
decoration="line-through"
>
Legacy 13px copy
</proto-ui-shadcn-text>
</del>
</div>
<div class="flex flex-col gap-1">
<small>
<proto-ui-shadcn-text
size="sm"
weight="medium"
leading="tight"
>
Email address
</proto-ui-shadcn-text>
</small>
<p>
<proto-ui-shadcn-text size="sm" tone="muted">
Enter your work email to receive release notifications.
</proto-ui-shadcn-text>
</p>
</div>
</div>色调与表面前景色继承
Section titled “色调与表面前景色继承”在深色、实心(solid)或强调色(accent)Surface 容器中设置 tone="inherit",让文字自动跟随外层前景色,在亮暗主题下均保持清晰对比度。
<div class="grid max-w-xl grid-cols-1 gap-3 sm:grid-cols-2">
<proto-ui-shadcn-surface variant="outline" radius="lg">
<div class="flex flex-col gap-1 p-4">
<proto-ui-shadcn-text
size="sm"
weight="semibold"
tone="default"
>
Default Ink
</proto-ui-shadcn-text>
<proto-ui-shadcn-text size="sm" tone="muted">
Muted secondary copy on a neutral surface.
</proto-ui-shadcn-text>
</div>
</proto-ui-shadcn-surface>
<proto-ui-shadcn-surface
variant="solid"
radius="lg"
border="none"
>
<div class="flex flex-col gap-1 p-4">
<proto-ui-shadcn-text
size="sm"
weight="semibold"
tone="inherit"
>
Solid Surface · tone="inherit"
</proto-ui-shadcn-text>
<proto-ui-shadcn-text size="sm" tone="inherit">
Inherits primary-foreground ink automatically.
</proto-ui-shadcn-text>
</div>
</proto-ui-shadcn-surface>
<proto-ui-shadcn-surface
variant="accent"
radius="lg"
border="none"
>
<div class="flex flex-col gap-1 p-4">
<proto-ui-shadcn-text
size="sm"
weight="semibold"
tone="inherit"
>
Accent Surface · tone="inherit"
</proto-ui-shadcn-text>
<proto-ui-shadcn-text size="sm" tone="inherit">
Stays paired with accent-foreground in light and dark mode.
</proto-ui-shadcn-text>
</div>
</proto-ui-shadcn-surface>
<proto-ui-shadcn-surface
variant="muted"
radius="lg"
border="none"
>
<div class="flex flex-col gap-1 p-4">
<proto-ui-shadcn-text
size="sm"
weight="semibold"
tone="default"
>
Muted Surface
</proto-ui-shadcn-text>
<proto-ui-shadcn-text size="sm" tone="muted">
Supports default and muted hierarchy cleanly.
</proto-ui-shadcn-text>
</div>
</proto-ui-shadcn-surface>
</div>操作排版预设(actionProfile)
Section titled “操作排版预设(actionProfile)”将 actionProfile 与对应风格的 Surface 配对,呈现 Rhea、Luma、Lyra、Mira 与 Sera 的紧凑操作文字行高与字距规范。
<div
id="text-action-profiles"
class="flex flex-wrap items-center gap-3"
>
<proto-ui-shadcn-surface variant="solid">
<span class="block px-3 py-1.5">
<proto-ui-shadcn-text
size="sm"
weight="medium"
tone="inherit"
>
Rhea · 1.25rem
</proto-ui-shadcn-text>
</span>
</proto-ui-shadcn-surface>
<proto-ui-shadcn-surface variant="secondary">
<span class="block px-3 py-1.5">
<proto-ui-shadcn-text
size="sm"
weight="medium"
tone="inherit"
>
Luma · 1.25rem
</proto-ui-shadcn-text>
</span>
</proto-ui-shadcn-surface>
<proto-ui-shadcn-surface variant="outline">
<span class="block px-2.5 py-1.5">
<proto-ui-shadcn-text
size="xs"
weight="medium"
tone="inherit"
>
Lyra · 1rem
</proto-ui-shadcn-text>
</span>
</proto-ui-shadcn-surface>
<proto-ui-shadcn-surface variant="secondary">
<span class="block px-2.5 py-1">
<proto-ui-shadcn-text
size="xs"
weight="medium"
tone="inherit"
>
Mira · relaxed
</proto-ui-shadcn-text>
</span>
</proto-ui-shadcn-surface>
<proto-ui-shadcn-surface variant="solid">
<span class="block px-3 py-1.5">
<proto-ui-shadcn-text
size="xs"
weight="semibold"
tone="inherit"
>
Sera · Uppercase
</proto-ui-shadcn-text>
</span>
</proto-ui-shadcn-surface>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const profiles = ['rhea', 'luma', 'lyra', 'mira', 'sera'];
const root = document.querySelector('#text-action-profiles');
root
?.querySelectorAll('proto-ui-shadcn-surface')
.forEach((el, i) =>
setElementProps(el, { actionProfile: profiles[i] })
);
root
?.querySelectorAll('proto-ui-shadcn-text')
.forEach((el, i) =>
setElementProps(el, { actionProfile: profiles[i] })
);
</script>RTL 与中英混排
Section titled “RTL 与中英混排”Text 遵循外层容器的 dir="rtl" 逻辑方向,并支持中英文与多语言混排下的系统字体回退。
<div class="flex max-w-xl flex-col gap-5">
<section
dir="rtl"
lang="ar"
class="flex flex-col gap-3 rounded-lg border border-border p-4 text-start"
>
<h2>
<proto-ui-shadcn-text
size="2xl"
font="heading"
weight="bold"
leading="tight"
>
فرض الضرائب على الضحك: سجلات ضريبة النكتة
</proto-ui-shadcn-text>
</h2>
<p>
<proto-ui-shadcn-text tone="muted" leading="relaxed">
تتبع النصوص اتجاه الحاوية المنطقي مع الحفاظ على تدرج الخطوط
وارتفاع الأسطر عبر اللغات من اليمين إلى اليسار.
</proto-ui-shadcn-text>
</p>
<blockquote class="border-s-2 border-border ps-4">
<proto-ui-shadcn-text
size="sm"
emphasis="italic"
leading="relaxed"
>
«الجميع يستمتع بنكتة جيدة عندما تكون القراءة مريحة وواضحة.»
</proto-ui-shadcn-text>
</blockquote>
</section>
<section
lang="zh-CN"
class="flex flex-col gap-2 rounded-lg border border-border p-4 text-start"
>
<h3>
<proto-ui-shadcn-text
size="xl"
font="heading"
weight="semibold"
leading="snug"
>
中英混排与 CJK 回退示例 · Geist + System CJK
</proto-ui-shadcn-text>
</h3>
<p>
<proto-ui-shadcn-text
size="sm"
tone="muted"
leading="relaxed"
>
搭配 SHADCN_TYPOGRAPHY 预设时,拉丁字符优先使用
Geist,中文字符平滑回退至系统无衬线字体。
</proto-ui-shadcn-text>
</p>
</section>
</div>以下属性属于 Root(ShadcnTextRoot):
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
size | 'xs' 'sm' 'base' 'lg' 'xl' '2xl' '3xl' '4xl' '5xl' | base | 字号刻度;配合 leading="size" 可保留字号内建行高 |
tone | 'default' 'muted' 'inherit' | default | 文字颜色语义;在彩色或深色表面内使用 inherit 继承前景色 |
weight | 'normal' 'medium' 'semibold' 'bold' | normal | 字重 |
font | 'body' 'heading' 'mono' | body | 字体族(正文、标题或等宽) |
leading | 'size' 'tighter' 'tight' 'snug' 'normal' 'relaxed' | normal | 行高;size 保留字号默认行高,tighter 为 1.1 |
tracking | 'normal' 'tight' 'tighter' | normal | 字距;tight 为 -0.025em,tighter 为 -0.05em |
emphasis | 'normal' 'italic' | normal | 正体或斜体样式 |
decoration | 'none' 'underline' 'line-through' | none | 文字装饰线 |
actionProfile | 'none' 'vega' 'nova' 'maia' 'lyra' 'mira' 'luma' 'sera' 'rhea' 'new-york-v4' 'new-york' | none | 显式操作排版预设(Shadcn 专有),不隐式继承 style-scope |