Heading
A heading whose outline level (h1 to h6) and look (the heading text style) are set independently.
Import
import { Heading } from '@nizivo/react/heading';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/heading.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
Good morning, Asha
Revenue
No orders yet
import type { JSX } from 'react';
import { Heading } from '@nizivo/react/heading';
export function HeadingExample(): JSX.Element {
return (
<div>
<Heading level={1}>Good morning, Asha</Heading>
{/* The outline level and the look are independent: an <h2> drawn as Heading/H4. */}
<Heading level={2} variant="heading-h4">
Revenue
</Heading>
<Heading level={3} tone="secondary">
No orders yet
</Heading>
</div>
);
}
Props
Server component Renders data-slot="heading" with the class nz-heading. Props: HeadingProps. Source: src/heading/heading.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
levelrequired | HeadingLevel123456 | – | Required: the outline level decides the element, never the look. |
render | RenderProp<HeadingState> | – | |
tone | TextTone"primary""secondary""tertiary""disabled""inverse""on-brand""on-accent""on-critical""brand""accent""success""warning""critical""info" | – | A |
variant | HeadingVariant"display-l""display-m""heading-h1""heading-h2""heading-h3""heading-h4" | the style named after the level, and `heading-h4` for levels 5 and 6 (Figma has no H5 or H6) | The text style, independent of |
- Also takes every attribute of
<h2>. (ComponentPropsWithRef<"h2">)
render takes an element, or, in client code, a function of the props and this state (HeadingState):
| Name | Type | Default | Description |
|---|---|---|---|
levelrequired | HeadingLevel123456 | – | |
tonerequired | TextTone | undefined"primary""secondary""tertiary""disabled""inverse""on-brand""on-accent""on-critical""brand""accent""success""warning""critical""info" | – | |
variantrequired | HeadingVariant"display-l""display-m""heading-h1""heading-h2""heading-h3""heading-h4" | – |
Other exports
HeadingLeveltypeimport type { HeadingLevel } from '@nizivo/react/heading'The document outline level:
<h1>to<h6>.type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6HeadingPropstypeimport type { HeadingProps } from '@nizivo/react/heading'The props of
Heading, listed above.HeadingStatetypeimport type { HeadingState } from '@nizivo/react/heading'The render state of
Heading, listed above.HeadingVarianttypeimport type { HeadingVariant } from '@nizivo/react/heading'The Figma display and heading text styles.
type HeadingVariant = "display-l" | "display-m" | "heading-h1" | "heading-h2" | "heading-h3" | "heading-h4"
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 |
|---|---|---|
heading.nz-heading | Headingroot (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-heading.
Tokens this stylesheet reads (25)
--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-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-display-l, --nz-tracking-display-m, --nz-tracking-heading-h1, --nz-tracking-heading-h2, --nz-tracking-heading-h3, --nz-tracking-heading-h4
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