Text sets a piece of text in one of the typography roles and one of the text colours, on the element the caller's document needs.
When to use
Use Text to set words in one typography role and one text colour, on the element the document needs, such as a heading, a caption or a time.
| Use instead | When |
|---|---|
| Link | The words take the reader to another page or place |
| Section | A small heading in capitals names a group of content inside a panel |
| Stat | A key figure stands large with the words that say what it counts |
| Delay | The words say how late or early a vehicle runs, in the delay's colour |
| Kbd | The text is a key of the keyboard, inside help text |
| Tag | A word or two on a pill marks a property of what it sits beside |
Kongens Nytorv
Metro M1, M2 and M3.
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
Variants and states
| Rest | |
|---|---|
| Body | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Display | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Heading lg | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Heading md | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Heading sm | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Body sm | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Caption | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Label | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Label sm | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Overline | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Badge | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Stat | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Data xl | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Data lg | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Data | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Data sm | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Neutral | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Brand | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Success | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Warning | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Danger | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
| Info | Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned. |
- Rest
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- Rest
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- RestSignal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- Rest
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- Rest
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- Rest
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- Rest
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- Rest
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
- Rest
Signal fault at Danshøj. Trains between Flintholm and Ny Ellebjerg run slower than planned.
Props
| Name | Type | Default | Description |
|---|---|---|---|
variant | 'body' | 'display' | 'heading-lg' | 'heading-md' | 'heading-sm' | 'body-sm' | 'caption' | 'label' | 'label-sm' | 'overline' | 'badge' | 'stat' | 'data-xl' | 'data-lg' | 'data' | 'data-sm' | 'body' | The typography role, one per job, as Typography gives them: data roles for anything compared down a column, overline set in capitals. All sixteen roles, spelled as their tokens are, with 'body' first and the default: it is the role perron.css sets on the page body. |
color | 'neutral' | 'brand' | 'success' | 'warning' | 'danger' | 'info' | 'neutral' | The intent: what the colour means. neutral is main text; brand is emphasis on the hero page, never a link; the status intents say on time, warning, late or info, always beside words that say it too, such as "Late" or "+4 min": colour is never the only sign. All six intents, each with its color.text.* token, default 'neutral' (color.text.primary) rather than inheriting: every intent has a text token measured at 4.5:1, and text on an inverse or coloured fill is the fill's own component's text, not a Text. |
emphasis | 'primary' | 'secondary' | 'tertiary' | 'primary' | How strongly neutral text stands out: primary for what people read first, secondary for supporting text, tertiary for hints and captions next to stronger text. Changes nothing with any other color. A prop of Text's own, for color.text.secondary and color.text.tertiary, which are no intent and so can't be color values; its values are the tokens' own names. |
children | ReactNode | — | The text: a string, an element such as <strong> or <time>, or a list of both. |
className | string | — | Joined after pn-Text on the root. |
style | CSSProperties | — | Merged onto the root. |
ref | Ref<HTMLElement> | — | Reaches the root element, whichever element render makes it. |
variant'body' | 'display' | 'heading-lg' | 'heading-md' | 'heading-sm' | 'body-sm' | 'caption' | 'label' | 'label-sm' | 'overline' | 'badge' | 'stat' | 'data-xl' | 'data-lg' | 'data' | 'data-sm', default'body'- The typography role, one per job, as Typography gives them:
dataroles for anything compared down a column,overlineset in capitals. All sixteen roles, spelled as their tokens are, with'body'first and the default: it is the roleperron.csssets on the page body. color'neutral' | 'brand' | 'success' | 'warning' | 'danger' | 'info', default'neutral'- The intent: what the colour means.
neutralis main text;brandis emphasis on the hero page, never a link; the status intents say on time, warning, late or info, always beside words that say it too, such as "Late" or "+4 min": colour is never the only sign. All six intents, each with itscolor.text.*token, default'neutral'(color.text.primary) rather than inheriting: every intent has a text token measured at 4.5:1, and text on an inverse or coloured fill is the fill's own component's text, not a Text. emphasis'primary' | 'secondary' | 'tertiary', default'primary'- How strongly neutral text stands out:
primaryfor what people read first,secondaryfor supporting text,tertiaryfor hints and captions next to stronger text. Changes nothing with any othercolor. A prop of Text's own, forcolor.text.secondaryandcolor.text.tertiary, which are no intent and so can't becolorvalues; its values are the tokens' own names. childrenReactNode, default —- The text: a string, an element such as
<strong>or<time>, or a list of both. classNamestring, default —- Joined after
pn-Texton the root. styleCSSProperties, default —- Merged onto the root.
refRef<HTMLElement>, default —- Reaches the root element, whichever element
rendermakes it.
Use it
import { Text } from '@mylder/perron'Ask your agent
search_docs({ query: "Text" })Keyboard and ARIA
From the useRender reference. "From" says who does it: Base UI, or Perron.
| Key | Does | From |
|---|---|---|
| None | Text is not interactive: it never takes focus or a key. | none |
| Element | Role | Accessible name from | States announced |
|---|---|---|---|
root | The element's own: paragraph for <p>, generic for <span>, heading for an h element from render | Its own text, read in place; a heading from render is named by its children | None |
What axe won't catch, from the contract, each with how this component meets it:
- Everything the eye is told, the ear is told, for every shape each prop accepts: the text itself is what both are told; a status
coloris never the only sign, so the caller's words say it (CR-8), andoverline's capitals are styling over sentence-case source text, read as written. - Every landmark and named region has an accessible name: none here; Text makes no landmark or region.
- Every default label can be overridden: none here; Text owns no strings.
- Every shape the type accepts renders, in every variant:
childrenis aReactNode; theRichContentstory gives a list of a string and a<time>element, and every other story a string. - A hidden copy kept for animation is
aria-hidden, and a collapsed region isinert: none here; Text keeps no hidden copy and collapses nothing. - Native semantics first:
<p>for sentences,<span>for the rest, and the caller's own element throughrender:<h2>for a heading,<time>for a time. No ARIA. - Focus moves in reading order and returns on close: none here; Text takes no focus and opens nothing.
- Every target is at least
size.target-minsquare: none here; Text is no target. - Loops stop when the system asks for less motion: none here; Text has no animation.
Owned strings
No owned strings: every word comes from the caller, as children.
Do and don't
For a caller using the component, with the reason. Each row is a rule: a must row's Don't is never right, a should row's needs a reason, and Checked by says what catches the Don't in a caller's code.
| Rule | Level | Do | Don't | Checked by |
|---|---|---|---|---|
| DD-1 | must | Give a heading role its heading element through render, at its level in the page's outline: render={<h2 />}. | Set a heading's look on a <span>: a screen reader's list of headings never finds it. | review |
| DD-2 | must | Say a status in words beside its colour: color='danger' on "+4 min late". | Let red or green be the only sign, which fails 1.4.1 and every rider who can't tell them apart. | review |
| DD-3 | must | Keep emphasis='tertiary' for hints and captions next to stronger text. | Set a sentence people must read in tertiary: it misses 4.5:1 on purpose. | review |
| DD-4 | should | Set times, countdowns, counts and delays in a data role, so their tabular figures line up down a column. | Set a time in body, where each digit has its own width and a column of times wobbles. | review |
| DD-5 | must | Write an overline's text in sentence case and let the role set the capitals. | Type the capitals: a screen reader may spell them out letter by letter. | review |
| DD-6 | must | Keep color='brand' for emphasis on the hero page. | Use brand text for a link, or anything that looks like one. | review |
| DD-7 | should | Leave badge to line badges, the job its role was made for. | Set other text in badge: its line height of 1 crowds a second line against the first. | review |
| DD-8 | should | Restyle through className, with the tokens. | Reach for a raw size or colour in style, which leaves the theme and the scale behind. | review |