Typography
Text for articles and interfaces: titles, paragraphs, inline text and links, with styles, a copy button, in-place editing and the cut of long text.
When to use
- Use it for readable text with a consistent look: an article, notes or a blog.
- Use
copyableandeditablefor short values a person takes or changes, such as an identifier or a name. - Use
ellipsiswhere space is limited, and keep a way to read the whole text: a tooltip orexpandable.
Examples
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
| Property | Description | Type | Default |
|---|---|---|---|
| type | Colour of the text. | 'secondary' | 'success' | 'warning' | 'danger' | — |
| disabled | Disabled colour and a not-allowed cursor. The buttons stay usable; a link loses its href. | boolean | false |
| code | code look. | boolean | false |
| mark | Highlighted text. | boolean | false |
| underline | Underlined. | boolean | false |
| delete | Struck through. | boolean | false |
| strong | Bold. Not for a title. | boolean | false |
| italic | Italic. | boolean | false |
| keyboard | kbd look. For Text and Link. | boolean | false |
| content | The text as a value, used by edit, copy and the cut; wins over the child content. bind:content writes the edited text back. | string | — |
| copyable | A copy button (see the table below). | boolean | TypographyCopyable | false |
| editable | An edit button and the field (see the table below). | boolean | TypographyEditable | false |
| editing | Whether the field is open. bind:editing for two-way use; a plain value is the initial state. | boolean | false |
| ellipsis | Cuts the text (see the table below). Text and Link are one row: no rows, expandable or onexpand. | boolean | TypographyEllipsis | false |
| expanded | Whether the cut text is expanded. bind:expanded for two-way use. Title and Paragraph. | boolean | false |
| actions | Where the bar of buttons stands. | { placement?: 'start' | 'end' } | { placement: 'end' } |
| shimmer | Animated text. duration is seconds, or [motion, pause]. | boolean | { duration?: number | [number, number] } | false |
| children | The text and inline content. | Snippet | — |
| onclick | Click on the part, its buttons included. | (event: MouseEvent) => void | — |
| classNames | Extra classes for the parts. | Partial<Record<'root' | 'actions' | 'action' | 'textarea', string>> | — |
| styles | Inline styles of the parts, written after the component's own. | Partial<Record<'root' | 'actions' | 'action' | 'textarea', Record<string, string | number>>> | — |
| class | A class of the root. | string | — |
| style | Inline style of the root. | string | — |
| level | TypographyTitle only: 1 to 5 gives h1 to h5. | 1 | 2 | 3 | 4 | 5 | 1 |
| native attributes | Everything else goes to the element: id, data-*, aria-*; for a link also href, target, rel. | HTMLAttributes | — |
The copyable object
| Property | Description | Type | Default |
|---|---|---|---|
| text | The text to copy, else content, else the rendered text. While a promise is awaited the button shows a spinner and further clicks do nothing. A slow promise is copied too; on plain HTTP and in Firefox before 127 one slower than a few seconds fails. | string | (() => string | Promise<string>) | — |
| oncopy | Called once per successful copy, never after a failed one. | (event: MouseEvent | KeyboardEvent) => void | — |
| icon | Replaces the copy and the check icons; gets copied. | Snippet<[boolean]> | — |
| tooltips | The tips before and after the copy; false hides them. A string is also the button's name. | false | [string | Snippet, string | Snippet] | ['Copy', 'Copied'] |
| tabIndex | tabindex of the button. | number | — |
The editable object
| Property | Description | Type | Default |
|---|---|---|---|
| text | The starting text of the field. | string | — |
| maxLength | maxlength of the field. | number | — |
| autoSize | The field grows with the text. | boolean | { minRows?: number; maxRows?: number } | true |
| icon | Replaces the pencil. | Snippet | — |
| tooltip | The tip of the edit button; false hides it. A string is also its name. | string | Snippet | false | 'Edit' |
| enterIcon | The mark in the field; null removes it. | Snippet | null | — |
| triggerType | What starts the editing. Without 'icon' there is no pencil; a text trigger is not focusable. | Array<'icon' | 'text'> | ['icon'] |
| tabIndex | tabindex of the edit button. | number | — |
| onstart | The user opened the field. | () => void | — |
| onchange | The editing completed with a different text. | (text: string) => void | — |
| onend | The editing completed by Enter or by leaving the field. | () => void | — |
| oncancel | Cancelled by Escape. | () => void | — |
The ellipsis object
| Property | Description | Type | Default |
|---|---|---|---|
| rows | Rows to show. | number | 1 |
| expandable | An expand button; 'collapsible' also collapses. | boolean | 'collapsible' | false |
| suffix | Text after the cut text, always shown. | string | — |
| symbol | The content of the button. A string is the expand text; a snippet gets expanded. | string | Snippet<[boolean]> | 'Expand', 'Collapse' |
| tooltip | The full text in a tip while the text is cut. | boolean | string | Snippet | TooltipProps | — |
| onexpand | The user pressed expand or collapse. | (event: MouseEvent, info: { expanded: boolean }) => void | — |
| onellipsis | The text started or stopped being cut. | (ellipsis: boolean) => void | — |
Differences from Ant Design:
content with bind: is how an editable or cut text is given, and editing and expanded are bound props, not fields of the objects. copyable.icon is one snippet that gets copied, classNames and styles take objects, and format: 'text/html' and table styles are reserved for v1.1. The labels are English until ConfigProvider (v1.1).Semantic parts
| Part | Description |
|---|---|
| root | The element of the part itself, the decorations inside it. |
| actions | The bar that holds the buttons. |
| action | Each button: copy, edit, expand, collapse. |
| textarea | The <textarea> of the edit field. |
Design tokens
| Token | Description | Default |
|---|---|---|
| --ads-typography-font-size | Text size of a paragraph and the article. | var(--ads-font-size) |
| --ads-typography-line-height | Line height of a paragraph and the article. | 22px |
| --ads-typography-color | Text colour. | var(--ads-color-text) |
| --ads-typography-paragraph-margin-bottom | Space under a paragraph, a list and a quote. | 1em |
| --ads-typography-title-weight | Weight of headings. | 600 |
| --ads-typography-title-margin-top | Space above a heading (none above the first). | 1.2em |
| --ads-typography-title-margin-bottom | Space under a heading. | 0.5em |
| --ads-typography-h1-font-size | Size of a level 1 title. | 38px |
| --ads-typography-h1-line-height | Line height of a level 1 title. | 46px |
| --ads-typography-h2-font-size | Size of a level 2 title. | 30px |
| --ads-typography-h2-line-height | Line height of a level 2 title. | 38px |
| --ads-typography-h3-font-size | Size of a level 3 title. | 24px |
| --ads-typography-h3-line-height | Line height of a level 3 title. | 32px |
| --ads-typography-h4-font-size | Size of a level 4 title. | 20px |
| --ads-typography-h4-line-height | Line height of a level 4 title. | 28px |
| --ads-typography-h5-font-size | Size of a level 5 title. | 16px |
| --ads-typography-h5-line-height | Line height of a level 5 title. | 24px |
| --ads-typography-secondary-color | Colour of the secondary type. tokens-accessible.css darkens it. | var(--ads-color-text-tertiary) |
| --ads-typography-success-color | Colour of the success type. tokens-accessible.css darkens it. | #52c41a |
| --ads-typography-warning-color | Colour of the warning type. tokens-accessible.css darkens it. | #faad14 |
| --ads-typography-danger-color | Colour of the danger type. tokens-accessible.css darkens it. | var(--ads-color-danger) |
| --ads-typography-disabled-color | Colour of disabled text. | var(--ads-color-text-disabled) |
| --ads-typography-link-color | Colour of a link; tokens-accessible.css darkens it. | var(--ads-color-link) |
| --ads-typography-link-hover-color | Colour of a link on hover. | var(--ads-color-link-hover) |
| --ads-typography-link-active-color | Colour of a pressed link. | var(--ads-color-link-active) |
| --ads-typography-link-decoration | Line under a link; the dark theme underlines links, whose colour is too close to the text there. | none |
| --ads-typography-action-color | Colour of the buttons. | var(--ads-color-link) |
| --ads-typography-action-hover-color | Colour of a button on hover. | var(--ads-color-link-hover) |
| --ads-typography-action-active-color | Colour of a pressed button. | var(--ads-color-link-active) |
| --ads-typography-actions-gap | Space between the text and the buttons. | 4px |
| --ads-typography-mark-bg | Fill of highlighted text. | #ffe58f |
| --ads-typography-mark-color | Text colour of highlighted text. | #000000 |
| --ads-typography-code-bg | Fill of code and pre. | rgba(150, 150, 150, 0.1) |
| --ads-typography-code-border | Border of code, kbd and pre. | rgba(100, 100, 100, 0.2) |
| --ads-typography-kbd-bg | Fill of kbd. | rgba(150, 150, 150, 0.06) |
| --ads-typography-code-font-family | Font of code, kbd and pre. | SFMono-Regular, Consolas, 'Liberation Mono', Menlo, Courier, monospace |
| --ads-typography-blockquote-border | Bar at the start of a quote. | rgba(100, 100, 100, 0.2) |
| --ads-typography-edit-offset-inline | How far the edit field hangs over the start of the line. | 12px |
| --ads-typography-edit-offset-block | How far the edit field hangs over the line above and below. | 5px |
| --ads-typography-enter-color | Colour of the enter mark in the field. | var(--ads-color-text-tertiary) |
| --ads-typography-shimmer-motion | Motion time of the shimmer, in seconds. | 1 |
| --ads-typography-shimmer-wait | Pause of the shimmer, in seconds. | 1 |
| --ads-typography-shimmer-highlight | Colour of the moving band of the shimmer. | var(--ads-color-bg-container) |
| --ads-typography-transition | Time of the colour change of links and buttons. | 0.3s |
Accessibility
- Copy, edit and expand are real buttons in the Tab order, named
Copy,Editand by the visible text of the expand button, which also says witharia-expandedwhether the text is open. A successful copy is announced by a polite status; a failed one is silent. - A text cut by script keeps the whole text in the page for assistive technology; the visible pieces and the dots are hidden from it.
- The edit field has a name; Enter, Tab and a click elsewhere keep the text, Escape discards it, and Enter during an IME composition does nothing.
- Two limits: a text that starts the editing without the pencil, and a text with a tooltip, cannot be focused. Keep
'icon'intriggerType, and give a keyboard way to the full text withexpandable. typeonly changes the colour: add a word or an icon where it carries meaning.- By default the colours are Ant Design's own and some do not reach 4.5:1; with
tokens-accessible.cssand in the dark theme they do. Reduced motion stops the shimmer, and in forced-colors modes the highlight uses system colours. - Checked with Orca (Firefox): the buttons, the copy status, the edit field, the expanded state, the whole cut text, the level of a title and plain links. Orca says
expandedbut nothing when a button closes again, as with anyaria-expandedbutton. Not checked:Copiedfor a promised text that takes seconds (the test setup does not speak so late a change), NVDA, JAWS, VoiceOver and phones.