Components
ChatMessage
Unstable: one turn of a conversation, the person's or the assistant's, with its sender named in text, and ChatLog, the live region that holds them. Import them from @nizivo/react/unstable/chat-message.
Examples
Basic
A turn each way in a log: the person's request, then the assistant's answer.
import type { JSX } from 'react';
import { ChatLog, ChatMessage } from '@nizivo/react/unstable/chat-message';
export function ChatMessageExample(): JSX.Element {
return (
<ChatLog style={{ maxInlineSize: 560 }}>
<ChatMessage from="user" time={<time dateTime="09:41">09:41</time>}>
Tag the mug and candle on yesterday’s posts, then publish.
</ChatMessage>
<ChatMessage from="assistant" sender="Nizivo AI" time={<time dateTime="09:41">09:41</time>}>
Done — both products are tagged. The post is now shoppable at /mossandkiln.
</ChatMessage>
</ChatLog>
);
}
Import
import { ChatLog, ChatMessage } from '@nizivo/react/unstable/chat-message';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/chat-message.css';Static or interactive
Server. No client JavaScript. How to choose.
Turns
from is user (a bg/brand bubble at the end of the line) or assistant (bg/muted at the start,
after the sparkles mark, which avatar replaces). Under the bubble, sender ("You" or "Assistant"
by default) and time name who wrote it and when: never only the side or the colour.
The log
Put the turns in a ChatLog: role="log", a polite live region named "Conversation", so a screen
reader reads each new turn as it is added. For an answer that streams, use a
ResponseBlock inside it, which is read once, when complete.
Props
ChatLog
Server component Renders data-slot="chat-log" with the class nz-chat-log. Props: ChatLogProps. Source: src/unstable/chat-message/chat-message.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
labels | Partial<ChatLogLabels> | – | |
render | RenderProp<Record<string, never>> | – | Must render a |
- Also takes every attribute of
<div>exceptrole. (Omit<ComponentPropsWithRef<"div">, "role">)
render takes an element, or, in client code, a function of the props and no state.
ChatMessage
Server component Renders data-slot="chat-message" with the class nz-chat-message. Props: ChatMessageProps. Source: src/unstable/chat-message/chat-message.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
avatar | ReactNode | – | Replaces the assistant's sparkles mark, for example an Avatar. |
fromrequired | "user" | "assistant" | – | Whose turn it is. |
labels | Partial<ChatMessageLabels> | – | |
render | RenderProp<Record<string, never>> | – | Must render a |
sender | ReactNode | – | Names the sender. Replaces |
time | ReactNode | – | When it was sent, after the sender: a |
- Also takes every attribute of
<div>exceptrole. (Omit<ComponentPropsWithRef<"div">, "role">)
render takes an element, or, in client code, a function of the props and no state.
Other exports
ChatLogLabelstypeimport type { ChatLogLabels } from '@nizivo/react/unstable/chat-message'ChatLog's own strings (§16.4): serialisable, English defaults.
Name Type Default Description labelrequiredstring'Conversation'The log's name, unless the consumer names it.
ChatLogPropstypeimport type { ChatLogProps } from '@nizivo/react/unstable/chat-message'The props of
ChatLog, listed above.ChatMessageLabelstypeimport type { ChatMessageLabels } from '@nizivo/react/unstable/chat-message'ChatMessage's own strings (§16.4): serialisable, English defaults.
Name Type Default Description assistantrequiredstring'Assistant'The assistant's turns, unless
senderis given.userrequiredstring'You'The person's turns, unless
senderis given.ChatMessagePropstypeimport type { ChatMessageProps } from '@nizivo/react/unstable/chat-message'The props of
ChatMessage, 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 |
|---|---|---|
chat-log.nz-chat-log | ChatLogroot (takes render) | none |
chat-message.nz-chat-message | ChatMessageroot (takes render) |
|
chat-message-bubble.nz-chat-message-bubble | ChatMessageinner element (CSS only) | none |
chat-message-meta.nz-chat-message-meta | ChatMessageinner 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.
This stylesheet reads no public hook.
Layers: nz.components. Classes: .nz-chat-log, .nz-chat-message, .nz-chat-message-avatar, .nz-chat-message-body, .nz-chat-message-bubble, .nz-chat-message-meta.
Tokens this stylesheet reads (14)
--nz-bg-brand, --nz-bg-muted, --nz-font-body-m, --nz-font-body-s, --nz-radius-full, --nz-radius-xs, --nz-size-icon-sm, --nz-space-1-5, --nz-space-3, --nz-space-4, --nz-space-8, --nz-text-on-brand, --nz-text-primary, --nz-text-secondary
Accessibility
Nothing in this component takes focus or keyboard input.
Keyboard
None.
CaretHeadline
Unstable: a headline that ends in a blinking underscore caret, which stays on under Reduced motion. Import it from @nizivo/react/unstable/caret-headline.
Checkbox
A native checkbox with its label, including the indeterminate (mixed) state. It submits with the form before hydration; inside a Field it is labelled, described and validated by the Field.