Skip to content
Get started

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.

Server component, no client JSUnstable

Examples

Basic

A turn each way in a log: the person's request, then the assistant's answer.

Tag the mug and candle on yesterday’s posts, then publish.
You ·
Done — both products are tagged. The post is now shoppable at /mossandkiln.
Nizivo AI ·
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.

NameTypeDefaultDescription
labelsPartial<ChatLogLabels>–
renderRenderProp<Record<string, never>>–

Must render a <div>.

  • Also takes every attribute of <div> except role. (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.

NameTypeDefaultDescription
avatarReactNode–

Replaces the assistant's sparkles mark, for example an Avatar.

fromrequired"user" | "assistant"–

Whose turn it is.

labelsPartial<ChatMessageLabels>–
renderRenderProp<Record<string, never>>–

Must render a <div>.

senderReactNode–

Names the sender. Replaces labels.user or labels.assistant.

timeReactNode–

When it was sent, after the sender: a <time> is best.

  • Also takes every attribute of <div> except role. (Omit<ComponentPropsWithRef<"div">, "role">)

render takes an element, or, in client code, a function of the props and no state.

Other exports

ChatLogLabels type

import type { ChatLogLabels } from '@nizivo/react/unstable/chat-message'

ChatLog's own strings (§16.4): serialisable, English defaults.

NameTypeDefaultDescription
labelrequiredstring'Conversation'

The log's name, unless the consumer names it.

ChatLogProps type

import type { ChatLogProps } from '@nizivo/react/unstable/chat-message'

The props of ChatLog, listed above.

ChatMessageLabels type

import type { ChatMessageLabels } from '@nizivo/react/unstable/chat-message'

ChatMessage's own strings (§16.4): serialisable, English defaults.

NameTypeDefaultDescription
assistantrequiredstring'Assistant'

The assistant's turns, unless sender is given.

userrequiredstring'You'

The person's turns, unless sender is given.

ChatMessageProps type

import 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.

SlotRendered byData attributes
chat-log
.nz-chat-log
ChatLog
root (takes render)
none
chat-message
.nz-chat-message
ChatMessage
root (takes render)
  • data-variant: "user""assistant"
    The variant prop; values in each component manifest
chat-message-bubble
.nz-chat-message-bubble
ChatMessage
inner element (CSS only)
none
chat-message-meta
.nz-chat-message-meta
ChatMessage
inner 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.

On this page