跳转到内容

Typography 排印 ​

用于组织标题、正文和富文本内容。

用法 ​

组合标题和正文

构建一致的产品体验

使用清晰的层级和舒适的行距组织内容。阅读设计指南

组件结构 ​

加粗的是必需部件。

data-scope="typography":root · heading · paragraph · text · link · prose

示例 ​

标题层级 ​

设置标题的视觉层级

一级标题

二级标题

三级标题

四级标题

五级标题

六级标题

文本变体 ​

设置正文、辅助、强调、代码和链接样式

默认正文

辅助信息

重要内容

pnpm add @xihan-ui/vue

查看文档

颜色 ​

使用语义颜色

品牌

成功

警告

危险

信息

尺寸 ​

设置正文大小

小号正文

默认正文

大号正文

富文本 ​

排版外部 HTML 内容

安装

安装 Vue 组件和默认样式。

pnpm add @xihan-ui/vue @xihan-ui/styles
  • 组件按需引入
  • 皮肤整份引入

设计指引 ​

何时使用 ​

  • 展示文章、说明、条款或消息正文。
  • 统一标题层级、段落间距和行宽。

何时不用 ​

  • 单行标签或简短提示直接使用文本。
  • 需要限制长文本行数时,使用文本截断。
  • Markdown 内容使用 @xihan-ui/markdown 渲染后放入 prose。

特性 ​

  • 支持六档标题层级和三档正文尺寸。
  • 支持弱化、强调、代码等文本变体。
  • 支持链接、语义颜色、对齐和字重。
  • prose 可直接排版外部 HTML 内容。

组合 ​

最佳实践 ​

  • 使用 root 控制正文最大行宽。
  • 根据文档结构选择标题标签,使用 level 调整视觉大小。

反模式 ​

  • 不要仅为了放大文字而改变标题语义。
  • 不要在正文中密集放置交互控件。

API 参考 ​

产物 ​

层值
自定义元素<xh-typography>
Vue 组件XhTypographyHeading XhTypographyLink XhTypographyParagraph XhTypographyProse XhTypographyRoot XhTypographyText
状态机无,connect 直接由 props 算属性
皮肤@xihan-ui/styles/typography.css

Props ​

属性类型必填说明
alignTypographyAlign对齐:start / center / end / justify,整块正文随之变化。
sizeSize尺寸:sm / md / lg,整块正文的字号与段间距随之换档。
weightTypographyWeight字重:regular / medium / semibold / bold,整块正文随之变化。

React 适配器 props ​

只列各组件自己声明的那些:继承自 ComponentPropsWithRef 的 DOM 属性不在其中,根组件上与上面 Props 表同名的也不重复列。Vue 的对应物是上面的插槽表。

React 组件属性类型必填说明
XhTypographyHeadinglevelTypographyLevel | string字号档位 1-6,超出范围收敛到边界。
XhTypographyHeadingasElementType渲染为哪个标签,默认 p;需要进入文档大纲时写 h2(或 hN)。
XhTypographyProseasElementType渲染为哪个标签,默认 div。
XhTypographyTexttoneTone语气:决定使用哪族颜色。
XhTypographyTextvariantTypographyVariant形态:muted 弱化 / strong 加重 / code 等宽。
XhTypographyTextweightTypographyWeight字重:regular / medium / semibold / bold,只作用于该段行内文字。
XhTypographyTextasElementType渲染为哪个标签,默认 span;需要 code / strong 的原生语义时自行写明。

connect API ​

getXxxProps() 返回对应部件的宿主属性。

成员类型说明
getRootProps() => T['element']
getHeadingProps(props?: TypographyHeadingProps) => T['element']
getParagraphProps() => T['element']
getTextProps(props?: TypographyTextProps) => T['element']
getLinkProps() => T['element']
getProseProps() => T['element']富文本容器:外来的 HTML(Markdown 渲染结果)铺入其中,样式按标签提供。

无障碍 ​

键盘 ​

规格出处:W3C APG

无键盘交互(不接收焦点,或焦点行为完全由原生元素提供)。

样式参考 ​

皮肤 ​

@xihan-ui/styles/typography.css 使用 [data-scope="typography"][data-part="root"] 部件选择器,位于 xihan.components 层。覆盖样式使用 xihan.overrides。

数据属性 ​

由 connect 生成;条件不成立时不输出无值属性。

部件属性值
rootdata-alignprops.align
rootdata-sizeprops.size
rootdata-weightprops.weight
headingdata-levellevelAttr(heading.level)
textdata-tonetext.tone
textdata-varianttext.variant
textdata-weighttext.weight

CSS 变量 ​

本组件公开覆盖槽由独立皮肤的实际消费位生成;默认来源、作用部件和状态均与 CSS 同源。

变量部件CSS 属性状态默认来源说明
--xh-typography-block-gapheading
paragraph
margin-block-startis([data-part='heading'], [data-part='paragraph'])--xh-_typography-block-gaptypography 的 heading、paragraph 部件 margin-block-start 覆盖槽。
--xh-typography-code-bgprose
text
backgroundvariant=code
where(code)
--xh-bg-subtletypography 的 prose、text 部件 background 覆盖槽。
--xh-typography-code-fontprose
text
font-familyvariant=code
where(code)
where(pre)
--xh-font-family-monotypography 的 prose、text 部件 font-family 覆盖槽。
--xh-typography-code-font-sizeprose
text
font-sizevariant=code
where(code)
where(pre)
--xh-_typography-code-sizetypography 的 prose、text 部件 font-size 覆盖槽。
--xh-typography-code-pxprose
text
padding-inlinevariant=code
where(code)
--xh-space-1typography 的 prose、text 部件 padding-inline 覆盖槽。
--xh-typography-code-pyprose
text
padding-blockvariant=code
where(code)
--xh-space-0_5typography 的 prose、text 部件 padding-block 覆盖槽。
--xh-typography-code-radiusprose
text
border-radiusvariant=code
where(code)
--xh-shape-insettypography 的 prose、text 部件 border-radius 覆盖槽。
--xh-typography-fgrootcolordefault--xh-fg-defaulttypography 的 root 部件 color 覆盖槽。
--xh-typography-font-sizerootfont-sizedefault--xh-_typography-body-sizetypography 的 root 部件 font-size 覆盖槽。
--xh-typography-font-weightrootfont-weightdefault
weight=bold
weight=medium
weight=regular
weight=semibold
--xh-font-weight-bold
--xh-font-weight-medium
--xh-font-weight-regular
--xh-font-weight-semibold
--xh-text-body-weight
typography 的 root 部件 font-weight 覆盖槽。
--xh-typography-heading-fgheadingcolordefault--xh-fg-defaulttypography 的 heading 部件 color 覆盖槽。
--xh-typography-heading-font-sizeheadingfont-sizedefault
level=1
level=2
level=3
level=4
level=5
level=6
--xh-_typography-h1
--xh-_typography-h2
--xh-_typography-h3
--xh-_typography-h4
--xh-_typography-h5
--xh-_typography-h6
typography 的 heading 部件 font-size 覆盖槽。
--xh-typography-heading-font-weightheadingfont-weightdefault--xh-font-weight-semiboldtypography 的 heading 部件 font-weight 覆盖槽。
--xh-typography-heading-gapheading
paragraph
margin-block-startis([data-part='heading'], [data-part='paragraph'])--xh-_typography-heading-gaptypography 的 heading、paragraph 部件 margin-block-start 覆盖槽。
--xh-typography-heading-leadingheadingline-heightdefault--xh-leading-tighttypography 的 heading 部件 line-height 覆盖槽。
--xh-typography-leadingrootline-heightdefault--xh-text-body-leadingtypography 的 root 部件 line-height 覆盖槽。
--xh-typography-link-fglink
prose
colordefault
where(a)
--xh-fg-brandtypography 的 link、prose 部件 color 覆盖槽。
--xh-typography-link-fg-hoverlinkcolor@media (hover: hover)
hover
--xh-fg-brand-strongtypography 的 link 部件 color 覆盖槽。
--xh-typography-link-radiuslink
prose
border-radiusdefault
where(a)
--xh-shape-insettypography 的 link、prose 部件 border-radius 覆盖槽。
--xh-typography-link-underline-offsetlink
prose
text-underline-offsetdefault
where(a)
--xh-space-0_5typography 的 link、prose 部件 text-underline-offset 覆盖槽。
--xh-typography-measurerootmax-inline-sizedefault--xh-_typography-measuretypography 的 root 部件 max-inline-size 覆盖槽。
--xh-typography-prose-block-gapprosemargin-block-startwhere(h1, h2, h3, h4, h5, h6, p, ul, ol, pre, blockquote, table, hr)--xh-_typography-block-gaptypography 的 prose 部件 margin-block-start 覆盖槽。
--xh-typography-prose-cell-borderproseborder-block-endwhere(th, td)--xh-border-subtletypography 的 prose 部件 border-block-end 覆盖槽。
--xh-typography-prose-cell-pxprosepadding-inlinewhere(th, td)--xh-space-3typography 的 prose 部件 padding-inline 覆盖槽。
--xh-typography-prose-cell-pyprosepadding-blockwhere(th, td)--xh-space-2typography 的 prose 部件 padding-block 覆盖槽。
--xh-typography-prose-fgprosecolordefault--xh-fg-defaulttypography 的 prose 部件 color 覆盖槽。
--xh-typography-prose-font-sizeprosefont-sizedefault--xh-_typography-body-sizetypography 的 prose 部件 font-size 覆盖槽。
--xh-typography-prose-h1prosefont-sizewhere(h1)--xh-_typography-h1typography 的 prose 部件 font-size 覆盖槽。
--xh-typography-prose-h2prosefont-sizewhere(h2)--xh-_typography-h2typography 的 prose 部件 font-size 覆盖槽。
--xh-typography-prose-h3prosefont-sizewhere(h3)--xh-_typography-h3typography 的 prose 部件 font-size 覆盖槽。
--xh-typography-prose-h4prosefont-sizewhere(h4)--xh-_typography-h4typography 的 prose 部件 font-size 覆盖槽。
--xh-typography-prose-h5prosefont-sizewhere(h5)--xh-_typography-h5typography 的 prose 部件 font-size 覆盖槽。
--xh-typography-prose-h6prosefont-sizewhere(h6)--xh-_typography-h6typography 的 prose 部件 font-size 覆盖槽。
--xh-typography-prose-heading-fgprosecolorwhere(h1, h2, h3, h4, h5, h6)--xh-fg-defaulttypography 的 prose 部件 color 覆盖槽。
--xh-typography-prose-heading-font-weightprosefont-weightwhere(h1, h2, h3, h4, h5, h6)--xh-font-weight-semiboldtypography 的 prose 部件 font-weight 覆盖槽。
--xh-typography-prose-heading-gapprosemargin-block-startwhere(h1, h2, h3, h4, h5, h6)
where(h1, h2, h3, h4, h5, h6, p, ul, ol, pre, blockquote, table, hr)
--xh-_typography-heading-gaptypography 的 prose 部件 margin-block-start 覆盖槽。
--xh-typography-prose-item-gapprosemargin-block-startwhere(li + li)
where(li)
where(ul, ol)
--xh-space-1typography 的 prose 部件 margin-block-start 覆盖槽。
--xh-typography-prose-leadingproseline-heightdefault--xh-text-prose-leadingtypography 的 prose 部件 line-height 覆盖槽。
--xh-typography-prose-link-fgprosecolorwhere(a)--xh-typography-link-fgtypography 的 prose 部件 color 覆盖槽。
--xh-typography-prose-link-radiusproseborder-radiuswhere(a)--xh-typography-link-radiustypography 的 prose 部件 border-radius 覆盖槽。
--xh-typography-prose-link-underline-offsetprosetext-underline-offsetwhere(a)--xh-typography-link-underline-offsettypography 的 prose 部件 text-underline-offset 覆盖槽。
--xh-typography-prose-list-psprosepadding-inline-startwhere(ul, ol)--xh-space-6typography 的 prose 部件 padding-inline-start 覆盖槽。
--xh-typography-prose-pre-bgprosebackgroundwhere(pre)--xh-bg-subtletypography 的 prose 部件 background 覆盖槽。
--xh-typography-prose-pre-paddingprosepaddingwhere(pre)--xh-space-4typography 的 prose 部件 padding 覆盖槽。
--xh-typography-prose-pre-radiusproseborder-radiuswhere(pre)--xh-shape-surfacetypography 的 prose 部件 border-radius 覆盖槽。
--xh-typography-prose-quote-borderproseborder-inline-startwhere(blockquote)--xh-border-subtletypography 的 prose 部件 border-inline-start 覆盖槽。
--xh-typography-prose-quote-fgprosecolorwhere(blockquote)--xh-fg-mutedtypography 的 prose 部件 color 覆盖槽。
--xh-typography-prose-quote-psprosepadding-inline-startwhere(blockquote)--xh-space-4typography 的 prose 部件 padding-inline-start 覆盖槽。
--xh-typography-prose-rule-borderproseborder-block-startwhere(hr)--xh-border-subtletypography 的 prose 部件 border-block-start 覆盖槽。
--xh-typography-prose-strong-font-weightprosefont-weightwhere(strong)--xh-font-weight-semiboldtypography 的 prose 部件 font-weight 覆盖槽。
--xh-typography-prose-th-font-weightprosefont-weightwhere(th)--xh-font-weight-semiboldtypography 的 prose 部件 font-weight 覆盖槽。
--xh-typography-text-fg-mutedtextcolorvariant=muted--xh-fg-mutedtypography 的 text 部件 color 覆盖槽。
--xh-typography-text-fg-tonetextcolortone--xh-_tone-fgtypography 的 text 部件 color 覆盖槽。
--xh-typography-text-font-weighttextfont-weightvariant=strong--xh-font-weight-semiboldtypography 的 text 部件 font-weight 覆盖槽。

动效 ​

动效角色:状态(见动效规范)。

color 走 transition 过渡。时长与缓动读动效令牌,改令牌即改全局节奏。

系统开启减弱动效时由令牌层统一收敛,皮肤不另作判断。

响应式 ​

皮肤另按输入能力分档:hover: hover:同一份皮肤在触屏与带指针的设备上不一样,与视口宽度无关。

RTL ​

皮肤用逻辑属性排布(inline-start 一族),dir="rtl" 下自动镜像。

Released under The MIT License