Text
Body, label, numeric and mono text in the Nizivo text styles and text colours, as a paragraph or any element through render.
Import
import { Text } from '@nizivo/react/text';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/text.css';Static or interactive
Server. It ships no client JavaScript when a Server Component renders it, in every Next.js build
mode; its code is bundled only when a client component (a 'use client' file) imports it. How to
choose.
In a client app (a Vite or React Router single-page app, or a 'use client' file) it is an ordinary React component: event handlers, refs and state work as usual. In a client app.
Tones
tone="accent" is deprecated: it paints --nz-text-brand, exactly as tone="brand" does, since
Figma has no accent text for page surfaces (M38). Use tone="brand". It keeps working, with no
visual change; its removal is deferred to 1.0, or to when Figma adds an accent text for page
surfaces. Accent text on bg/inverse is --nz-text-inverse-accent. Card's and KpiTile's
tone="accent", a surface rather than a text colour, is not deprecated.
Examples
Basic
Shown on product pages and checkout.
No action needed.
₹4,82,190Updated 2 min agoSKU-1040import type { JSX } from 'react';
import { Text } from '@nizivo/react/text';
export function TextExample(): JSX.Element {
return (
<div>
<Text>Shown on product pages and checkout.</Text>
<Text variant="body-m" tone="secondary">
No action needed.
</Text>
<Text variant="numeric-kpi" tone="primary" render={<span />}>
₹4,82,190
</Text>
<Text variant="label-s" tone="tertiary" render={<span />}>
Updated 2 min ago
</Text>
<Text variant="mono-m" tone="secondary" render={<code />}>
SKU-1040
</Text>
</div>
);
}
Props
Server component Renders data-slot="text" with the class nz-text. Props: TextProps. Source: src/text/text.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
render | RenderProp<TextState> | – | Another element or component, for example |
tone | TextTone"primary""secondary""tertiary""disabled""inverse""on-brand""on-accent""on-critical""brand""accent""success""warning""critical""info" | – | A |
variant | TextVariant"display-l""display-m""heading-h1""heading-h2""heading-h3""heading-h4""body-l""body-m""body-m-strong""body-s""label-l""label-m""label-m-strong""label-s""numeric-display""numeric-kpi""numeric-l""numeric-m""mono-m""mono-m-strong" | 'body-m' | The text style. 12 px exists only as |
- Also takes every attribute of
<p>. (ComponentPropsWithRef<"p">)
render takes an element, or, in client code, a function of the props and this state (TextState):
| Name | Type | Default | Description |
|---|---|---|---|
tonerequired | TextTone | undefined"primary""secondary""tertiary""disabled""inverse""on-brand""on-accent""on-critical""brand""accent""success""warning""critical""info" | – | |
variantrequired | TextVariant"display-l""display-m""heading-h1""heading-h2""heading-h3""heading-h4""body-l""body-m""body-m-strong""body-s""label-l""label-m""label-m-strong""label-s""numeric-display""numeric-kpi""numeric-l""numeric-m""mono-m""mono-m-strong" | – |
Other exports
TextPropstypeimport type { TextProps } from '@nizivo/react/text'The props of
Text, listed above.TextStatetypeimport type { TextState } from '@nizivo/react/text'The render state of
Text, listed above.TextTonetypeimport type { TextTone } from '@nizivo/react/text'The
text/*colour tokens.accentpaints--nz-text-brand, since Figma has no accent text for page surfaces (M38;--nz-text-inverse-accentis forbg/inverse).Deprecated:
'accent', which looks exactly like'brand'; use'brand'. It keeps working; its removal is deferred to 1.0, or to when Figma adds an accent text for page surfaces (M42). TypeScript cannot deprecate one member of a union type, so this note is the marker. Card's and KpiTile'stone="accent", a surface, are not deprecated.type TextTone = "primary" | "secondary" | "tertiary" | "disabled" | "inverse" | "on-brand" | "on-accent" | "on-critical" | "brand" | "accent" | "success" | "warning" | "critical" | "info"TextVarianttypeimport type { TextVariant } from '@nizivo/react/text'The Figma text styles as lowercase names (
Nizivo/Label/M→label-m), plus the 12 px proposals.type TextVariant = "display-l" | "display-m" | "heading-h1" | "heading-h2" | "heading-h3" | "heading-h4" | "body-l" | "body-m" | "body-m-strong" | "body-s" | "label-l" | "label-m" | "label-m-strong" | "label-s" | "numeric-display" | "numeric-kpi" | "numeric-l" | "numeric-m" | "mono-m" | "mono-m-strong"
Data attributes and slots
Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.
| Slot | Rendered by | Data attributes |
|---|---|---|
text.nz-text | Textroot (takes render) |
|
CSS hooks
Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.
This stylesheet reads no public hook.
Layers: nz.components. Classes: .nz-text.
Tokens this stylesheet reads (53)
--nz-font-body-l, --nz-font-body-m, --nz-font-body-m-strong, --nz-font-body-s, --nz-font-display-l, --nz-font-display-m, --nz-font-heading-h1, --nz-font-heading-h2, --nz-font-heading-h3, --nz-font-heading-h4, --nz-font-label-l, --nz-font-label-m, --nz-font-label-m-strong, --nz-font-label-s, --nz-font-mono-m, --nz-font-mono-m-strong, --nz-font-numeric-display, --nz-font-numeric-kpi, --nz-font-numeric-l, --nz-font-numeric-m, --nz-text-brand, --nz-text-critical, --nz-text-disabled, --nz-text-info, --nz-text-inverse, --nz-text-on-accent, --nz-text-on-brand, --nz-text-on-critical, --nz-text-primary, --nz-text-secondary, --nz-text-success, --nz-text-tertiary, --nz-text-warning, --nz-tracking-body-l, --nz-tracking-body-m, --nz-tracking-body-m-strong, --nz-tracking-body-s, --nz-tracking-display-l, --nz-tracking-display-m, --nz-tracking-heading-h1, --nz-tracking-heading-h2, --nz-tracking-heading-h3, --nz-tracking-heading-h4, --nz-tracking-label-l, --nz-tracking-label-m, --nz-tracking-label-m-strong, --nz-tracking-label-s, --nz-tracking-mono-m, --nz-tracking-mono-m-strong, --nz-tracking-numeric-display, --nz-tracking-numeric-kpi, --nz-tracking-numeric-l, --nz-tracking-numeric-m
Accessibility
Nothing in this component takes focus or keyboard input.
Keyboard
None.
Figma
Node ids from design/component-map.json, which nz gen writes from component.json. The links open the Nizivo Figma library, which may ask you to sign in.
- Canonical: none
- Ghost masters: none
Tabs
In-page views of one subject, one panel at a time, as WAI-ARIA tabs. Only the selected panel is rendered, on the server too; keepMounted keeps a panel's state while it is hidden. When each view is a URL, use TabNav; to pick a range or a value, use SegmentedControl.
Textarea
A multi-line native text area, at least 112 px tall, that grows with its content where the browser supports field-sizing and can be resized vertically. Inside a Field it is labelled, described and validated by the Field.