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.

Import
import { Typography, TypographyTitle, TypographyParagraph, TypographyText, TypographyLink } from 'svelte-ant-design';
Links
src/lib/Typography Report an issue Component README

When to use

  • Use it for readable text with a consistent look: an article, notes or a blog.
  • Use copyable and editable for short values a person takes or changes, such as an identifier or a name.
  • Use ellipsis where space is limited, and keep a way to read the whole text: a tooltip or expandable.

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.

Article

Typography is an <article> with the base text. Write its headings, paragraphs, inline text and links with the four components.

Release notes

Read the table of properties before you start.

  • Run npm install and press Enter
  • Decide first, then build
Consistency is a feature that every page gets for free.
npm install svelte-ant-design

Ready HTML

For HTML that comes ready, from Markdown or a CMS, where you cannot place components. Inside Typography plain headings, paragraphs, links, lists, a quote, pre, code, kbd, mark and strong are styled; components of this library inside it keep their own look. Insert only HTML you trust or have sanitized.

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

Titles

level 1 to 5 gives h1 to h5; the size follows the level. The example starts at 2: a page has one h1, the default level.

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 (code) Ant Design (keyboard) Ant Design (underline) Ant Design (delete) Ant Design (strong) Ant Design (italic)
combined Not for production

Text styles

type, disabled and the flags strong, italic, underline, delete, mark, code and keyboard. Flags combine.

copyable
This is a copyable text.
Nothing copied yet
text: 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 yet
icon, tooltips
Own icon and tips.
tooltips: false
No tip, the button keeps its name.
a Text with only the button

Copy

copyable adds a copy button. The text, the icon, the tips and a callback are in the object form; the text may be a function or a promise: while it is awaited the button shows a spinner.

bind:content, with the events
This is an editable text.
No events yet
icon, 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.

Edit

editable opens a field in place of the text. Enter, Tab and a click elsewhere keep it, Escape cancels. bind:content writes the new text back.

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 whole
a 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.

Ellipsis

ellipsis cuts the text to one row or to rows. With tooltip the full text shows on hover, only while the text is cut.

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.
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.
Nothing pressed yet
symbol 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.

Expand and collapse

expandable puts a button at the end of the last row; 'collapsible' adds a way back. symbol is its content, as text or a snippet.

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.
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.

Controlled

bind:expanded holds the state; the number of rows can change at any time and the text is cut again.

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.
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.

Suffix

suffix follows the cut text, and stays also when the text fits.

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.

Action bar

actions.placement puts the buttons after the text or before it. Their order is expand, edit, copy.

shimmer
Thinking...
duration: 3 A slow sweep, then one second of rest
duration: [1, 0] A sweep without a pause

Shimmer

shimmer moves a band of light over the text while something is being prepared. duration is the motion time, or the motion and the pause.

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.

Styling the parts

classNames and styles address the root, the action bar, each button and the edit field.

API

PropertyDescriptionTypeDefault
typeColour of the text.'secondary' | 'success' | 'warning' | 'danger'—
disabledDisabled colour and a not-allowed cursor. The buttons stay usable; a link loses its href.booleanfalse
codecode look.booleanfalse
markHighlighted text.booleanfalse
underlineUnderlined.booleanfalse
deleteStruck through.booleanfalse
strongBold. Not for a title.booleanfalse
italicItalic.booleanfalse
keyboardkbd look. For Text and Link.booleanfalse
contentThe text as a value, used by edit, copy and the cut; wins over the child content. bind:content writes the edited text back.string—
copyableA copy button (see the table below).boolean | TypographyCopyablefalse
editableAn edit button and the field (see the table below).boolean | TypographyEditablefalse
editingWhether the field is open. bind:editing for two-way use; a plain value is the initial state.booleanfalse
ellipsisCuts the text (see the table below). Text and Link are one row: no rows, expandable or onexpand.boolean | TypographyEllipsisfalse
expandedWhether the cut text is expanded. bind:expanded for two-way use. Title and Paragraph.booleanfalse
actionsWhere the bar of buttons stands.{ placement?: 'start' | 'end' }{ placement: 'end' }
shimmerAnimated text. duration is seconds, or [motion, pause].boolean | { duration?: number | [number, number] }false
childrenThe text and inline content.Snippet—
onclickClick on the part, its buttons included.(event: MouseEvent) => void—
classNamesExtra classes for the parts.Partial<Record<'root' | 'actions' | 'action' | 'textarea', string>>—
stylesInline styles of the parts, written after the component's own.Partial<Record<'root' | 'actions' | 'action' | 'textarea', Record<string, string | number>>>—
classA class of the root.string—
styleInline style of the root.string—
levelTypographyTitle only: 1 to 5 gives h1 to h5.1 | 2 | 3 | 4 | 51
native attributesEverything else goes to the element: id, data-*, aria-*; for a link also href, target, rel.HTMLAttributes—

The copyable object

PropertyDescriptionTypeDefault
textThe 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>)—
oncopyCalled once per successful copy, never after a failed one.(event: MouseEvent | KeyboardEvent) => void—
iconReplaces the copy and the check icons; gets copied.Snippet<[boolean]>—
tooltipsThe tips before and after the copy; false hides them. A string is also the button's name.false | [string | Snippet, string | Snippet]['Copy', 'Copied']
tabIndextabindex of the button.number—

The editable object

PropertyDescriptionTypeDefault
textThe starting text of the field.string—
maxLengthmaxlength of the field.number—
autoSizeThe field grows with the text.boolean | { minRows?: number; maxRows?: number }true
iconReplaces the pencil.Snippet—
tooltipThe tip of the edit button; false hides it. A string is also its name.string | Snippet | false'Edit'
enterIconThe mark in the field; null removes it.Snippet | null—
triggerTypeWhat starts the editing. Without 'icon' there is no pencil; a text trigger is not focusable.Array<'icon' | 'text'>['icon']
tabIndextabindex of the edit button.number—
onstartThe user opened the field.() => void—
onchangeThe editing completed with a different text.(text: string) => void—
onendThe editing completed by Enter or by leaving the field.() => void—
oncancelCancelled by Escape.() => void—

The ellipsis object

PropertyDescriptionTypeDefault
rowsRows to show.number1
expandableAn expand button; 'collapsible' also collapses.boolean | 'collapsible'false
suffixText after the cut text, always shown.string—
symbolThe content of the button. A string is the expand text; a snippet gets expanded.string | Snippet<[boolean]>'Expand', 'Collapse'
tooltipThe full text in a tip while the text is cut.boolean | string | Snippet | TooltipProps—
onexpandThe user pressed expand or collapse.(event: MouseEvent, info: { expanded: boolean }) => void—
onellipsisThe 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

PartDescription
rootThe element of the part itself, the decorations inside it.
actionsThe bar that holds the buttons.
actionEach button: copy, edit, expand, collapse.
textareaThe <textarea> of the edit field.

Design tokens

TokenDescriptionDefault
--ads-typography-font-sizeText size of a paragraph and the article.var(--ads-font-size)
--ads-typography-line-heightLine height of a paragraph and the article.22px
--ads-typography-colorText colour.var(--ads-color-text)
--ads-typography-paragraph-margin-bottomSpace under a paragraph, a list and a quote.1em
--ads-typography-title-weightWeight of headings.600
--ads-typography-title-margin-topSpace above a heading (none above the first).1.2em
--ads-typography-title-margin-bottomSpace under a heading.0.5em
--ads-typography-h1-font-sizeSize of a level 1 title.38px
--ads-typography-h1-line-heightLine height of a level 1 title.46px
--ads-typography-h2-font-sizeSize of a level 2 title.30px
--ads-typography-h2-line-heightLine height of a level 2 title.38px
--ads-typography-h3-font-sizeSize of a level 3 title.24px
--ads-typography-h3-line-heightLine height of a level 3 title.32px
--ads-typography-h4-font-sizeSize of a level 4 title.20px
--ads-typography-h4-line-heightLine height of a level 4 title.28px
--ads-typography-h5-font-sizeSize of a level 5 title.16px
--ads-typography-h5-line-heightLine height of a level 5 title.24px
--ads-typography-secondary-colorColour of the secondary type. tokens-accessible.css darkens it.var(--ads-color-text-tertiary)
--ads-typography-success-colorColour of the success type. tokens-accessible.css darkens it.#52c41a
--ads-typography-warning-colorColour of the warning type. tokens-accessible.css darkens it.#faad14
--ads-typography-danger-colorColour of the danger type. tokens-accessible.css darkens it.var(--ads-color-danger)
--ads-typography-disabled-colorColour of disabled text.var(--ads-color-text-disabled)
--ads-typography-link-colorColour of a link; tokens-accessible.css darkens it.var(--ads-color-link)
--ads-typography-link-hover-colorColour of a link on hover.var(--ads-color-link-hover)
--ads-typography-link-active-colorColour of a pressed link.var(--ads-color-link-active)
--ads-typography-link-decorationLine under a link; the dark theme underlines links, whose colour is too close to the text there.none
--ads-typography-action-colorColour of the buttons.var(--ads-color-link)
--ads-typography-action-hover-colorColour of a button on hover.var(--ads-color-link-hover)
--ads-typography-action-active-colorColour of a pressed button.var(--ads-color-link-active)
--ads-typography-actions-gapSpace between the text and the buttons.4px
--ads-typography-mark-bgFill of highlighted text.#ffe58f
--ads-typography-mark-colorText colour of highlighted text.#000000
--ads-typography-code-bgFill of code and pre.rgba(150, 150, 150, 0.1)
--ads-typography-code-borderBorder of code, kbd and pre.rgba(100, 100, 100, 0.2)
--ads-typography-kbd-bgFill of kbd.rgba(150, 150, 150, 0.06)
--ads-typography-code-font-familyFont of code, kbd and pre.SFMono-Regular, Consolas, 'Liberation Mono', Menlo, Courier, monospace
--ads-typography-blockquote-borderBar at the start of a quote.rgba(100, 100, 100, 0.2)
--ads-typography-edit-offset-inlineHow far the edit field hangs over the start of the line.12px
--ads-typography-edit-offset-blockHow far the edit field hangs over the line above and below.5px
--ads-typography-enter-colorColour of the enter mark in the field.var(--ads-color-text-tertiary)
--ads-typography-shimmer-motionMotion time of the shimmer, in seconds.1
--ads-typography-shimmer-waitPause of the shimmer, in seconds.1
--ads-typography-shimmer-highlightColour of the moving band of the shimmer.var(--ads-color-bg-container)
--ads-typography-transitionTime of the colour change of links and buttons.0.3s

Accessibility

  • Copy, edit and expand are real buttons in the Tab order, named Copy, Edit and by the visible text of the expand button, which also says with aria-expanded whether 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' in triggerType, and give a keyboard way to the full text with expandable.
  • type only 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.css and 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 expanded but nothing when a button closes again, as with any aria-expanded button. Not checked: Copied for a promised text that takes seconds (the test setup does not speak so late a change), NVDA, JAWS, VoiceOver and phones.