When to Use
- To display the text content of articles, blogs, logs, etc.
- To take basic operations such as copying and omitting text.
Demos
How to import
<script lang="ts">
import { TypographyNumeral, TypographyParagraph, TypographyText, TypographyTitle } from '@fibrae/semi-ui-svelte';
</script>
The Svelte package uses the named exports TypographyText, TypographyTitle, TypographyParagraph and TypographyNumeral; the package root also exports Typography.
Title
Use heading to set different levels of headint title.
h1. Semi Design
h2. Semi Design
h3. Semi Design
h4. Semi Design
h5. Semi Design
h6. Semi Design
Code
<script lang="ts">
import { TypographyTitle } from '@fibrae/semi-ui-svelte';
</script>
<div>
<TypographyTitle style="margin: 8px 0">h1. Semi Design</TypographyTitle>
<TypographyTitle heading={2} style="margin: 8px 0">h2. Semi Design</TypographyTitle>
<TypographyTitle heading={3} style="margin: 8px 0">h3. Semi Design</TypographyTitle>
<TypographyTitle heading={4} style="margin: 8px 0">h4. Semi Design</TypographyTitle>
<TypographyTitle heading={5} style="margin: 8px 0">h5. Semi Design</TypographyTitle>
<TypographyTitle heading={6} style="margin: 8px 0">h6. Semi Design</TypographyTitle>
</div>Text
Text component has different built-in styles.
You could also use the icon snippet to use the built-in styles for icon. Different from putting the icon in children, using icon for link will have no underline in compliance with Semi Design Next principles.
Secondary
Tertiary v>=1.2.0
Quaternary v>=1.2.0
Warning
Danger
Success v>=1.7.0
Disabled
Default Mark
Example Code Underline
Strong
Code
<script lang="ts">
import { TypographyText } from '@fibrae/semi-ui-svelte';
</script>
<div>
<TypographyText>Text</TypographyText>
<br />
<br />
<TypographyText type="secondary">Secondary</TypographyText>
<br />
<br />
<TypographyText type="tertiary">Tertiary v>=1.2.0</TypographyText>
<br />
<br />
<TypographyText type="quaternary">Quaternary v>=1.2.0</TypographyText>
<br />
<br />
<TypographyText type="warning">Warning</TypographyText>
<br />
<br />
<TypographyText type="danger">Danger</TypographyText>
<br />
<br />
<TypographyText type="success">Success v>=1.7.0</TypographyText>
<br />
<br />
<TypographyText disabled>Disabled</TypographyText>
<br />
<br />
<TypographyText mark>Default Mark</TypographyText>
<br />
<br />
<TypographyText code>Example Code</TypographyText>
<br />
<br />
<TypographyText underline>Underline</TypographyText>
<br />
<br />
<TypographyText delete>Deleted</TypographyText>
<br />
<br />
<TypographyText strong>Strong</TypographyText>
</div>You could pass object to link, which will be mounted on <a>.
Code
<script lang="ts">
import { IconLink } from '@fibrae/semi-icons-svelte';
import { TypographyText } from '@fibrae/semi-ui-svelte';
</script>
<div>
<TypographyText link={{ href: 'https://semi.design/' }}>链接文本</TypographyText>
<br />
<br />
<TypographyText link={{ href: 'https://semi.design/' }}>打开网站</TypographyText>
<br />
<br />
<TypographyText link underline>
{#snippet icon()}
<IconLink />
{/snippet}
带下划线的网页链接
</TypographyText>
</div>Paragraph
Paragraph component has two spacings. You could setspacing='extended' for a looser spacing.
默认行距
Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
宽松行距
Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
Code
<script lang="ts">
import { TypographyParagraph, TypographyTitle } from '@fibrae/semi-ui-svelte';
</script>
<div>
<TypographyTitle heading={5}>默认行距</TypographyTitle>
<TypographyParagraph>Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。</TypographyParagraph>
<br />
<TypographyTitle heading={5}>宽松行距</TypographyTitle>
<TypographyParagraph spacing="extended">Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。</TypographyParagraph>
</div>Numeral
Based on Text component, added properties: rule, precision, truncate, parser, to provide the ability to handle Numeral in text separately.
precision allows you to set the number of decimal places to be retained, used to set precision
truncate The truncation of the number of decimal places, optionally ceil, floor, round, aligned with Math.ceil, Math.floor, Math.round
rule for setting the parsing rules
- set to
percentagesto automatically convert numbers to percentages - set to
bytes-decimalto automatically convert numbers to bytes, 1 KB is defined as 1000 bytes, (B, KB, MB, GB, TB, PB, EB, ZB, YB) - Set to
bytes-binaryautomatically converts the number to the unit of display corresponding to bytes, 1 KiB is defined as equal to 1024 bytes, (B, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB) - When set to
text, Automatic rounding of numbers only, based on theprecisionandtruncateattributes - When set to
numbers, non-numeric characters will be filtered and only numbers will be displayed - When set to
exponential, numbers are automatically converted to scientific notation
Numeral renders a span by default. When the content has block elements such as p, use component="div" to render a block container.
点赞量:1.6111e1 K
播放量:2.4444e2K
好评率: 0.915
已使用: 1000
未使用: 1024000
已使用: 1024
未使用: 2000000000000
Code
<script lang="ts">
import { TypographyNumeral } from '@fibrae/semi-ui-svelte';
</script>
<div>
<TypographyNumeral component="div" precision={1}>
<p>点赞量:1.6111e1 K</p>
</TypographyNumeral>
<p>播放量:<TypographyNumeral precision={1} rule="numbers">2.4444e2</TypographyNumeral>K</p>
<TypographyNumeral component="div" precision={2} rule="percentages" style="margin-bottom: 12px">
<p>好评率: 0.915</p>
</TypographyNumeral>
<TypographyNumeral rule="percentages" style="margin-bottom: 12px">这场比赛我的胜率是0.6,输的概率是0.4</TypographyNumeral>
<TypographyNumeral component="div" precision={2} rule="bytes-decimal" truncate="floor">
<p>已使用: 1000</p>
<p>未使用: {1024 * 1000}</p>
</TypographyNumeral>
<TypographyNumeral component="div" precision={2} rule="bytes-binary" truncate="floor">
<p>已使用: 1024</p>
<p>未使用: {2e12}</p>
</TypographyNumeral>
</div>Parsing rules can be customised via parser.
Stars:7100
Fork:560
Downloads:5000000
Contributors:100
现已服务 100000 用户,前往官网 >>
Code
<script lang="ts">
import { TypographyNumeral } from '@fibrae/semi-ui-svelte';
const 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>
<div>
<TypographyNumeral component="div" parser={parserTCH}>
Semi Design 重视我们的用户,加入并助力我们不断完善
{#each infos as item (item.min)}
<p>
{item.type}:<b style="color: var(--semi-violet-5)">{item.min}</b>
</p>
{/each}
</TypographyNumeral>
<br />
<TypographyNumeral link={{ href: 'https://semi.design', target: '_blank' }} parser={parserTCH}>现已服务 {1e5} 用户,前往官网 >></TypographyNumeral>
</div>Size
Paragraph and Text component support two sizes, small(12px) and normal(14px), and inherit to take the outer size. By default it is set to normal.
When the paragraph component or text component are used nested, set the size property of the inner component to inherit, and the size of the inner component will inherit the size setting of the outer component.
Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
小文本
Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
这是一段文本,样式为 small 这是一段链接,设置 size 为 inherit 继承外部样式设置
Code
<script lang="ts">
import { TypographyParagraph, TypographyText } from '@fibrae/semi-ui-svelte';
</script>
<div>
<TypographyText>正常文本</TypographyText>
<TypographyParagraph spacing="extended">Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。</TypographyParagraph>
<br />
<TypographyText size="small">小文本</TypographyText>
<TypographyParagraph size="small">Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。</TypographyParagraph>
<br />
<TypographyText size="small">
这是一段文本,样式为 small
<TypographyText link size="inherit">这是一段链接,设置 size 为 inherit 继承外部样式设置</TypographyText>
</TypographyText>
</div>Copyable text
Copying of text can be supported by configuring the copyable property.
When copyable is configured as true, the default copied content is children itself. Note that at this time, children only support string type.
When copyable is configured as object, you can specify the content copied to the clipboard through copyable.content, which is no longer strongly associated with children.
At this time, children will no longer limit the type, but copyable.content still needs to be a string.
Use the copyIcon snippet for the content of the copy button, copyTip for its tooltip and copySuccessTip for the success tip; the copyAction snippet (argument { copied, copy, config }) replaces the whole copy node, and copy takes the click event. The copy callback goes in the config object: copyable={{ onCopy }}.
点击右边的图标复制文本。
点击复制文本。
点击右边的图标复制文本。
时间戳: 1700000000s自定义复制节点
自定义复制渲染
粘贴区域:
Code
<script lang="ts">
import { IconSetting } from '@fibrae/semi-icons-svelte';
import { Button, TextArea, Toast, TypographyNumeral, TypographyParagraph, TypographyText } from '@fibrae/semi-ui-svelte';
// fixed so the server render and the browser agree
const timestamp = 1700000000;
</script>
<div>
<TypographyParagraph copyable>点击右边的图标复制文本。</TypographyParagraph>
<TypographyParagraph copyable={{ content: 'Hello, Semi Design!' }}>点击复制文本。</TypographyParagraph>
<TypographyParagraph copyable={{ onCopy: () => Toast.success({ content: '复制文本成功' }) }}>点击右边的图标复制文本。</TypographyParagraph>
时间戳:
<TypographyNumeral copyable truncate="ceil" underline>{timestamp}s</TypographyNumeral>
<TypographyParagraph copyable>
{#snippet copyIcon()}
<IconSetting style="color: var(--semi-color-link)" />
{/snippet}
自定义复制节点
</TypographyParagraph>
<TypographyParagraph copyable={{ content: 'Custom render!' }}>
{#snippet copyAction({ copied, copy, config })}
<Button size="small" onclick={copy}>
<span>{copied ? '复制成功' : `点击复制:${config.content}`}</span>
</Button>
{/snippet}
自定义复制渲染
</TypographyParagraph>
<br />
<br />
<TypographyText id="typography-copyable-paste" type="secondary">粘贴区域:</TypographyText>
<br />
<TextArea aria-labelledby="typography-copyable-paste" autosize rows={3} style="width: 320px; margin-top: 4px" />
</div>Ellipsis
Show ellipsis if text is overflowed. Refer to Ellipsis Config for detailed configuration.
是一个很长很长很长很长5号标题
可以自定义浮层里的展示内容试试看吧
是一个很长很长很长很长的链接
有后缀的情况:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。小尾巴
这是一个多行截断的例子:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
多行截断,展示 Popover:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
支持展开和折叠:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
sssssssssssssssssssssssss
这是一个自定义弹出层组件的省略文本,背景色是蓝色
Code
<script lang="ts">
import { Tooltip, TypographyParagraph, TypographyText, TypographyTitle } from '@fibrae/semi-ui-svelte';
</script>
<div>
<TypographyTitle ellipsis={{ showTooltip: true }} heading={5} style="width: 250px">是一个很长很长很长很长5号标题</TypographyTitle>
<br />
<TypographyText ellipsis={{ showTooltip: true }} style="width: 150px">
{#snippet ellipsisContent()}这是自定义要展示的内容{/snippet}
可以自定义浮层里的展示内容试试看吧
</TypographyText>
<br />
<TypographyText ellipsis={{ showTooltip: true, pos: 'middle' }} link style="width: 150px">是一个很长很长很长很长的链接</TypographyText>
<br />
<TypographyParagraph ellipsis={{ suffix: '小尾巴' }} style="width: 300px">有后缀的情况:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。</TypographyParagraph>
<br />
<TypographyParagraph ellipsis={{ rows: 3 }} style="width: 300px">这是一个多行截断的例子:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。</TypographyParagraph>
<br />
<TypographyParagraph ellipsis={{ rows: 3, showTooltip: { type: 'popover', opts: { style: 'width: 300px' } } }} style="width: 300px">
多行截断,展示 Popover:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
</TypographyParagraph>
<br />
<TypographyParagraph ellipsis={{ rows: 3, expandable: true, collapsible: true, collapseText: '折叠我吧', onExpand: (expanded, event) => console.log(expanded, event) }} style="width: 300px">
支持展开和折叠:Semi Design 是由抖音前端团队与 UED 团队共同设计开发并维护的设计系统。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
</TypographyParagraph>
<br />
<TypographyText ellipsis={{ showTooltip: true, pos: 'middle' }} style="width: 150px; word-break: break-word">
{#snippet ellipsisContent()}全英文设置了word-break{/snippet}
sssssssssssssssssssssssss
</TypographyText>
<br />
<br />
<TypographyTitle ellipsis={{ showTooltip: true }} heading={5} style="width: 250px">
{#snippet ellipsisTooltip({ content: fullText, trigger })}
<Tooltip style="background-color: var(--semi-color-primary)">
{@render trigger()}
{#snippet content()}{fullText}{/snippet}
</Tooltip>
{/snippet}
这是一个自定义弹出层组件的省略文本,背景色是蓝色
</TypographyTitle>
</div>覆盖类名超长文本发生截断时可使用类名覆盖进行自定义配置
覆盖style超长文本发生截断时可使用style进行自定义配置
Code
<script lang="ts">
import { TypographyText } from '@fibrae/semi-ui-svelte';
</script>
<div>
<TypographyText ellipsis={{ showTooltip: true }} style="width: 150px">
{#snippet ellipsisContent()}架构|Semi-inf|graph.cheet.relation{/snippet}
有问题的超长文本发生截断时可按需进行自定义配置
</TypographyText>
<br />
<TypographyText ellipsis={{ showTooltip: { opts: { class: 'components-typography-demo' } } }} style="width: 150px">
{#snippet ellipsisContent()}架构|Semi-inf|graph.cheet.relation{/snippet}
覆盖类名超长文本发生截断时可使用类名覆盖进行自定义配置
</TypographyText>
<br />
<TypographyText ellipsis={{ showTooltip: { opts: { style: 'word-break: break-all' } } }} style="width: 150px">
{#snippet ellipsisContent()}架构|Semi-inf|graph.cheet.relation{/snippet}
覆盖style超长文本发生截断时可使用style进行自定义配置
</TypographyText>
</div>// config word-break
.components-typography-demo {
word-break: break-word;
// or
word-break: break-all;
}
API Reference
Typography.Text
Props
| Property | Description | Type | Default |
|---|---|---|---|
| code | Whether the text is wrapped in a code element. | boolean | - |
| component | Tag name of the element to render. Defaults to span. | string | 'span' |
| copyable | Whether the text can be copied; pass an object for the Copyable Config. | TypographyCopyableConfig | boolean | - |
| copyAction | Snippet that replaces the whole copy node, with the argument { copied, copy, config }; copy takes the click event. | TypeSnippet<[TypographyCopyActionProps]> | - |
| copyIcon | Snippet for the content of the copy button; a single node with an aria-label names the button, otherwise the locale's "Copy" does. | Snippet | - |
| copySuccessTip | Snippet for the content shown after a successful copy. | Snippet | - |
| copyTip | Snippet for the tooltip content of the copy button. | Snippet | - |
| delete | Adds a strikethrough. | boolean | - |
| disabled | Disables the text. | boolean | - |
| ellipsis | Truncates overflowing text; pass an object for the Ellipsis Config. | Ellipsis | boolean | - |
| ellipsisContent | Snippet for the content of the floating layer when truncated; defaults to the full text. | Snippet | - |
| ellipsisTooltip | Snippet for a custom floating layer, rendered only when the text overflows; its argument is { content, trigger }, where content is the full text and trigger is a snippet of the text element, to be placed in your own layer with {@render trigger()}. | TypeSnippet<[TypographyEllipsisTooltipProps]> | - |
| icon | Snippet for the prefix icon; a Semi icon is set to small or default according to size. | Snippet | - |
| link | Whether the text is a link; with an object, its attributes (href, target, class, style, onclick and so on) are applied to the a element. | LinkType | - |
| mark | Adds a highlight. | boolean | - |
| size | Text size; inherit takes the size of the enclosing Text or Paragraph. | TypographyBaseSize | - |
| strong | Whether the text is bold. | boolean | - |
| type | Text type. | TypographyBaseType | - |
| underline | Adds an underline. | boolean | - |
| weight | Font weight as a number. | number | - |
The content inside the tag is children (a snippet). class, style, id, aria-* and other native attributes and events land on the text element.
Typography.Title
Props
| Property | Description | Type | Default |
|---|---|---|---|
| component | Tag name of the element to render. Defaults to h1 to h6 by heading. | string | - |
| copyable | Whether the text can be copied; pass an object for the Copyable Config. | TypographyCopyableConfig | boolean | - |
| copyAction | Snippet that replaces the whole copy node, with the argument { copied, copy, config }; copy takes the click event. | TypeSnippet<[TypographyCopyActionProps]> | - |
| copyIcon | Snippet for the content of the copy button; a single node with an aria-label names the button, otherwise the locale's "Copy" does. | Snippet | - |
| copySuccessTip | Snippet for the content shown after a successful copy. | Snippet | - |
| copyTip | Snippet for the tooltip content of the copy button. | Snippet | - |
| delete | Adds a strikethrough. | boolean | - |
| disabled | Disables the text. | boolean | - |
| ellipsis | Truncates overflowing text; pass an object for the Ellipsis Config. | Ellipsis | boolean | - |
| ellipsisContent | Snippet for the content of the floating layer when truncated; defaults to the full text. | Snippet | - |
| ellipsisTooltip | Snippet for a custom floating layer, rendered only when the text overflows; its argument is { content, trigger }, where content is the full text and trigger is a snippet of the text element, to be placed in your own layer with {@render trigger()}. | TypeSnippet<[TypographyEllipsisTooltipProps]> | - |
| heading | Heading level, matching h1 to h6. | 1 | 2 | 3 | 4 | 5 | 6 | 1 |
| link | Whether the text is a link; with an object, its attributes (href, target, class, style, onclick and so on) are applied to the a element. | LinkType | - |
| mark | Adds a highlight. | boolean | - |
| strong | Whether the text is bold. | boolean | - |
| type | Text type. | TypographyBaseType | - |
| underline | Adds an underline. | boolean | - |
| weight | Font weight: light, regular, medium, semibold, bold, default, or a number. | Type'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'default' | number | - |
The content inside the tag is children (a snippet). class, style, id, aria-* and other native attributes and events land on the heading element.
Typography.Paragraph
Props
| Property | Description | Type | Default |
|---|---|---|---|
| component | Tag name of the element to render. Defaults to p. | string | 'p' |
| copyable | Whether the text can be copied; pass an object for the Copyable Config. | TypographyCopyableConfig | boolean | - |
| copyAction | Snippet that replaces the whole copy node, with the argument { copied, copy, config }; copy takes the click event. | TypeSnippet<[TypographyCopyActionProps]> | - |
| copyIcon | Snippet for the content of the copy button; a single node with an aria-label names the button, otherwise the locale's "Copy" does. | Snippet | - |
| copySuccessTip | Snippet for the content shown after a successful copy. | Snippet | - |
| copyTip | Snippet for the tooltip content of the copy button. | Snippet | - |
| delete | Adds a strikethrough. | boolean | - |
| disabled | Disables the text. | boolean | - |
| ellipsis | Truncates overflowing text; pass an object for the Ellipsis Config. | Ellipsis | boolean | - |
| ellipsisContent | Snippet for the content of the floating layer when truncated; defaults to the full text. | Snippet | - |
| ellipsisTooltip | Snippet for a custom floating layer, rendered only when the text overflows; its argument is { content, trigger }, where content is the full text and trigger is a snippet of the text element, to be placed in your own layer with {@render trigger()}. | TypeSnippet<[TypographyEllipsisTooltipProps]> | - |
| link | Whether the text is a link; with an object, its attributes (href, target, class, style, onclick and so on) are applied to the a element. | LinkType | - |
| mark | Adds a highlight. | boolean | - |
| size | Text size; inherit takes the size of the enclosing Text or Paragraph. | TypographyBaseSize | - |
| spacing | Line spacing; extended is looser. | TypographyBaseSpacing | - |
| strong | Whether the text is bold. | boolean | - |
| type | Text type. | TypographyBaseType | - |
| underline | Adds an underline. | boolean | - |
The content inside the tag is children (a snippet). class, style, id, aria-* and other native attributes and events land on the paragraph element.
Typography.Numeral
Props
| Property | Description | Type | Default |
|---|---|---|---|
| code | Whether the text is wrapped in a code element. | boolean | - |
| component | Tag name of the element to render. Defaults to span; use div when the content has block elements such as p. | string | 'span' |
| copyable | Whether the text can be copied; pass an object for the Copyable Config. | TypographyCopyableConfig | boolean | - |
| copyAction | Snippet that replaces the whole copy node, with the argument { copied, copy, config }; copy takes the click event. | TypeSnippet<[TypographyCopyActionProps]> | - |
| copyIcon | Snippet for the content of the copy button; a single node with an aria-label names the button, otherwise the locale's "Copy" does. | Snippet | - |
| copySuccessTip | Snippet for the content shown after a successful copy. | Snippet | - |
| copyTip | Snippet for the tooltip content of the copy button. | Snippet | - |
| delete | Adds a strikethrough. | boolean | - |
| disabled | Disables the text. | boolean | - |
| icon | Snippet for the prefix icon; a Semi icon is set to small or default according to size. | Snippet | - |
| link | Whether the text is a link; with an object, its attributes (href, target, class, style, onclick and so on) are applied to the a element. | LinkType | - |
| mark | Adds a highlight. | boolean | - |
| parser | Custom number parser. | Type(value: string) => string | - |
| precision | Number of decimal places to keep. | number | 0 |
| rule | Parsing rule: text only rounds, numbers filters out non-numeric characters, bytes-decimal and bytes-binary convert byte units, percentages converts to percent, exponential converts to scientific notation. | TypographyBaseRule | "text" |
| size | Text size; inherit takes the size of the enclosing Text or Paragraph. | TypographyBaseSize | - |
| strong | Whether the text is bold. | boolean | - |
| truncate | How the kept decimals are rounded, matching Math.round, Math.ceil and Math.floor. | TypographyBaseTruncate | "round" |
| type | Text type. | TypographyBaseType | - |
| underline | Adds an underline. | boolean | - |
The content inside the tag is children (a snippet); text and elements in it are processed recursively, text inside components is not. class, style, id, aria-* and other native attributes and events land on the text element.
Ellipsis Config
| Properties | Instructions | type | Default |
|---|---|---|---|
| collapseText | Displayed text to collapse | string | Collapse |
| collapsible | Toggle whether text is collapsible | boolean | false |
| expandText | Displayed text to expand | string | Expand |
| expandable | Toggle whether text is expandable | boolean | false |
| onExpand | Callback when expand or collapse, with the expanded state after the action and the click event | (expanded: boolean, event: MouseEvent) => void | - |
| pos | Position to start ellipsis, one of end, middle | 'end' | 'middle' | end |
| rows | Number of rows that should not be truncated | number | 1 |
| showTooltip | Toggle whether to show tooltip, if passed in as object: type, type of component to show tooltip, one of tooltip, popover; opts, props passed through to the floating layer, where class lands on the layer and style is a string. The layer content comes from the ellipsisContent snippet, and a custom layer from the ellipsisTooltip snippet. When expandable is true or expandText is set, showTooltip does not take effect; the two are mutually exclusive | boolean | { type?: 'tooltip' | 'popover', opts?: object } | false |
| suffix | Text suffix that will not be truncated | string | - |
Copyable Config
| Properties | Instructions | Type | Default |
|---|---|---|---|
| content | Copied content | string | - |
| class | Class name of the copy action's wrapping span | ClassValue | - |
| duration | Seconds the copied state lasts | number | 3 |
| onCopy | Copy callback, with the click event, the copied content and whether the write succeeded; false means the write was rejected and the copied state is not entered | (event: MouseEvent, content: string, success: boolean) => void | - |
| style | Style string of the copy action's wrapping span | string | - |
Use the copyIcon, copyTip and copySuccessTip snippets for the content of the copy button, its tooltip and the success tip; the copyAction snippet (argument { copied, copy, config }) replaces the whole copy node, and config is the resolved config.
Content Guidelines
- Link
- Text links need to be clear and predictable, users should be able to predict what will happen when they click on the link
- Do not mislead users by mislabeling links
- Avoid using "Click here" or "Here" as stand-alone links
| ✅ Recommended usage | ❌ Deprecated usage |
|---|---|
| No spaces yet? Create space | No spaces yet? Click here |
- Avoid using entire sentences as clickable text links, and instead use text that describes where to go as the link content
| ✅ Recommended usage | ❌ Deprecated usage |
|---|---|
| Views user documentation for details | View user documentation for details |
- Using short terms or words as link text is more conducive to internationalization, to avoid the problem of link text being split due to different grammar and word order in different languages
| ✅ Recommended usage | ❌ Deprecated usage |
|---|---|
| Manage notifications to | Manage notifications to |
- When ending with a text link, there is no need to follow punctuation, except for the question mark "?"
| ✅ Recommended usage | ❌ Deprecated usage |
|---|---|
| No spaces yet? Create space | No spaces yet? Click here |
| Forgot password ? | Forgot password |
- Link text does not contain the articles "the, a, an"
| ✅ Recommended usage | ❌ Deprecated usage |
|---|---|
| View user documentation for details | View the user documentation for details |
Design Tokens
| Sass variable | Value | Usage |
|---|---|---|
| $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
-
What are the specific mechanism and precautions of Typography ellipsis?
Semi ellipsis has two strategies, CSS ellipsis and JS ellipsis. When setting middle truncation (pos='middle')、 expandable、 expandText is set (not undefined)、 suffix is not empty string、copyable, the JS ellipsis strategy is enabled. Otherwise, enable the CSS ellipsis strategy.
In general CSS truncation performance is better than JS truncation. when the children and container size remain unchanged, CSS truncation only involves 1~2 calculations, while js truncation is based on dichotomy and may require multiple calculations.
Pay attention to performance consumption when using a large number of Typography with ellipsis. For example, in Table, you can reduce performance loss by setting a reasonable pageSize for paging.