使用场景
- 对文章、博客、日志等的文本内容进行展示时。
- 对文本进行复制和省略等基础操作时。
代码演示
如何引入
<script setup lang="ts">
import { Typography } from '@fibrous/semi-ui-vue';
</script>
模板中使用 Typography.Text、Typography.Title、Typography.Paragraph、Typography.Numeral,也可以直接导入 TypographyText、TypographyTitle、TypographyParagraph、TypographyNumeral。
标题组件
通过设置 heading 可以展示不同级别的标题。
h1. Semi Design
h2. Semi Design
h3. Semi Design
h4. Semi Design
h5. Semi Design
h6. Semi Design
代码
<script setup lang="ts">
import { Typography } from '@fibrous/semi-ui-vue';
const { Title } = Typography;
</script>
<template>
<div>
<Title style="margin: 8px 0">h1. Semi Design</Title>
<Title :heading="2" style="margin: 8px 0">h2. Semi Design</Title>
<Title :heading="3" style="margin: 8px 0">h3. Semi Design</Title>
<Title :heading="4" style="margin: 8px 0">h4. Semi Design</Title>
<Title :heading="5" style="margin: 8px 0">h5. Semi Design</Title>
<Title :heading="6" style="margin: 8px 0">h6. Semi Design</Title>
</div>
</template>文本组件
内置不同样式的文本。
可以通过 #icon 插槽传入图标,这种方式传入的图标默认与文本有间距,同时在链接文本的情况不会出现下划线符合设计规范。
Secondary
Tertiary v>=1.2.0
Quaternary v>=1.2.0
Warning
Danger
Success v>=1.7.0
Disabled
Default Mark
Example CodeUnderline
Strong
代码
<script setup lang="ts">
import { Typography } from '@fibrous/semi-ui-vue';
const { Text } = Typography;
</script>
<template>
<div>
<Text>Text</Text>
<br />
<br />
<Text type="secondary">Secondary</Text>
<br />
<br />
<Text type="tertiary">Tertiary v>=1.2.0</Text>
<br />
<br />
<Text type="quaternary">Quaternary v>=1.2.0</Text>
<br />
<br />
<Text type="warning">Warning</Text>
<br />
<br />
<Text type="danger">Danger</Text>
<br />
<br />
<Text type="success">Success v>=1.7.0</Text>
<br />
<br />
<Text disabled>Disabled</Text>
<br />
<br />
<Text mark>Default Mark</Text>
<br />
<br />
<Text code>Example Code</Text>
<br />
<br />
<Text underline>Underline</Text>
<br />
<br />
<Text delete>Deleted</Text>
<br />
<br />
<Text strong>Strong</Text>
</div>
</template>链接文本支持传入 object,将对应的属性挂在 <a> 标签上。
默认没有下划线,可以配合 underline 属性在 hover、active 态增加下划线的样式。
代码
<script setup lang="ts">
import { IconLink } from '@fibrous/semi-icons-vue';
import { Typography } from '@fibrous/semi-ui-vue';
const { Text } = Typography;
</script>
<template>
<div>
<Text :link="{ href: 'https://semi.design/' }">链接文本</Text>
<br />
<br />
<Text :link="{ href: 'https://semi.design/' }">打开网站</Text>
<br />
<br />
<Text link underline>
带下划线的网页链接
<template #icon>
<IconLink />
</template>
</Text>
</div>
</template>段落组件
段落组件拥有两种行距,可以通过设置 spacing='extended' 使用更宽松的行距。
默认行距
Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
宽松行距
Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
代码
<script setup lang="ts">
import { Typography } from '@fibrous/semi-ui-vue';
const { Paragraph, Title } = Typography;
</script>
<template>
<div>
<Title :heading="5">默认行距</Title>
<Paragraph> Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。 </Paragraph>
<br />
<Title :heading="5">宽松行距</Title>
<Paragraph spacing="extended"> Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。 </Paragraph>
</div>
</template>数值组件
Numeral 组件在Text组件的基础上,添加了属性: rule, precision, truncate, parser, 以提供需要单独处理文本中数值的能力。
precision 可以设置小数点后保留位数, 用于设置精度
truncate 小数点后保留位截段取整方式,可选 ceil, floor, round,作用与 Math.ceil、Math.floor、Math.round 对齐
rule 用于设置解析规则
- 设为
percentages会将数字自动转换为百分比形式展示 - 设为
bytes-decimal会将数字自动换算为字节对应的单位展示, 1 KB 定义为等于 1000 字节,(B, KB, MB, GB, TB, PB, EB, ZB, YB) - 设为
bytes-binary会将数字自动换算为字节对应的单位展示,1 KiB 定义为等于 1024字节,(B, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB) - 设为
text时,仅自动对数字进行取整,根据precision和truncate属性 - 设为
numbers时,会将非数字字符进行过滤,仅展示数字 - 设为
exponential时,会将数字自动转换为科学计数法形式展示
Numeral 默认渲染 span,内容里包含 p 等块级元素时,用 component="div" 改为块级容器。
Vue 模板中相邻的文字与插值合成一个文本节点并整段格式化,所以 rule="numbers" 的逗号分隔会跨过插值。
点赞量:16.1 K
播放量:244.4K
好评率: 91.50%
已使用: 1.00 KB
未使用: 1.02 MB
已使用: 1.00 KiB
未使用: 1.81 TiB
代码
<script setup lang="ts">
import { Typography } from '@fibrous/semi-ui-vue';
const { Numeral } = Typography;
</script>
<template>
<div>
<Numeral component="div" :precision="1">
<p>点赞量:1.6111e1 K</p>
</Numeral>
<p>播放量:<Numeral :precision="1" rule="numbers">2.4444e2</Numeral>K</p>
<Numeral component="div" :precision="2" rule="percentages" style="margin-bottom: 12px">
<p>好评率: 0.915</p>
</Numeral>
<Numeral rule="percentages" style="margin-bottom: 12px">这场比赛我的胜率是0.6,输的概率是0.4</Numeral>
<Numeral component="div" :precision="2" rule="bytes-decimal" truncate="floor">
<p>已使用: 1000</p>
<p>未使用: {{ 1024 * 1000 }}</p>
</Numeral>
<Numeral component="div" :precision="2" rule="bytes-binary" truncate="floor">
<p>已使用: 1024</p>
<p>未使用: {{ 2e12 }}</p>
</Numeral>
</div>
</template>可以通过 parser 自定义解析规则
Stars:7,100+
Fork:560+
Downloads:5,000,000+
Contributors:100+
现已服务 100,000+ 用户,前往官网 >>
代码
<script setup lang="ts">
import { Typography } from '@fibrous/semi-ui-vue';
const { Numeral } = Typography;
function parserTCH(oldVal: string) {
return oldVal
.split(' ')
.map((item) => (Number(item) ? `${item.replace(/(\d)(?=(?:\d{3})+(?:\.|$))/g, '$1,')}+` : item))
.join(' ');
}
const infos = [
{ type: 'Stars', min: '7100' },
{ type: 'Fork', min: '560' },
{ type: 'Downloads', min: '5000000' },
{ type: 'Contributors', min: '100' },
];
</script>
<template>
<div>
<Numeral component="div" :parser="parserTCH">
Semi Design 重视我们的用户,加入并助力我们不断完善
<p v-for="item in infos" :key="item.min">
{{ item.type }}:<b style="color: var(--semi-violet-5)">{{ item.min }}</b>
</p>
</Numeral>
<br />
<Numeral :link="{ href: 'https://semi.design', target: '_blank' }" :parser="parserTCH"> 现已服务 {{ 1e5 }} 用户,前往官网 >> </Numeral>
</div>
</template>文本大小
段落组件和文本组件支持两种尺寸 small(12px)和 normal(14px),另可设为 inherit 继承外层尺寸,默认为 normal。
当段落组件或者文本组件嵌套使用时候,设置内层组件的 size 属性为 inherit,内层组件的 size 将继承外层组件的尺寸设置。
Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
小文本
Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
这是一段文本,样式为 small 这是一段链接,设置 size 为 inherit 继承外部样式设置
代码
<script setup lang="ts">
import { Typography } from '@fibrous/semi-ui-vue';
const { Paragraph, Text } = Typography;
</script>
<template>
<div>
<Text>正常文本</Text>
<Paragraph spacing="extended"> Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。 </Paragraph>
<br />
<Text size="small">小文本</Text>
<Paragraph size="small"> Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。 </Paragraph>
<br />
<Text size="small">
这是一段文本,样式为 small
<Text link size="inherit">这是一段链接,设置 size 为 inherit 继承外部样式设置</Text>
</Text>
</div>
</template>可复制文本
可通过配置 copyable 属性支持文本的复制。
当 copyable 配置为 true时,默认复制内容为 children 本身,注意,此时 children 只支持 string类型传入
当 copyable 配置为 object 时,可通过 copyable.content 指定复制至粘贴板的内容,与 children 不再强关联, 此时 children 将不再限定类型,但 copyable.content 仍需要为 string
复制按钮的内容用 #copyIcon 插槽,提示用 #copyTip,成功提示用 #copySuccessTip;用 #copyAction="{ copied, copy, config }" 完全自定义复制节点的渲染。
点击右边的图标复制文本。
点击复制文本。
点击右边的图标复制文本。
时间戳: 1700000000s自定义复制节点
自定义复制渲染
粘贴区域:
代码
<script setup lang="ts">
import { IconSetting } from '@fibrous/semi-icons-vue';
import { Button, TextArea, Toast, Typography } from '@fibrous/semi-ui-vue';
const { Paragraph, Text, Numeral } = Typography;
// fixed so the server render and the browser agree
const timestamp = 1700000000;
</script>
<template>
<div>
<Paragraph copyable>点击右边的图标复制文本。</Paragraph>
<Paragraph :copyable="{ content: 'Hello, Semi Design!' }">点击复制文本。</Paragraph>
<Paragraph copyable @copy="Toast.success({ content: '复制文本成功' })">点击右边的图标复制文本。</Paragraph>
时间戳:
<Numeral copyable truncate="ceil" underline>{{ timestamp }}s</Numeral>
<Paragraph copyable>
自定义复制节点
<template #copyIcon>
<IconSetting style="color: var(--semi-color-link)" />
</template>
</Paragraph>
<Paragraph :copyable="{ content: 'Custom render!' }">
自定义复制渲染
<template #copyAction="{ copied, copy, config }">
<Button size="small" @click="copy">
<span>{{ copied ? '复制成功' : `点击复制:${config.content}` }}</span>
</Button>
</template>
</Paragraph>
<br />
<br />
<Text id="typography-copyable-paste" type="secondary">粘贴区域:</Text>
<br />
<TextArea aria-labelledby="typography-copyable-paste" autosize :rows="3" style="width: 320px; margin-top: 4px" />
</div>
</template>省略文本
支持文本的省略,可以通过 ellipsis 配置相关参数,具体参考 Ellipsis Config。
是一个很长很长很长很长5号标题
可以自定义浮层里的展示内容试试看吧
是一个很长很长很长很长的链接
有后缀的情况:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。小尾巴
这是一个多行截断的例子:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
多行截断,展示 Popover:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
支持展开和折叠:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
sssssssssssssssssssssssss
这是一个自定义弹出层组件的省略文本,背景色是蓝色
代码
<script setup lang="ts">
import { Tooltip, Typography } from '@fibrous/semi-ui-vue';
const { Paragraph, Title, Text } = Typography;
</script>
<template>
<div>
<Title :ellipsis="{ showTooltip: true }" :heading="5" style="width: 250px">是一个很长很长很长很长5号标题</Title>
<br />
<Text :ellipsis="{ showTooltip: true }" style="width: 150px">
可以自定义浮层里的展示内容试试看吧
<template #ellipsisContent>这是自定义要展示的内容</template>
</Text>
<br />
<Text :ellipsis="{ showTooltip: true, pos: 'middle' }" link style="width: 150px">是一个很长很长很长很长的链接</Text>
<br />
<Paragraph :ellipsis="{ suffix: '小尾巴' }" style="width: 300px"> 有后缀的情况:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。 </Paragraph>
<br />
<Paragraph :ellipsis="{ rows: 3 }" style="width: 300px"> 这是一个多行截断的例子:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。 </Paragraph>
<br />
<Paragraph :ellipsis="{ rows: 3, showTooltip: { type: 'popover', opts: { style: { width: '300px' } } } }" style="width: 300px">
多行截断,展示 Popover:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
</Paragraph>
<br />
<Paragraph :ellipsis="{ rows: 3, expandable: true, collapsible: true, collapseText: '折叠我吧' }" style="width: 300px" @expand="(expanded, e) => console.log(expanded, e)">
支持展开和折叠:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
</Paragraph>
<br />
<Text :ellipsis="{ showTooltip: true, pos: 'middle' }" style="width: 150px; word-break: break-word">
sssssssssssssssssssssssss
<template #ellipsisContent>全英文设置了word-break</template>
</Text>
<br />
<br />
<Title :ellipsis="{ showTooltip: true }" :heading="5" style="width: 250px">
这是一个自定义弹出层组件的省略文本,背景色是蓝色
<template #ellipsisTooltip="{ content, trigger }">
<Tooltip style="background-color: var(--semi-color-primary)">
<component :is="trigger" />
<template #content>{{ content }}</template>
</Tooltip>
</template>
</Title>
</div>
</template>覆盖类名超长文本发生截断时可使用类名覆盖进行自定义配置
覆盖style超长文本发生截断时可使用style进行自定义配置
代码
<script setup lang="ts">
import { Typography } from '@fibrous/semi-ui-vue';
const { Text } = Typography;
</script>
<template>
<div>
<Text :ellipsis="{ showTooltip: true }" style="width: 150px">
有问题的超长文本发生截断时可按需进行自定义配置
<template #ellipsisContent>架构|Semi-inf|graph.cheet.relation</template>
</Text>
<br />
<Text :ellipsis="{ showTooltip: { opts: { class: 'components-typography-demo' } } }" style="width: 150px">
覆盖类名超长文本发生截断时可使用类名覆盖进行自定义配置
<template #ellipsisContent>架构|Semi-inf|graph.cheet.relation</template>
</Text>
<br />
<Text :ellipsis="{ showTooltip: { opts: { style: { wordBreak: 'break-all' } } } }" style="width: 150px">
覆盖style超长文本发生截断时可使用style进行自定义配置
<template #ellipsisContent>架构|Semi-inf|graph.cheet.relation</template>
</Text>
</div>
</template>// 按需配置 word-break
.components-typography-demo {
word-break: break-word;
// 或
word-break: break-all;
}
API参考
Typography.Text
Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| code | 是否被 code 元素包裹。 | boolean | false |
| ellipsis | 设置自动溢出省略;传对象时见 Ellipsis Config。 | boolean | Ellipsis | false |
| size | 文本大小,inherit 继承外层 Text 或 Paragraph 的尺寸。 | "normal" | "small" | "inherit" | "normal" |
| weight | 字重,数字。 | number | undefined |
| component | 自定义渲染元素,可以是标签名或 Vue 组件,默认 span。 | string | Component | undefined |
| copyable | 是否可复制;传对象时见 Copyable Config。 | boolean | TypographyCopyableConfig | false |
| delete | 添加删除线样式。 | boolean | false |
| disabled | 禁用文本。 | boolean | false |
| link | 是否为链接;传对象时,其中的属性(href、target、class、style、onClick 等)挂在 a 元素上。 | LinkType | false |
| mark | 添加标记样式。 | boolean | false |
| strong | 是否加粗。 | boolean | false |
| type | 文本类型。 | Type"primary" | "secondary" | "danger" | "warning" | "success" | "tertiary" | "quaternary" | "primary" |
| underline | 添加下划线样式。 | boolean | false |
Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| expand | 点击展开或收起控件时触发,参数为操作之后的展开状态和点击事件。 | [expanded: boolean, e: MouseEvent] |
| copy | 复制后触发,参数为点击事件、复制的内容和是否写入成功;写入被拒绝时为 false,此时不进入已复制状态。 | [e: MouseEvent, content: string, res: boolean] |
Slots
| 插槽 | 说明 | 作用域参数 |
|---|---|---|
| default | 文本内容。 | any |
| icon | 前缀图标;Semi 图标按 size 自动设为 small 或 default。 | any |
| copyIcon | 复制按钮的内容;内容为单个节点且带 aria-label 时以它作为按钮的可访问名称,否则用语言包的「复制」。 | any |
| copyTip | 复制图标的提示内容。 | any |
| copySuccessTip | 复制成功后的展示内容。 | any |
| copyAction | 完全自定义复制节点,参数为 copied、copy 和解析后的 config。 | TypographyCopyActionProps |
| ellipsisContent | 截断时浮层中的内容,默认是全文。 | any |
| ellipsisTooltip | 自定义浮层,仅在文本溢出时渲染;参数 content 是全文,trigger 是文字元素,用 <component :is="trigger" /> 放入自己的浮层。 | TypographyEllipsisTooltipProps |
Exposes
| 名称 | 说明 | 类型 |
|---|---|---|
| 无 |
class、style、id、aria-* 等原生属性经 attrs 落在文字元素上。
Typography.Title
Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| ellipsis | 设置自动溢出省略;传对象时见 Ellipsis Config。 | boolean | Ellipsis | false |
| heading | 标题级别,对应 h1 到 h6。 | 1 | 2 | 3 | 4 | 5 | 6 | 1 |
| weight | 字重,可选 light、regular、medium、semibold、bold、default,或数字。 | Typenumber | "bold" | "default" | "medium" | "light" | "regular" | "semibold" | undefined |
| component | 自定义渲染元素,可以是标签名或 Vue 组件,默认由 heading 决定(h1 到 h6)。 | string | Component | undefined |
| copyable | 是否可复制;传对象时见 Copyable Config。 | boolean | TypographyCopyableConfig | false |
| delete | 添加删除线样式。 | boolean | false |
| disabled | 禁用文本。 | boolean | false |
| link | 是否为链接;传对象时,其中的属性(href、target、class、style、onClick 等)挂在 a 元素上。 | LinkType | false |
| mark | 添加标记样式。 | boolean | false |
| strong | 是否加粗。 | boolean | false |
| type | 文本类型。 | Type"primary" | "secondary" | "danger" | "warning" | "success" | "tertiary" | "quaternary" | "primary" |
| underline | 添加下划线样式。 | boolean | false |
Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| expand | 点击展开或收起控件时触发,参数为操作之后的展开状态和点击事件。 | [expanded: boolean, e: MouseEvent] |
| copy | 复制后触发,参数为点击事件、复制的内容和是否写入成功;写入被拒绝时为 false,此时不进入已复制状态。 | [e: MouseEvent, content: string, res: boolean] |
Slots
| 插槽 | 说明 | 作用域参数 |
|---|---|---|
| default | 标题内容。 | any |
| copyIcon | 复制按钮的内容;内容为单个节点且带 aria-label 时以它作为按钮的可访问名称,否则用语言包的「复制」。 | any |
| copyTip | 复制图标的提示内容。 | any |
| copySuccessTip | 复制成功后的展示内容。 | any |
| copyAction | 完全自定义复制节点,参数为 copied、copy 和解析后的 config。 | TypographyCopyActionProps |
| ellipsisContent | 截断时浮层中的内容,默认是全文。 | any |
| ellipsisTooltip | 自定义浮层,仅在文本溢出时渲染;参数 content 是全文,trigger 是文字元素,用 <component :is="trigger" /> 放入自己的浮层。 | TypographyEllipsisTooltipProps |
Exposes
| 名称 | 说明 | 类型 |
|---|---|---|
| 无 |
class、style、id、aria-* 等原生属性经 attrs 落在文字元素上。
Typography.Paragraph
Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| ellipsis | 设置自动溢出省略;传对象时见 Ellipsis Config。 | boolean | Ellipsis | false |
| size | 文本大小,inherit 继承外层 Text 或 Paragraph 的尺寸。 | "normal" | "small" | "inherit" | "normal" |
| spacing | 行距,extended 为更宽松的行距。 | "normal" | "extended" | "normal" |
| component | 自定义渲染元素,可以是标签名或 Vue 组件,默认 p。 | string | Component | undefined |
| copyable | 是否可复制;传对象时见 Copyable Config。 | boolean | TypographyCopyableConfig | false |
| delete | 添加删除线样式。 | boolean | false |
| disabled | 禁用文本。 | boolean | false |
| link | 是否为链接;传对象时,其中的属性(href、target、class、style、onClick 等)挂在 a 元素上。 | LinkType | false |
| mark | 添加标记样式。 | boolean | false |
| strong | 是否加粗。 | boolean | false |
| type | 文本类型。 | Type"primary" | "secondary" | "danger" | "warning" | "success" | "tertiary" | "quaternary" | "primary" |
| underline | 添加下划线样式。 | boolean | false |
Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| expand | 点击展开或收起控件时触发,参数为操作之后的展开状态和点击事件。 | [expanded: boolean, e: MouseEvent] |
| copy | 复制后触发,参数为点击事件、复制的内容和是否写入成功;写入被拒绝时为 false,此时不进入已复制状态。 | [e: MouseEvent, content: string, res: boolean] |
Slots
| 插槽 | 说明 | 作用域参数 |
|---|---|---|
| default | 段落内容。 | any |
| copyIcon | 复制按钮的内容;内容为单个节点且带 aria-label 时以它作为按钮的可访问名称,否则用语言包的「复制」。 | any |
| copyTip | 复制图标的提示内容。 | any |
| copySuccessTip | 复制成功后的展示内容。 | any |
| copyAction | 完全自定义复制节点,参数为 copied、copy 和解析后的 config。 | TypographyCopyActionProps |
| ellipsisContent | 截断时浮层中的内容,默认是全文。 | any |
| ellipsisTooltip | 自定义浮层,仅在文本溢出时渲染;参数 content 是全文,trigger 是文字元素,用 <component :is="trigger" /> 放入自己的浮层。 | TypographyEllipsisTooltipProps |
Exposes
| 名称 | 说明 | 类型 |
|---|---|---|
| 无 |
class、style、id、aria-* 等原生属性经 attrs 落在文字元素上。
Typography.Numeral
Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| code | 是否被 code 元素包裹。 | boolean | false |
| parser | 自定义数值解析函数。 | Type((value: string) => string) | undefined |
| precision | 小数点后保留的位数。 | number | 0 |
| rule | 解析规则:text 仅取整,numbers 过滤非数字字符,bytes-decimal、bytes-binary 换算字节单位,percentages 转百分比,exponential 转科学计数法。 | Type"text" | "numbers" | "bytes-decimal" | "bytes-binary" | "percentages" | "exponential" | "text" |
| size | 文本大小,inherit 继承外层 Text 或 Paragraph 的尺寸。 | "normal" | "small" | "inherit" | "normal" |
| truncate | 小数点后保留位的取整方式,对应 Math.round、Math.ceil、Math.floor。 | "round" | "ceil" | "floor" | "round" |
| component | 自定义渲染元素,可以是标签名或 Vue 组件,默认 span;内容含 p 等块级元素时使用 div。 | string | Component | undefined |
| copyable | 是否可复制;传对象时见 Copyable Config。 | boolean | TypographyCopyableConfig | false |
| delete | 添加删除线样式。 | boolean | false |
| disabled | 禁用文本。 | boolean | false |
| link | 是否为链接;传对象时,其中的属性(href、target、class、style、onClick 等)挂在 a 元素上。 | LinkType | false |
| mark | 添加标记样式。 | boolean | false |
| strong | 是否加粗。 | boolean | false |
| type | 文本类型。 | Type"primary" | "secondary" | "danger" | "warning" | "success" | "tertiary" | "quaternary" | "primary" |
| underline | 添加下划线样式。 | boolean | false |
Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| copy | 复制后触发,参数为点击事件、复制的内容和是否写入成功;写入被拒绝时为 false,此时不进入已复制状态。 | [e: MouseEvent, content: string, res: boolean] |
Slots
| 插槽 | 说明 | 作用域参数 |
|---|---|---|
| default | 要格式化的内容;递归处理其中的文本与元素,不处理组件内部的文字。 | any |
| icon | 前缀图标;Semi 图标按 size 自动设为 small 或 default。 | any |
| copyIcon | 复制按钮的内容;内容为单个节点且带 aria-label 时以它作为按钮的可访问名称,否则用语言包的「复制」。 | any |
| copyTip | 复制图标的提示内容。 | any |
| copySuccessTip | 复制成功后的展示内容。 | any |
| copyAction | 完全自定义复制节点,参数为 copied、copy 和解析后的 config。 | TypographyCopyActionProps |
Exposes
| 名称 | 说明 | 类型 |
|---|---|---|
| 无 |
class、style、id、aria-* 等原生属性经 attrs 落在文字元素上。
Ellipsis Config
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| collapseText | 折叠的展示文本 | string | 收起 |
| collapsible | 是否支持折叠 | boolean | false |
| expandText | 展开的展示文本 | string | 展开 |
| expandable | 是否支持展开 | boolean | false |
| pos | 省略截断的位置,支持末尾和中间截断:end, middle | string | end |
| rows | 省略溢出行数 | number | 1 |
| showTooltip | 是否展示 tooltip 及相关配置: type,浮层内容承载的组件,支持 tooltip| popover;opts,其他需要透传给浮层组件的属性,其中 class、style 落在浮层上。浮层内容用 #ellipsisContent 插槽,自定义浮层用 #ellipsisTooltip="{ content, trigger }"(content 是全文,trigger 是文字元素,用 <component :is="trigger" /> 放入自己的浮层,只在溢出时渲染)。Tooltip 可显示时文字可用 Tab 聚焦;文字位于 option、treeitem、menuitem、gridcell、row 等组合控件条目内时不加入 Tab 顺序。expandable 为 true 或设置了 expandText 时,showTooltip 不生效,二者互斥 | boolean|{type?: 'tooltip'|'popover', opts?: object} | false |
| suffix | 始终展示的后缀 | string | - |
展开、收起时触发组件事件 expand(expanded, e),写作 @expand。
Copyable Config
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| content | 复制出的文本 | string | - |
| class | 复制操作外层 span 的类名 | string | object | array | - |
| duration | 已复制状态持续的秒数 | number | 3 |
| style | 复制操作外层 span 的样式 | StyleValue | - |
复制按钮的内容、提示与成功提示用 #copyIcon、#copyTip、#copySuccessTip 插槽;用 #copyAction="{ copied, copy, config }" 自定义复制节点,config 是解析后的 { content, duration, class, style }。复制完成后触发组件事件 copy(e, content, res),写作 @copy:res 为 true 表示写入剪贴板成功,false 表示写入被拒绝,此时不进入已复制状态。
文案规范
- Link
- 文字链接需要清晰且可预测,用户应该能够预测他们点击链接时会发生什么
- 切勿通过错误标记链接来误导用户
- 避免使用“Click here”或“Here”作为独立链接
| ✅ 推荐用法 | ❌ 不推荐用法 |
|---|---|
| No spaces yet? Create space | No spaces yet? Click here |
- 避免将整个句子作为可点击的文字链接,而是将描述具体去向的文字作为链接内容
| ✅ 推荐用法 | ❌ 不推荐用法 |
|---|---|
| Views user documentation for details | View user documentation for details |
- 使用短术语或词作为链接文本会更有利于国际化,以避免由于不同的语言的语法和语序不同,而出现链接文字被拆分的问题
| ✅ 推荐用法 | ❌ 不推荐用法 |
|---|---|
| Manage notifications to | Manage notifications to |
- 以文字链接结尾时,不需要跟随标点符号,除了问号“?”
| ✅ 推荐用法 | ❌ 不推荐用法 |
|---|---|
| No spaces yet? Create space | No spaces yet? Click here |
| Forgot password ? | Forgot password |
- 链接文字不要包含冠词“the, a, an”
| ✅ 推荐用法 | ❌ 不推荐用法 |
|---|---|
| View user documentation for details | View the user documentation for details |
设计变量
| Sass 变量 | 值 | 用法 |
|---|---|---|
| $color-typography_default-text-default | var(--semi-color-text-0) | 默认文本颜色 |
| $color-typography_secondary-text-default | var(--semi-color-text-1) | 稍次要文本颜色 |
| $color-typography_tertiary-text-default | var(--semi-color-text-2) | 次要文本颜色 |
| $color-typography_quaternary-text-default | var(--semi-color-text-3) | 最次要文本颜色 |
| $color-typography_warning-text-default | var(--semi-color-warning) | 警告文本颜色 |
| $color-typography_danger-text-default | var(--semi-color-danger) | 错误文本颜色 |
| $color-typography_success-text-default | var(--semi-color-success) | 成功文本颜色 |
| $color-typography_disabled-text-default | var(--semi-color-disabled-text) | 禁用文本颜色 |
| $color-typography_mark-bg-default | var(--semi-color-primary-light-default) | 标记文本颜色 |
| $color-typography_mark-text-default | var(--semi-color-text-0) | 标记文本文字颜色 |
| $font-typography_code-fontFamily | ui-monospace, sfmono-regular, menlo, consolas, monospace | 代码文本字体 |
| $font-typography_code-fontSize | 1em | 代码文本字号 |
| $color-typography_code-bg-default | var(--semi-color-fill-1) | 代码文本背景颜色 |
| $color-typography_code-text-default | var(--semi-color-text-2) | 代码文本颜色 |
| $color-typography_link-text-default | var(--semi-color-link) | 链接文本颜色 - 默认 |
| $color-typography_link-text-visited | var(--semi-color-link-visited) | 链接文本颜色 - 已访问 |
| $color-typography_link-text-hover | var(--semi-color-link-hover) | 链接文本颜色 - 悬浮 |
| $color-typography_link-text-active | var(--semi-color-link-active) | 链接文本颜色 - 激活 |
| $color-typography_link-text-disabled | var(--semi-color-link) | 链接文本颜色 - 禁用 |
| $color-typography_copied-text-success | var(--semi-color-text-2) | 可复制文本颜色 |
| $color-typography_copied-icon-success | var(--semi-color-success) | 可复制文本复制成功图标颜色 |
| $color-typography_code-border-default | var(--semi-color-border) | 代码文本描边颜色 |
| $font-typography_title-fontWeight | $font-weight-bold | 标题文本字重 |
| $font-typography_link-fontWeight | $font-weight-bold | 链接文本字重 |
| $font-typography_strong-fontWeight | $font-weight-bold | 强调文本字重 |
| $font-typography_paragraph_extended-lineHeight | 24px | 宽松行距段落文本行高 |
| $font-typography_smallText-regular-fontWeight | $font-weight-regular | small text 字重 - 正常 |
| $font-typography_normalParagraph-regular-fontWeight | $font-weight-regular | normal paragraph 字重 - 正常 |
| $font-typography_smallParagraph-regular-fontWeight | $font-weight-regular | small paragraph 字重 - 正常 |
| $font-typography_title1-fontWeight | $font-typography_title-fontWeight | 一级标题文本字重 |
| $font-typography_title2-fontWeight | $font-typography_title-fontWeight | 二级标题文本字重 |
| $font-typography_title3-fontWeight | $font-typography_title-fontWeight | 三级标题文本字重 |
| $font-typography_title4-fontWeight | $font-typography_title-fontWeight | 四级标题文本字重 |
| $font-typography_title5-fontWeight | $font-typography_title-fontWeight | 五级标题文本字重 |
| $font-typography_title6-fontWeight | $font-typography_title-fontWeight | 六级标题文本字重 |
| $font-typography_title1-light-fontWeight | 200 | 一级标题文本字重 - 细 |
| $font-typography_title2-light-fontWeight | 200 | 二级标题文本字重 - 细 |
| $font-typography_title3-light-fontWeight | 200 | 三级标题文本字重 - 细 |
| $font-typography_title4-light-fontWeight | 200 | 四级标题文本字重 - 细 |
| $font-typography_title5-light-fontWeight | 200 | 五级标题文本字重 - 细 |
| $font-typography_title6-light-fontWeight | 200 | 六级标题文本字重 - 细 |
| $font-typography_title1-regular-fontWeight | 400 | 一级标题文本字重 - 正常 |
| $font-typography_title2-regular-fontWeight | 400 | 二级标题文本字重 - 正常 |
| $font-typography_title3-regular-fontWeight | 400 | 三级标题文本字重 - 正常 |
| $font-typography_title4-regular-fontWeight | 400 | 四级标题文本字重 - 正常 |
| $font-typography_title5-regular-fontWeight | 400 | 五级标题文本字重 - 正常 |
| $font-typography_title6-regular-fontWeight | 400 | 六级标题文本字重 - 正常 |
| $font-typography_title1-medium-fontWeight | 500 | 一级标题文本字重 - 中等 |
| $font-typography_title2-medium-fontWeight | 500 | 二级标题文本字重 - 中等 |
| $font-typography_title3-medium-fontWeight | 500 | 三级标题文本字重 - 中等 |
| $font-typography_title4-medium-fontWeight | 500 | 四级标题文本字重 - 中等 |
| $font-typography_title5-medium-fontWeight | 500 | 五级标题文本字重 - 中等 |
| $font-typography_title6-medium-fontWeight | 500 | 六级标题文本字重 - 中等 |
| $font-typography_title1-semibold-fontWeight | 600 | 一级标题文本字重 - 半粗 |
| $font-typography_title2-semibold-fontWeight | 600 | 二级标题文本字重 - 半粗 |
| $font-typography_title3-semibold-fontWeight | 600 | 三级标题文本字重 - 半粗 |
| $font-typography_title4-semibold-fontWeight | 600 | 三级标题文本字重 - 半粗 |
| $font-typography_title5-semibold-fontWeight | 600 | 三级标题文本字重 - 半粗 |
| $font-typography_title6-semibold-fontWeight | 600 | 三级标题文本字重 - 半粗 |
| $font-typography_title1-bold-fontWeight | 700 | 一级标题文本字重 - 粗 |
| $font-typography_title2-bold-fontWeight | 700 | 二级标题文本字重 - 粗 |
| $font-typography_title3-bold-fontWeight | 700 | 三级标题文本字重 - 粗 |
| $font-typography_title4-bold-fontWeight | 700 | 三级标题文本字重 - 粗 |
| $font-typography_title5-bold-fontWeight | 700 | 三级标题文本字重 - 粗 |
| $font-typography_title6-bold-fontWeight | 700 | 三级标题文本字重 - 粗 |
| $spacing-typography_iconPrefix-marginRight | 4px | 带前缀文本图标右侧外边距 |
| $spacing-typography_expandText-marginLeft | 8px | 支持展开文本展开按钮左侧外边距 |
| $spacing-typography_copyIcon-marginLeft | 4px | 可复制文本复制图标左侧外边距 |
| $spacing-typography_copyIcon-padding | 0 | 可复制文本复制图标内边距 |
| $spacing-typography_title_h1-margin | 0 | 一级标题外边距 |
| $spacing-typography_title_h2-margin | 0 | 二级标题外边距 |
| $spacing-typography_title_h3-margin | 0 | 三级标题外边距 |
| $spacing-typography_title_h4-margin | 0 | 四级标题外边距 |
| $spacing-typography_title_h5-margin | 0 | 五级标题外边距 |
| $spacing-typography_title_h6-margin | 0 | 六级标题外边距 |
| $spacing-typography_title_paragraph-margin | 0 | 段落外边距 |
| $width-typography_code-border | 1px | 代码文本描边宽度 |
| $width-typography_link-border | 1px | 链接文本下划线宽度 |
| $radius-typography_code | 2px | 代码文本圆角 |
FAQ
-
Typography 省略具体机制及注意事项?
Semi 截断有两种策略, CSS 截断和 JS 截断。当设置中间截断(pos='middle')、可展开(expandable)、设置了展开文本(expandText 非 undefined)、有后缀(suffix 非空)、可复制(copyable),启用 JS 截断策略;非以上场景,启用 CSS 截断策略。
通常来说,CSS 截断性能优于 JS 截断。在 children、 容器尺寸不变的情况下,CSS 截断只涉及 1~2 次计算,js 截断可能涉及多次计算。
同时使用大量带有截断功能的 Typography 需注意性能消耗,如在 Table 中,可通过设置合理的页容量进行分页减少性能损耗。