Typography
Headings, inline text, and paragraphs: HuiTitle, HuiText, and HuiParagraph, plus the font-styling container HuiTypography.
Import
import { HuiTypography, HuiTitle, HuiText, HuiParagraph } from '@nscode/handy-ui'
Basic Usage
HuiTypography applies a shared font, color, and line height to its contents. Use HuiTitle, HuiParagraph, and HuiText for headings, paragraphs, and inline text respectively.
<template>
<HuiTypography>
<HuiTitle :level="2">Heading</HuiTitle>
<HuiParagraph
>A paragraph. <HuiText type="primary" bold>Emphasized text</HuiText> Continue
writing.</HuiParagraph
>
</HuiTypography>
</template>
Heading Levels
level accepts 1 through 5, rendering <h1> through <h5> at 48, 38, 30, 24, and 20px respectively. Levels 1 and 2 use bold (700), levels 3 and 4 use semibold (600), and level 5 uses medium (500). Headings have no default margin.
<template>
<HuiSpace direction="vertical" align="start">
<HuiTitle :level="1">Heading level 1</HuiTitle>
<HuiTitle :level="2">Heading level 2</HuiTitle>
<HuiTitle :level="3">Heading level 3</HuiTitle>
<HuiTitle :level="4">Heading level 4</HuiTitle>
<HuiTitle :level="5">Heading level 5</HuiTitle>
</HuiSpace>
</template>
Color Types
type controls text color with seven values: default (normal text), primary, success, warning, danger, info, and secondary. Title, Text, and Paragraph all support it. In the default theme, info and primary use the same blue.
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">Text</span>
<HuiText>Default(default)</HuiText>
<HuiText type="primary">Primary(primary)</HuiText>
<HuiText type="success">Success(success)</HuiText>
<HuiText type="warning">Warning(warning)</HuiText>
<HuiText type="danger">Danger(danger)</HuiText>
<HuiText type="info">Info(info)</HuiText>
<HuiText type="secondary">Secondary(secondary)</HuiText>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">Title</span>
<HuiTitle :level="5">Default</HuiTitle>
<HuiTitle :level="5" type="primary">Primary</HuiTitle>
<HuiTitle :level="5" type="success">Success</HuiTitle>
<HuiTitle :level="5" type="warning">Warning</HuiTitle>
<HuiTitle :level="5" type="danger">Danger</HuiTitle>
<HuiTitle :level="5" type="info">Info</HuiTitle>
<HuiTitle :level="5" type="secondary">Secondary</HuiTitle>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">Paragraph</span>
<HuiParagraph>Default paragraph</HuiParagraph>
<HuiParagraph type="primary">Primary paragraph</HuiParagraph>
<HuiParagraph type="success">Success paragraph</HuiParagraph>
<HuiParagraph type="warning">Warning paragraph</HuiParagraph>
<HuiParagraph type="danger">Danger paragraph</HuiParagraph>
<HuiParagraph type="info">Info paragraph</HuiParagraph>
<HuiParagraph type="secondary">Secondary paragraph</HuiParagraph>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 72px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Text Sizes
size sets the font size for Text and Paragraph: xs 12px, sm 13px, base 14px (the default), lg 16px, or xl 20px. Title uses level to determine its font size and does not have a size prop.
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap align="baseline">
<HuiText size="xs">Extra small (xs)</HuiText>
<HuiText size="sm">Small (sm)</HuiText>
<HuiText>Default (base)</HuiText>
<HuiText size="lg">Large (lg)</HuiText>
<HuiText size="xl">Extra large (xl)</HuiText>
</HuiSpace>
<HuiParagraph size="xs"
>xs: Paragraph font sizes are configurable, with a line height of 1.75 times the font
size.</HuiParagraph
>
<HuiParagraph size="sm"
>sm: Paragraph font sizes are configurable, with a line height of 1.75 times the font
size.</HuiParagraph
>
<HuiParagraph
>base: Paragraph font sizes are configurable, with a line height of 1.75 times the font
size.</HuiParagraph
>
<HuiParagraph size="lg"
>lg: Paragraph font sizes are configurable, with a line height of 1.75 times the font
size.</HuiParagraph
>
<HuiParagraph size="xl"
>xl: Paragraph font sizes are configurable, with a line height of 1.75 times the font
size.</HuiParagraph
>
</HuiSpace>
</template>
Text Decorations
Combine bold, italic, underline, deleted (strikethrough), mark (a pale yellow highlight), and code (a gray background with a monospace font at 0.9 times the surrounding font size). These props are available on Title, Text, and Paragraph.
Strikethrough, highlighted, and code text follow the type color:
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">Individual</span>
<HuiText bold>Bold(bold)</HuiText>
<HuiText italic>Italic(italic)</HuiText>
<HuiText underline>Underline(underline)</HuiText>
<HuiText deleted>Strikethrough(deleted)</HuiText>
<HuiText mark>Highlight(mark)</HuiText>
<HuiText code>Code(code)</HuiText>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">Combined</span>
<HuiText bold italic>Bold italic</HuiText>
<HuiText bold underline>Bold underlined</HuiText>
<HuiText deleted mark>Struck through and highlighted</HuiText>
<HuiText mark code>Highlighted code</HuiText>
<HuiText deleted code>Struck-through code</HuiText>
<HuiText bold italic underline>Three combined</HuiText>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">Colored</span>
<HuiText type="danger" deleted>Voided</HuiText>
<HuiText type="success" mark>Approved</HuiText>
<HuiText type="primary" code>v-model</HuiText>
<HuiText type="warning" underline>Pending confirmation</HuiText>
<HuiText type="secondary" italic>Remark</HuiText>
<HuiText size="lg" bold>Large bold text</HuiText>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">Heading</span>
<HuiTitle :level="5" italic>Italic heading</HuiTitle>
<HuiTitle :level="5" underline>Underlined heading</HuiTitle>
<HuiTitle :level="5" deleted>Struck-through heading</HuiTitle>
<HuiTitle :level="5" mark>Highlighted heading</HuiTitle>
<HuiTitle :level="5" code>HuiTitle</HuiTitle>
<HuiTitle :level="5" bold>Bold level-5 heading</HuiTitle>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
These decorations also apply to paragraphs. Nest HuiText within a paragraph to decorate only part of it:
<template>
<HuiTypography>
<HuiParagraph>
Order <HuiText code>20260001</HuiText> changed from
<HuiText type="danger" deleted>Awaiting payment</HuiText> to
<HuiText type="success" bold>Paid</HuiText>,
<HuiText mark>Expected to ship tomorrow</HuiText>.
</HuiParagraph>
<HuiParagraph type="secondary" italic
>An italic secondary paragraph for additional information.</HuiParagraph
>
<HuiParagraph mark>A highlighted paragraph for information requiring attention.</HuiParagraph>
</HuiTypography>
</template>
Copying
copyable displays a Copy button after the text. After a successful copy, it shows Copied for 2 seconds and emits copy with the copied text. The rendered text is copied, including text inside nested elements. Title, Text, and Paragraph all support copying.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiParagraph, HuiSpace, HuiText, HuiTitle } from '@nscode/handy-ui'
const copied = ref('')
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiText copyable @copy="copied = $event">
<span>Outer<b>Inner</b></span>
</HuiText>
<HuiText code copyable @copy="copied = $event">npm i @nscode/handy-ui</HuiText>
<HuiTitle :level="4" copyable @copy="copied = $event">A copyable heading</HuiTitle>
<HuiParagraph copyable @copy="copied = $event"
>The paragraph's Copy button follows its text.</HuiParagraph
>
</HuiSpace>
<p style="margin-top: 12px">{{ copied ? `Copied: ${copied}` : 'Try Copy' }}</p>
</template>
Single-Line Ellipsis (Title and Text)
The boolean ellipsis truncates content after one line. Text occupies at most the parent's line width by default; set max-width or width for a narrower limit. Title truncates according to its parent's width. With copyable, the Copy button follows the ellipsis while still copying the full text.
<template>
<HuiSpace direction="vertical" fill>
<HuiText ellipsis style="max-width: 200px"
>This is a long piece of text; content beyond the available width is truncated</HuiText
>
<div style="max-width: 240px">
<HuiText ellipsis>
Without an explicit width, text follows its parent's width. Here the parent is at most 240px
wide, so overflow is ellipsized
</HuiText>
</div>
<HuiText ellipsis copyable style="max-width: 260px">
With copying enabled, the Copy button follows the ellipsis and copies the full text
</HuiText>
<div style="max-width: 360px">
<HuiTitle :level="3" ellipsis copyable
>A long heading is ellipsized where it exceeds the parent's width</HuiTitle
>
</div>
</HuiSpace>
</template>
Multiline Ellipsis and Expansion (Paragraph)
ellipsis=true truncates to one line. An object configures the line count, expansion button, and suffix through TypographyEllipsisConfig:
rows: maximum visible line count.expandable: shows an Expand button when text is truncated. Clicking reveals the full text. The button is hidden when content does not overflow.collapsible: together withexpandable, shows Collapse after expansion. Defaults to false, preserving expansion without a collapse action.suffix: a suffix that remains after the text, including after expansion.
The suffix, Expand, and Copy controls appear on the next line after the truncated text, in that order. The paragraphs below have a 420px width limit. After expanding, use Collapse again to reset the example:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiParagraph, HuiSpace } from '@nscode/handy-ui'
const text =
'HandyUI is a Vue 3 component library offering buttons, forms, tables, overlays, and other common components. Theme variables control colors, sizes, and spacing, and all components follow dark-theme changes. The components include keyboard interaction and screen-reader attributes for admin applications, dashboards, and internal tools. Each example in the documentation can run directly: copy it into your project to see the same result.'
// Change key to remount the paragraph in its truncated state
const key = ref(0)
</script>
<template>
<div style="max-width: 420px">
<HuiSpace :key="key" direction="vertical" fill>
<div>
<div class="label">ellipsis (one-line truncation)</div>
<HuiParagraph ellipsis>{{ text }}</HuiParagraph>
</div>
<div>
<div class="label">{ rows: 2 }</div>
<HuiParagraph :ellipsis="{ rows: 2 }">{{ text }}</HuiParagraph>
</div>
<div>
<div class="label">{ rows: 3, expandable: true }</div>
<HuiParagraph :ellipsis="{ rows: 3, expandable: true }">{{ text }}</HuiParagraph>
</div>
<div>
<div class="label">
{ rows: 2, expandable: true, suffix: '— From the description' }, with copyable
</div>
<HuiParagraph
:ellipsis="{ rows: 2, expandable: true, suffix: '— From the description' }"
copyable
>
{{ text }}
</HuiParagraph>
</div>
<div>
<div class="label">Text fits within 2 lines, so Expand is hidden</div>
<HuiParagraph :ellipsis="{ rows: 2, expandable: true }">A short paragraph.</HuiParagraph>
</div>
</HuiSpace>
<HuiButton size="small" style="margin-top: 12px" @click="key++">Collapse again</HuiButton>
</div>
</template>
<style scoped>
.label {
margin-bottom: 4px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Overflow Tooltips and Controlled Expansion
Text, Title, and Paragraph accept showOverflowTooltip. Hovering shows the full body only when ellipsis is enabled and the text is actually truncated. Short text and keyboard focus on the Copy button do not open the tooltip. Suffix and action text are excluded.
Paragraph stores expansion internally when expanded is omitted. Passing the prop, including explicit undefined displayed as false, makes it controlled. Rejected updates preserve the parent value and only report the request; v-model:expanded accepts requests. Each action emits update:expanded before expand, both with the requested state. expandText and collapseText override button labels, including an empty string. The suffix remains visible when text fits, expands, or collapses.
The ellipsis event reports actual truncation: the first measurement emits true only when truncated, then emits only on changes; an initial untruncated measurement does not emit false. Expansion removes truncation and emits false; collapsing measures again. SSR does not measure layout. An initially expanded controlled paragraph can show Collapse immediately; truncation notifications start after client mounting.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiParagraph, HuiSpace, HuiText, HuiTitle } from '@nscode/handy-ui'
const expanded = ref(false)
const lastEvent = ref('Not expanded yet')
const truncated = ref(false)
const refused = ref('No request yet')
const text = 'This long text demonstrates actual overflow. '.repeat(8)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiText ellipsis show-overflow-tooltip copyable style="max-width:240px">{{ text }}</HuiText>
<HuiTitle :level="4" ellipsis show-overflow-tooltip style="width:240px">{{ text }}</HuiTitle>
<HuiText ellipsis show-overflow-tooltip>Short text shows no tooltip</HuiText>
<div>
<HuiButton @click="expanded = !expanded">Parent toggles expanded: {{ expanded }}</HuiButton>
<HuiParagraph
v-model:expanded="expanded"
:ellipsis="{
rows: 2,
expandable: true,
collapsible: true,
suffix: '— Always visible suffix'
}"
show-overflow-tooltip
expand-text="Read more"
collapse-text="Collapse text"
style="max-width:360px"
@expand="lastEvent = 'expand: ' + $event"
@ellipsis="truncated = $event"
>{{ text }}</HuiParagraph
>
<p>{{ lastEvent }}; actually truncated: {{ truncated }}; expanded: {{ expanded }}</p>
</div>
<div>
<HuiParagraph
:expanded="false"
:ellipsis="{ rows: 2, expandable: true, collapsible: true }"
style="max-width:360px"
@update:expanded="refused = JSON.stringify($event)"
>{{ text }}</HuiParagraph
>
<p>Parent rejects updates; last request: {{ refused }}</p>
</div>
<HuiParagraph :ellipsis="{ rows: 2, suffix: '— Short paragraph suffix' }"
>A short paragraph.</HuiParagraph
>
</HuiSpace>
</template>
Typography Props
No props. Applies a shared font, color, and line height to its contents.
Title Props
| Prop | Type | Default | Description |
|---|---|---|---|
| level | 1 | 2 | 3 | 4 | 5 | 1 | Heading level |
| type | 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'secondary' | 'default' | Heading color type |
| bold | boolean | false | Whether bold |
| italic | boolean | false | Whether italic |
| underline | boolean | false | Whether underlined |
| deleted | boolean | false | Whether struck through |
| mark | boolean | false | Whether highlighted |
| code | boolean | false | Whether styled as code |
| copyable | boolean | false | Whether copyable |
| ellipsis | boolean | false | Whether to truncate overflowing text |
| showOverflowTooltip | boolean | false | Shows the full body on hover only when ellipsis is enabled and content is actually truncated. |
Text Props
| Prop | Type | Default | Description |
|---|---|---|---|
| type | 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'secondary' | 'default' | Text color type |
| size | 'xs' | 'sm' | 'base' | 'lg' | 'xl' | 'base' | Text size: xs 12px, sm 13px, base 14px, lg 16px, xl 20px |
| bold | boolean | false | Whether bold |
| italic | boolean | false | Whether italic |
| underline | boolean | false | Whether underlined |
| deleted | boolean | false | Whether struck through |
| mark | boolean | false | Whether highlighted |
| code | boolean | false | Whether styled as code |
| copyable | boolean | false | Whether copyable |
| ellipsis | boolean | false | Whether to truncate overflowing text |
| showOverflowTooltip | boolean | false | Shows the full body on hover only when ellipsis is enabled and content is actually truncated. |
Paragraph Props
| Prop | Type | Default | Description |
|---|---|---|---|
| type | 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'secondary' | 'default' | Paragraph color type |
| size | 'xs' | 'sm' | 'base' | 'lg' | 'xl' | 'base' | Paragraph size: xs 12px, sm 13px, base 14px, lg 16px, xl 20px |
| bold | boolean | false | Whether bold |
| italic | boolean | false | Whether italic |
| underline | boolean | false | Whether underlined |
| deleted | boolean | false | Whether struck through |
| mark | boolean | false | Whether highlighted |
| code | boolean | false | Whether styled as code |
| copyable | boolean | false | Whether copyable |
| ellipsis | boolean | TypographyEllipsisConfig | false | Line count, expansion, collapse, and suffix configuration. |
| showOverflowTooltip | boolean | false | Shows the full body on hover when multiline content is actually truncated. |
| expanded | boolean | undefined | Controlled when present, including undefined displayed as false; supports v-model:expanded. |
| expandText | string | Localized Expand | Expand label; an empty string overrides the localized default. |
| collapseText | string | Localized Collapse | Collapse label; an empty string overrides the localized default. |
Events (Title, Text, and Paragraph)
| Event | Parameters | Description |
|---|---|---|
| copy | (text: string) | Emitted after a successful copy |
Paragraph also emits:
| Event | Parameters | Description |
|---|---|---|
| update:expanded | (expanded: boolean) | Requests expansion before expand; still emitted when the parent rejects the update. |
| expand | (expanded: boolean) | Requested expanded or collapsed state. |
| ellipsis | (truncated: boolean) | Actual truncation changes; no initial false when content fits. |
Slots
| Slot | Description |
|---|---|
| default | Heading, text, or paragraph content |
Types
Public types use the component prefix. Compatibility mappings are TitleLevel → TypographyTitleLevel, TextSize → TypographyTextSize, and EllipsisConfig → TypographyEllipsisConfig. The old names remain importable from @nscode/handy-ui, are marked @deprecated, and will be removed in 1.0.
import type {
TitleProps,
TextProps,
ParagraphProps,
ParagraphEmits,
TypographyEllipsisConfig,
TypographyTitleLevel,
TypographyType,
TypographyTextSize
} from '@nscode/handy-ui'
interface TypographyEllipsisConfig {
rows: number
expandable?: boolean
collapsible?: boolean
suffix?: string
}