Component
Messages

MessageList

Standalone message stream rendering with loading, search highlighting, and optional context capture.

Full working example

The comments in this snippet show which props drive search, context capture, and scroll control.

Messages.tsx
import React from 'react';
import { MessageList } from '@jazzmine-ui/react';
import type { Context, Message } from '@jazzmine-ui/react';
import '@jazzmine-ui/react/styles';

export function Messages() {
  const [messages] = React.useState<Message[]>([
    {
      id: 'm-1',
      text: 'How do I reset my password?',
      sender: 'user',
      timestamp: new Date().toISOString(),
    },
    {
      id: 'm-2',
      text: 'Go to Settings > Account and choose Reset password.',
      sender: 'assistant',
      timestamp: new Date().toISOString(),
    },
  ]);
  const [selectedContexts, setSelectedContexts] = React.useState<Context[]>([]);
  const scrollRef = React.useRef<HTMLDivElement | null>(null);

  return (
    <div style={{ height: '60vh' }}>
      <MessageList
        messages={messages} /* Required: message feed data */
        assistantName="Support Assistant" /* Optional: assistant label */
        searchQuery="password" /* Optional: highlight text matches */
        activeSearchMessageId="m-2" /* Optional: focus target match by message id */
        scrollRef={scrollRef} /* Optional: external access to scroll container */
        onAddContext={(context) => {
          /* Optional: capture selected snippets for later send context */
          setSelectedContexts((prev) => [...prev, context]);
        }}
      />

      <pre>{JSON.stringify(selectedContexts, null, 2)}</pre>
    </div>
  );
}

MessageList props

PropTypeRequiredDefaultDescription
messagesMessage[]Yes-Message feed data.
assistantNamestringNo-Assistant label in assistant messages.
defaultMessagestringNo''Empty-state assistant message.
isLoadingbooleanNofalseAppends loading assistant row.
loadingTextstringNo'typing'Loading indicator text.
loadingVariant'text-and-dots' | 'dots-only'No'text-and-dots'Loading indicator style.
classNamestringNo''Root class override.
searchQuerystringNo-Highlight query string.
activeSearchMessageIdstringNo-Auto-scroll target message id.
onAddContext(context: Context) => voidNo-Adds selected snippet to context panel.
scrollRefReact.RefObject<HTMLDivElement | null> | ((node: HTMLDivElement | null) => void)No-External scroll node access.

Notes

onAddContext

Use onAddContext to capture snippets a user selects and forward them later through onSend(text, contexts?) in ChatInterface-style flows.

searchQuery + activeSearchMessageId

searchQuery highlights matching text, and activeSearchMessageId moves focus to a specific hit.

scrollRef

scrollRef gives your app direct access to the internal scroll container for custom behaviors like preserving position or jumping to anchor points.