InlineError
One error look for fields and data widgets: icon + text, never colour alone. Not a live region.
Import
import { InlineError } from '@nizivo/react/inline-error';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/inline-error.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.
Examples
Basic
import type { JSX } from 'react';
import { Button } from '@nizivo/react/button';
import { InlineError } from '@nizivo/react/inline-error';
/** Stands in for an `@nizivo/icons` glyph (Lucide circle-x). */
function ErrorMark(): JSX.Element {
return (
<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor">
<circle cx="12" cy="12" r="10" />
</svg>
);
}
export function InlineErrorExample(): JSX.Element {
return (
<div>
<InlineError icon={<ErrorMark />}>Enter a price above zero.</InlineError>
<InlineError
icon={<ErrorMark />}
action={
<Button size="sm" variant="tertiary">
Retry
</Button>
}
>
Couldn’t load revenue.
</InlineError>
</div>
);
}
Props
One error look for fields and data widgets: icon + text, never colour alone. Not a live region.
Server component Renders data-slot="inline-error" with the class nz-inline-error. Props: InlineErrorProps. Source: src/inline-error/inline-error.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
action | ReactNode | – | A recovery control after the message, for example |
icon | ReactNode | – | The error mark, decorative: the message carries the meaning, and the mark keeps the error from being colour-only (§15.1). Defaults to the internal |
render | RenderProp<Record<string, never>> | – |
- Also takes every attribute of
<div>. (ComponentPropsWithRef<"div">)
render takes an element, or, in client code, a function of the props and no state.
Other exports
InlineErrorPropstypeimport type { InlineErrorProps } from '@nizivo/react/inline-error'The props of
InlineError, listed above.
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 |
|---|---|---|
inline-error.nz-inline-error | InlineErrorroot (takes render) | none |
inline-error-action.nz-inline-error-action | InlineErrorinner element (CSS only) | none |
inline-error-icon.nz-inline-error-icon | InlineErrorinner element (CSS only) | none |
inline-error-message.nz-inline-error-message | InlineErrorinner element (CSS only) | none |
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.
| Hook | Default | Read as |
|---|---|---|
--nz-inline-error-fg | --nz-text-critical |
|
--nz-inline-error-font | --nz-font-body-m |
|
--nz-inline-error-gap | --nz-space-1-5 |
|
--nz-inline-error-icon-fg | --nz-icon-critical |
|
Layers: nz.components. Classes: .nz-inline-error, .nz-inline-error-action, .nz-inline-error-icon.
Tokens this stylesheet reads (5)
--nz-font-body-m, --nz-icon-critical, --nz-size-icon-sm, --nz-space-1-5, --nz-text-critical
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