TypographyТекст
Текст для статей и интерфейсов: заголовки, абзацы, строчный текст и ссылки с оформлением, копированием, правкой на месте и обрезкой длинного текста.
Когда использовать
- Используйте для читаемого текста единого вида: статьи, заметки, блог.
copyableиeditableподходят для коротких значений, которые копируют или меняют: идентификаторов, имён.ellipsis— там, где мало места; оставляйте способ прочитать весь текст: подсказку илиexpandable.
Примеры
A design system
Many projects need the same design rules and the same parts. A design system keeps them in one place, so the work does not start again in every application.
How to start
Run
npm install svelte-ant-design and press Enter. Decide first, then build. The API table lists
every property.
<script lang="ts">
import { Typography, TypographyLink, TypographyParagraph, TypographyText, TypographyTitle } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<Typography>
<TypographyTitle level={3}>A design system</TypographyTitle>
<TypographyParagraph>
Many projects need the same design rules and the same parts. A design system keeps them in one place, so the work does not
<TypographyText strong>start again</TypographyText> in every application.
</TypographyParagraph>
<TypographyTitle level={4}>How to start</TypographyTitle>
<TypographyParagraph>
Run <TypographyText code>npm install svelte-ant-design</TypographyText> and press <TypographyText keyboard>Enter</TypographyText>.
</TypographyParagraph>
<TypographyParagraph>
<TypographyText mark>Decide first</TypographyText>, then build. The <TypographyLink href="#api">API table</TypographyLink> lists
every property.
</TypographyParagraph>
</Typography>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
width: 100%;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
</style>
Release notes
Read the table of properties before you start.
- Run
npm installand press Enter - Decide first, then build
Consistency is a feature that every page gets for free.
npm install svelte-ant-design
<script lang="ts">
import { Typography } from 'svelte-ant-design';
// HTML that comes ready, here a constant. From Markdown or a CMS, pass only what you trust or have sanitized.
const ready = `
<h4>Release notes</h4>
<p>Read the <a href="#api">table of properties</a> before you start.</p>
<ul>
<li>Run <code>npm install</code> and press <kbd>Enter</kbd></li>
<li><mark>Decide first</mark>, then <strong>build</strong></li>
</ul>
<blockquote>Consistency is a feature that every page gets for free.</blockquote>
<pre>npm install svelte-ant-design</pre>
`;
</script>
<div class="stack">
<div class="field">
<Typography>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html ready}
</Typography>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
width: 100%;
}
/* The article takes the whole width, so a block such as `pre` is as wide as in a real page. */
.field {
display: grid;
justify-items: stretch;
gap: 8px;
width: 100%;
}
</style>
level 2 to 5 (level 1 is the default and is the h1 of a page)
h2. Ant Design
h3. Ant Design
h4. Ant Design
h5. Ant Design
<script lang="ts">
import { TypographyTitle } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">level 2 to 5 (level 1 is the default and is the h1 of a page)</span>
<div class="titles">
<TypographyTitle level={2}>h2. Ant Design</TypographyTitle>
<TypographyTitle level={3}>h3. Ant Design</TypographyTitle>
<TypographyTitle level={4}>h4. Ant Design</TypographyTitle>
<TypographyTitle level={5}>h5. Ant Design</TypographyTitle>
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
type Ant Design (default) Ant Design (secondary) Ant Design (success) Ant Design (warning) Ant Design (danger) Ant Design (disabled)
decorations Ant Design (mark) Ant Design (delete) Ant Design (strong) Ant Design (italic)
Ant Design (code) Ant Design (keyboard) Ant Design (underline) combined
Not for production<script lang="ts">
import { TypographyText } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">type</span>
<TypographyText>Ant Design (default)</TypographyText>
<TypographyText type="secondary">Ant Design (secondary)</TypographyText>
<TypographyText type="success">Ant Design (success)</TypographyText>
<TypographyText type="warning">Ant Design (warning)</TypographyText>
<TypographyText type="danger">Ant Design (danger)</TypographyText>
<TypographyText disabled>Ant Design (disabled)</TypographyText>
</div>
<div class="field">
<span class="caption">decorations</span>
<TypographyText mark>Ant Design (mark)</TypographyText>
<TypographyText code>Ant Design (code)</TypographyText>
<TypographyText keyboard>Ant Design (keyboard)</TypographyText>
<TypographyText underline>Ant Design (underline)</TypographyText>
<TypographyText delete>Ant Design (delete)</TypographyText>
<TypographyText strong>Ant Design (strong)</TypographyText>
<TypographyText italic>Ant Design (italic)</TypographyText>
</div>
<div class="field">
<span class="caption">combined</span>
<TypographyText strong code type="danger">Not for production</TypographyText>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
href, target svelte.dev
type A dangerous link
disabled (the copy button still works) Not available
a plain <a> inside a part
Read the table of properties first.
<script lang="ts">
import { TypographyLink, TypographyParagraph } from 'svelte-ant-design';
let clicks = $state(0);
</script>
<div class="stack">
<div class="field">
<span class="caption">href, target</span>
<TypographyLink href="https://svelte.dev" target="_blank">svelte.dev</TypographyLink>
</div>
<div class="field">
<span class="caption">type</span>
<TypographyLink href="#api" type="danger">A dangerous link</TypographyLink>
</div>
<div class="field">
<span class="caption">disabled (the copy button still works)</span>
<TypographyLink href="#api" disabled copyable>Not available</TypographyLink>
</div>
<div class="field">
<span class="caption">a plain <a> inside a part</span>
<TypographyParagraph>Read the <a href="#api">table of properties</a> first.</TypographyParagraph>
</div>
<div class="field">
<span class="caption">onclick</span>
<TypographyLink href="#api" onclick={() => (clicks += 1)}>Count the clicks</TypographyLink>
<span role="status">Clicked {clicks} times</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
copyable
This is a copyable text.
Nothing copied yettext: the copy is not the shown text
Copy something else.
text: a function that returns a promise
Ask the server for the text.
Not requested yeticon, tooltips
Own icon and tips.
tooltips: false
No tip, the button keeps its name.
a Text with only the button
<script lang="ts">
import { TypographyParagraph, TypographyText } from 'svelte-ant-design';
import { SmileFilled, SmileOutlined } from 'svelte-ant-design/icons';
let copied = $state('Nothing copied yet');
let requested = $state('Not requested yet');
async function fetchText(): Promise<string> {
await new Promise((resolve) => setTimeout(resolve, 1000));
requested = 'The text was requested';
return 'Text from the server';
}
</script>
<div class="stack">
<div class="field">
<span class="caption">copyable</span>
<TypographyParagraph copyable={{ oncopy: () => (copied = 'The sentence was copied') }}>This is a copyable text.</TypographyParagraph>
<span role="status">{copied}</span>
</div>
<div class="field">
<span class="caption">text: the copy is not the shown text</span>
<TypographyParagraph copyable={{ text: 'Hello, clipboard!' }}>Copy something else.</TypographyParagraph>
</div>
<div class="field">
<span class="caption">text: a function that returns a promise</span>
<TypographyParagraph copyable={{ text: fetchText }}>Ask the server for the text.</TypographyParagraph>
<span role="status">{requested}</span>
</div>
<div class="field">
<span class="caption">icon, tooltips</span>
<TypographyParagraph copyable={{ icon, tooltips: ['Copy the greeting', 'Done'] }}>Own icon and tips.</TypographyParagraph>
</div>
<div class="field">
<span class="caption">tooltips: false</span>
<TypographyParagraph copyable={{ tooltips: false }}>No tip, the button keeps its name.</TypographyParagraph>
</div>
<div class="field">
<span class="caption">a Text with only the button</span>
<TypographyText copyable={{ text: 'icon only' }} content="" />
</div>
{#snippet icon(done: boolean)}
{#if done}<SmileFilled label="" />{:else}<SmileOutlined label="" />{/if}
{/snippet}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
bind:content, with the events
This is an editable text.
No events yeticon, tooltip
Custom icon and tip.
triggerType: ['icon', 'text']
Click the text or the icon.
maxLength, autoSize, no enter mark
No more than 20 chars
bind:editing
reading
Open me from outside.
<script lang="ts">
import { Button, TypographyParagraph, TypographyText } from 'svelte-ant-design';
import { HighlightOutlined } from 'svelte-ant-design/icons';
let plain = $state('This is an editable text.');
let custom = $state('Custom icon and tip.');
let byText = $state('Click the text or the icon.');
let limited = $state('No more than 20 chars');
let held = $state('Open me from outside.');
let holding = $state(false);
let events = $state('No events yet');
</script>
<div class="stack">
<div class="field">
<span class="caption">bind:content, with the events</span>
<TypographyParagraph
bind:content={plain}
editable={{
onstart: () => (events = 'started'),
onchange: (text) => (events = `changed to "${text}"`),
onend: () => (events += ', ended'),
oncancel: () => (events = 'cancelled')
}}
/>
<span role="status">{events}</span>
</div>
<div class="field">
<span class="caption">icon, tooltip</span>
<TypographyParagraph bind:content={custom} editable={{ icon: pencil, tooltip: 'Click to edit' }} />
</div>
<div class="field">
<span class="caption">triggerType: ['icon', 'text']</span>
<TypographyParagraph bind:content={byText} editable={{ triggerType: ['icon', 'text'] }} />
</div>
<div class="field">
<span class="caption">maxLength, autoSize, no enter mark</span>
<TypographyParagraph
bind:content={limited}
editable={{ maxLength: 20, autoSize: { maxRows: 3 }, enterIcon: null }}
/>
</div>
<div class="field">
<span class="caption">bind:editing</span>
<div class="row">
<Button onclick={() => (holding = true)}>Edit the sentence</Button>
<TypographyText type="secondary">{holding ? 'editing' : 'reading'}</TypographyText>
</div>
<TypographyParagraph bind:content={held} bind:editing={holding} editable={{ triggerType: [] }} />
</div>
{#snippet pencil()}<HighlightOutlined label="" />{/snippet}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
one row, with a tooltip
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
rows=3
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
onellipsis
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
The text is shown wholea Text in a narrow box
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
<script lang="ts">
import { TypographyParagraph, TypographyText } from 'svelte-ant-design';
const long =
'Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.';
let cut = $state(false);
</script>
<div class="stack">
<div class="field">
<span class="caption">one row, with a tooltip</span>
<TypographyParagraph ellipsis={{ tooltip: true }}>{long}</TypographyParagraph>
</div>
<div class="field">
<span class="caption">rows={3}</span>
<TypographyParagraph ellipsis={{ rows: 3 }}>{long}</TypographyParagraph>
</div>
<div class="field">
<span class="caption">onellipsis</span>
<TypographyParagraph ellipsis={{ rows: 2, onellipsis: (value) => (cut = value) }}>{long}</TypographyParagraph>
<span role="status">The text is {cut ? 'cut' : 'shown whole'}</span>
</div>
<div class="field">
<span class="caption">a Text in a narrow box</span>
<div class="narrow">
<TypographyText ellipsis={{ tooltip: true }}>{long}</TypographyText>
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.narrow {
width: 200px;
max-width: 100%;
}
</style>
expandable
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
expandable: 'collapsible', onexpand
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
Nothing pressed yetsymbol as a snippet
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
<script lang="ts">
import { TypographyParagraph } from 'svelte-ant-design';
const long =
'Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.';
let note = $state('Nothing pressed yet');
</script>
<div class="stack">
<div class="field">
<span class="caption">expandable</span>
<TypographyParagraph ellipsis={{ rows: 2, expandable: true, symbol: 'more' }}>{long}</TypographyParagraph>
</div>
<div class="field">
<span class="caption">expandable: 'collapsible', onexpand</span>
<TypographyParagraph
ellipsis={{
rows: 2,
expandable: 'collapsible',
onexpand: (_event, { expanded }) => (note = expanded ? 'Expanded' : 'Collapsed')
}}
>
{long}
</TypographyParagraph>
<span role="status">{note}</span>
</div>
<div class="field">
<span class="caption">symbol as a snippet</span>
<TypographyParagraph ellipsis={{ rows: 2, expandable: 'collapsible', symbol }}>{long}</TypographyParagraph>
</div>
{#snippet symbol(expanded: boolean)}{expanded ? 'Show less' : 'Read on'}{/snippet}
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
bind:expanded
cut
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
rows, with a slider
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
<script lang="ts">
import { Switch, TypographyParagraph } from 'svelte-ant-design';
const long =
'Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers. Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.';
let open = $state(false);
let rows = $state(2);
</script>
<div class="stack">
<div class="field">
<span class="caption">bind:expanded</span>
<div class="row">
<Switch bind:checked={open} aria-label="Show the whole text" />
<span>{open ? 'expanded' : 'cut'}</span>
</div>
<TypographyParagraph bind:expanded={open} ellipsis={{ rows: 2, expandable: 'collapsible' }}>{long}</TypographyParagraph>
</div>
<div class="field">
<span class="caption">rows, with a slider</span>
<label class="row">
Rows: {rows}
<input type="range" min="1" max="6" bind:value={rows} />
</label>
<TypographyParagraph ellipsis={{ rows, expandable: true }}>{long}</TypographyParagraph>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
suffix, rows and expandable
To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more. To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more. To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more. To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more. To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more. To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more.
suffix with a text that fits
To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more.To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more.
<script lang="ts">
import { TypographyParagraph } from 'svelte-ant-design';
const quote =
'To be, or not to be, that is the question: whether it is nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and by opposing end them. To die, to sleep; no more.';
// Long enough to be cut at any width.
const speech = [quote, quote, quote].join(' ');
</script>
<div class="stack">
<div class="field">
<span class="caption">suffix, rows and expandable</span>
<TypographyParagraph ellipsis={{ rows: 2, expandable: 'collapsible', suffix: '--William Shakespeare' }}>{speech}</TypographyParagraph>
</div>
<div class="field">
<span class="caption">suffix with a text that fits</span>
<TypographyParagraph ellipsis={{ rows: 6, suffix: '--William Shakespeare' }}>{quote}</TypographyParagraph>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
actions.placement: 'end'
Buttons after the text.
actions.placement: 'start'
Buttons before the text.
expand, edit and copy together
Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.
<script lang="ts">
import { TypographyParagraph } from 'svelte-ant-design';
let text = $state('Buttons after the text.');
let other = $state('Buttons before the text.');
const long =
'Ant Design, a design language for background applications, is refined by Ant UED Team. It aims to make the interface specifications of internal projects uniform, to lower the cost of design differences and of implementation, and to free the time of designers and front-end developers.';
</script>
<div class="stack">
<div class="field">
<span class="caption">actions.placement: 'end'</span>
<TypographyParagraph bind:content={text} editable copyable />
</div>
<div class="field">
<span class="caption">actions.placement: 'start'</span>
<TypographyParagraph bind:content={other} editable copyable actions={{ placement: 'start' }} />
</div>
<div class="field">
<span class="caption">expand, edit and copy together</span>
<TypographyParagraph content={long} editable copyable ellipsis={{ rows: 2, expandable: true }} />
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
shimmer
Thinking...
duration: 3 A slow sweep, then one second of rest
duration: [1, 0] A sweep without a pause
<script lang="ts">
import { Switch, TypographyText } from 'svelte-ant-design';
let thinking = $state(true);
</script>
<div class="stack">
<div class="field">
<span class="caption">shimmer</span>
<div class="row">
<Switch bind:checked={thinking} aria-label="Shimmer" />
<TypographyText shimmer={thinking}>{thinking ? 'Thinking...' : 'Done.'}</TypographyText>
</div>
</div>
<div class="field">
<span class="caption">duration: 3</span>
<TypographyText shimmer={{ duration: 3 }}>A slow sweep, then one second of rest</TypographyText>
</div>
<div class="field">
<span class="caption">duration: [1, 0]</span>
<TypographyText shimmer={{ duration: [1, 0] }}>A sweep without a pause</TypographyText>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
classNames: a class for each part (the CSS is in this example)
Styled by part.
styles: inline styles, custom properties included
Purple buttons, further from the text.
class and style
A note with a bar.
<script lang="ts">
import { TypographyParagraph } from 'svelte-ant-design';
let text = $state('Styled by part.');
</script>
<div class="stack">
<div class="field">
<span class="caption">classNames: a class for each part (the CSS is in this example)</span>
<TypographyParagraph
bind:content={text}
copyable
editable
classNames={{ root: 'demo-root', actions: 'demo-actions', action: 'demo-action', textarea: 'demo-textarea' }}
/>
</div>
<div class="field">
<span class="caption">styles: inline styles, custom properties included</span>
<TypographyParagraph
copyable
styles={{
root: { '--ads-typography-action-color': '#722ed1' },
actions: { 'margin-inline-start': '12px' }
}}
>
Purple buttons, further from the text.
</TypographyParagraph>
</div>
<div class="field">
<span class="caption">class and style</span>
<TypographyParagraph class="demo-note" style="padding-inline-start: 8px">A note with a bar.</TypographyParagraph>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 20px;
--ads-typography-paragraph-margin-bottom: 0;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
width: 100%;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
:global(.demo-root) {
font-weight: 600;
}
:global(.demo-actions) {
border-inline-start: 1px solid var(--ads-color-border);
padding-inline-start: 4px;
}
:global(.demo-action) {
transform: scale(1.15);
}
:global(.demo-textarea) {
font-style: italic;
}
:global(.demo-note) {
border-inline-start: 3px solid var(--ads-color-primary);
}
</style>
API
| Свойство | Описание | Тип | По умолчанию |
|---|---|---|---|
| type | Цвет текста. | 'secondary' | 'success' | 'warning' | 'danger' | — |
| disabled | Цвет и курсор отключённого. Кнопки работают; ссылка теряет href. | boolean | false |
| code | Вид code. | boolean | false |
| mark | Выделенный маркером текст. | boolean | false |
| underline | Подчёркнутый. | boolean | false |
| delete | Зачёркнутый. | boolean | false |
| strong | Жирный. Не для заголовка. | boolean | false |
| italic | Курсив. | boolean | false |
| keyboard | Вид kbd. Для Text и Link. | boolean | false |
| content | Текст как значение для правки, копирования и обрезки; важнее дочернего содержимого. bind:content записывает изменённый текст обратно. | string | — |
| copyable | Кнопка копирования (таблица ниже). | boolean | TypographyCopyable | false |
| editable | Кнопка правки и поле (таблица ниже). | boolean | TypographyEditable | false |
| editing | Открыто ли поле. bind:editing для двусторонней связи; обычное значение — начальное. | boolean | false |
| ellipsis | Обрезает текст (таблица ниже). Text и Link — одна строка: без rows, expandable и onexpand. | boolean | TypographyEllipsis | false |
| expanded | Развёрнут ли обрезанный текст. bind:expanded для двусторонней связи. Title и Paragraph. | boolean | false |
| actions | Где стоит панель кнопок. | { placement?: 'start' | 'end' } | { placement: 'end' } |
| shimmer | Анимированный текст. duration — секунды или [движение, пауза]. | boolean | { duration?: number | [number, number] } | false |
| children | Текст и строчное содержимое. | Snippet | — |
| onclick | Клик по компоненту, включая кнопки. | (event: MouseEvent) => void | — |
| classNames | Дополнительные классы частей. | Partial<Record<'root' | 'actions' | 'action' | 'textarea', string>> | — |
| styles | Инлайновые стили частей, после собственных. | Partial<Record<'root' | 'actions' | 'action' | 'textarea', Record<string, string | number>>> | — |
| class | Класс корня. | string | — |
| style | Инлайновый стиль корня. | string | — |
| level | Только TypographyTitle: 1–5 даёт h1–h5. | 1 | 2 | 3 | 4 | 5 | 1 |
| native attributes | Остальное идёт на элемент: id, data-*, aria-*; у ссылки также href, target, rel. | HTMLAttributes | — |
Объект copyable
| Свойство | Описание | Тип | По умолчанию |
|---|---|---|---|
| text | Что копировать, иначе content, иначе видимый текст. Пока промис ожидается, на кнопке крутится спиннер, а повторные нажатия ничего не делают. Долгий промис тоже копируется; по обычному HTTP и в Firefox старше 127 промис дольше нескольких секунд не скопируется. | string | (() => string | Promise<string>) | — |
| oncopy | Вызывается один раз за успешное копирование, не вызывается после неудачи. | (event: MouseEvent | KeyboardEvent) => void | — |
| icon | Заменяет значки копирования и галочки; получает copied. | Snippet<[boolean]> | — |
| tooltips | Подсказки до и после копирования; false прячет их. Строка становится и именем кнопки. | false | [string | Snippet, string | Snippet] | ['Copy', 'Copied'] |
| tabIndex | tabindex кнопки. | number | — |
Объект editable
| Свойство | Описание | Тип | По умолчанию |
|---|---|---|---|
| text | Начальный текст поля. | string | — |
| maxLength | maxlength поля. | number | — |
| autoSize | Поле растёт вместе с текстом. | boolean | { minRows?: number; maxRows?: number } | true |
| icon | Заменяет карандаш. | Snippet | — |
| tooltip | Подсказка кнопки правки; false прячет. Строка становится и её именем. | string | Snippet | false | 'Edit' |
| enterIcon | Значок в поле; null убирает его. | Snippet | null | — |
| triggerType | Чем начинается правка. Без 'icon' карандаша нет; текст-триггер не получает фокус. | Array<'icon' | 'text'> | ['icon'] |
| tabIndex | tabindex кнопки правки. | number | — |
| onstart | Пользователь открыл поле. | () => void | — |
| onchange | Правка завершена с другим текстом. | (text: string) => void | — |
| onend | Правка завершена Enter или уходом из поля. | () => void | — |
| oncancel | Отменено клавишей Escape. | () => void | — |
Объект ellipsis
| Свойство | Описание | Тип | По умолчанию |
|---|---|---|---|
| rows | Сколько строк показывать. | number | 1 |
| expandable | Кнопка разворачивания; 'collapsible' и сворачивает. | boolean | 'collapsible' | false |
| suffix | Текст после обрезанного, виден всегда. | string | — |
| symbol | Содержимое кнопки. Строка — текст разворачивания; snippet получает expanded. | string | Snippet<[boolean]> | 'Expand', 'Collapse' |
| tooltip | Полный текст в подсказке, пока текст обрезан. | boolean | string | Snippet | TooltipProps | — |
| onexpand | Пользователь нажал «развернуть» или «свернуть». | (event: MouseEvent, info: { expanded: boolean }) => void | — |
| onellipsis | Текст стал или перестал быть обрезанным. | (ellipsis: boolean) => void | — |
Отличия от Ant Design: текст для правки и обрезки задаётся через
content с bind:, а editing и expanded — связываемые пропсы, а не поля объектов. copyable.icon — один snippet с параметром copied, classNames и styles принимают объекты, а format: 'text/html' и стили таблиц отложены на v1.1. Подписи на английском до ConfigProvider (v1.1).Части компонента
| Часть | Описание |
|---|---|
| root | Сам элемент компонента с оформлением внутри. |
| actions | Панель с кнопками. |
| action | Каждая кнопка: копирование, правка, разворот, сворачивание. |
| textarea | <textarea> поля правки. |
Дизайн-токены
| Токен | Описание | По умолчанию |
|---|---|---|
| --ads-typography-font-size | Размер текста абзаца и статьи. | var(--ads-font-size) |
| --ads-typography-line-height | Высота строки абзаца и статьи. | 22px |
| --ads-typography-color | Цвет текста. | var(--ads-color-text) |
| --ads-typography-paragraph-margin-bottom | Отступ под абзацем, списком и цитатой. | 1em |
| --ads-typography-title-weight | Начертание заголовков. | 600 |
| --ads-typography-title-margin-top | Отступ над заголовком (нет у первого). | 1.2em |
| --ads-typography-title-margin-bottom | Отступ под заголовком. | 0.5em |
| --ads-typography-h1-font-size | Размер заголовка уровня 1. | 38px |
| --ads-typography-h1-line-height | Высота строки заголовка уровня 1. | 46px |
| --ads-typography-h2-font-size | Размер заголовка уровня 2. | 30px |
| --ads-typography-h2-line-height | Высота строки заголовка уровня 2. | 38px |
| --ads-typography-h3-font-size | Размер заголовка уровня 3. | 24px |
| --ads-typography-h3-line-height | Высота строки заголовка уровня 3. | 32px |
| --ads-typography-h4-font-size | Размер заголовка уровня 4. | 20px |
| --ads-typography-h4-line-height | Высота строки заголовка уровня 4. | 28px |
| --ads-typography-h5-font-size | Размер заголовка уровня 5. | 16px |
| --ads-typography-h5-line-height | Высота строки заголовка уровня 5. | 24px |
| --ads-typography-secondary-color | Цвет типа secondary. tokens-accessible.css затемняет его. | var(--ads-color-text-tertiary) |
| --ads-typography-success-color | Цвет типа success. tokens-accessible.css затемняет его. | #52c41a |
| --ads-typography-warning-color | Цвет типа warning. tokens-accessible.css затемняет его. | #faad14 |
| --ads-typography-danger-color | Цвет типа danger. tokens-accessible.css затемняет его. | var(--ads-color-danger) |
| --ads-typography-disabled-color | Цвет отключённого текста. | var(--ads-color-text-disabled) |
| --ads-typography-link-color | Цвет ссылки; tokens-accessible.css затемняет его. | var(--ads-color-link) |
| --ads-typography-link-hover-color | Цвет ссылки при наведении. | var(--ads-color-link-hover) |
| --ads-typography-link-active-color | Цвет нажатой ссылки. | var(--ads-color-link-active) |
| --ads-typography-link-decoration | Черта под ссылкой; в тёмной теме ссылки подчёркнуты, там их цвет слишком близок к цвету текста. | none |
| --ads-typography-action-color | Цвет кнопок. | var(--ads-color-link) |
| --ads-typography-action-hover-color | Цвет кнопки при наведении. | var(--ads-color-link-hover) |
| --ads-typography-action-active-color | Цвет нажатой кнопки. | var(--ads-color-link-active) |
| --ads-typography-actions-gap | Отступ между текстом и кнопками. | 4px |
| --ads-typography-mark-bg | Заливка выделенного текста. | #ffe58f |
| --ads-typography-mark-color | Цвет выделенного текста. | #000000 |
| --ads-typography-code-bg | Заливка code и pre. | rgba(150, 150, 150, 0.1) |
| --ads-typography-code-border | Граница code, kbd и pre. | rgba(100, 100, 100, 0.2) |
| --ads-typography-kbd-bg | Заливка kbd. | rgba(150, 150, 150, 0.06) |
| --ads-typography-code-font-family | Шрифт code, kbd и pre. | SFMono-Regular, Consolas, 'Liberation Mono', Menlo, Courier, monospace |
| --ads-typography-blockquote-border | Полоса в начале цитаты. | rgba(100, 100, 100, 0.2) |
| --ads-typography-edit-offset-inline | На сколько поле правки выступает в начале строки. | 12px |
| --ads-typography-edit-offset-block | На сколько поле правки выступает над и под строкой. | 5px |
| --ads-typography-enter-color | Цвет значка Enter в поле. | var(--ads-color-text-tertiary) |
| --ads-typography-shimmer-motion | Время движения мерцания в секундах. | 1 |
| --ads-typography-shimmer-wait | Пауза мерцания в секундах. | 1 |
| --ads-typography-shimmer-highlight | Цвет движущейся полосы мерцания. | var(--ads-color-bg-container) |
| --ads-typography-transition | Время смены цвета ссылок и кнопок. | 0.3s |
Доступность
- Копирование, правка и разворачивание — настоящие кнопки в порядке Tab с именами
Copy,Editи видимым текстом кнопки разворачивания; она же сообщает черезaria-expanded, раскрыт ли текст. Успешное копирование объявляется вежливым статусом, неудачное — молча. - Текст, обрезанный скриптом, целиком остаётся на странице для вспомогательных технологий; видимые куски и многоточие от них скрыты.
- У поля правки есть имя; Enter, Tab и клик в сторону сохраняют текст, Escape отбрасывает его, а Enter во время набора через IME ничего не делает.
- Два ограничения: текст, с которого начинается правка без карандаша, и текст с подсказкой не получают фокус. Оставляйте
'icon'вtriggerTypeи давайте клавиатурный путь к полному тексту черезexpandable. typeменяет только цвет: где он несёт смысл, добавьте слово или значок.- По умолчанию цвета — собственные цвета Ant Design, и часть не достигает 4.5:1; с
tokens-accessible.cssи в тёмной теме — достигает. При уменьшении движения мерцание останавливается, а в режимах принудительных цветов выделение рисуется системными цветами. - Проверено в Orca (Firefox): кнопки, статус копирования, поле правки, развёрнутое состояние, полный обрезанный текст, уровень заголовка и обычные ссылки. Orca говорит
expanded, но молчит, когда кнопка снова сворачивает — как и у любой кнопки сaria-expanded. Не проверено:Copiedу обещанного текста, который идёт несколько секунд (тестовый стенд не озвучивает такое позднее изменение), NVDA, JAWS, VoiceOver и телефоны.