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
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
| messages | Message[] | Yes | - | Message feed data. |
| assistantName | string | No | - | Assistant label in assistant messages. |
| defaultMessage | string | No | '' | Empty-state assistant message. |
| isLoading | boolean | No | false | Appends loading assistant row. |
| loadingText | string | No | 'typing' | Loading indicator text. |
| loadingVariant | 'text-and-dots' | 'dots-only' | No | 'text-and-dots' | Loading indicator style. |
| className | string | No | '' | Root class override. |
| searchQuery | string | No | - | Highlight query string. |
| activeSearchMessageId | string | No | - | Auto-scroll target message id. |
| onAddContext | (context: Context) => void | No | - | Adds selected snippet to context panel. |
| scrollRef | React.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.