import { Trace } from '@precursor/chat';Example
You
What can I build?
brief.mdAssistant
Start with a theme and a few primitives. Foundations
Activity summary
Selected examples from the foundations guide.
Read guide Complete · 0.2 s
Found layout and theming examples.
'use client';
import { useId, useState } from 'react';
import {
Attachment,
ChatBubble,
ChatComposer,
ChatComposerActions,
ChatMessage,
ChatMessageAuthor,
ChatThread,
Citation,
ReasoningSummary,
Trace,
TraceStep,
} from '@precursor/chat';
import Button from '@precursor/button';
import Stack from '@precursor/stack';
import TextArea from '@precursor/textarea';
export default function Example() {
const id = useId();
const [draft, setDraft] = useState('');
const [messages, setMessages] = useState<string[]>([]);
return (
<Stack gap="s">
<ChatThread>
<ChatMessage variant="user">
<ChatMessageAuthor>You</ChatMessageAuthor>
<ChatBubble variant="accent">What can I build?</ChatBubble>
<Attachment>brief.md</Attachment>
</ChatMessage>
<ChatMessage>
<ChatMessageAuthor>Assistant</ChatMessageAuthor>
<ChatBubble>
Start with a theme and a few primitives.{' '}
<Citation href="https://danieldelcore.github.io/precursor/docs/foundations/">
Foundations
</Citation>
</ChatBubble>
<ReasoningSummary>
Selected examples from the foundations guide.
</ReasoningSummary>
<Trace>
<TraceStep
label="Read guide"
status="complete"
duration="0.2 s"
>
Found layout and theming examples.
</TraceStep>
</Trace>
</ChatMessage>
{messages.map((message, index) => (
<ChatMessage key={index} variant="user">
<ChatMessageAuthor>You</ChatMessageAuthor>
<ChatBubble variant="accent">{message}</ChatBubble>
</ChatMessage>
))}
</ChatThread>
<ChatComposer
onSubmit={() => {
if (draft.trim()) {
setMessages([...messages, draft.trim()]);
setDraft('');
}
}}
>
<label htmlFor={id}>Message</label>
<TextArea
id={id}
name="message"
value={draft}
onChange={(event) => setDraft(event.currentTarget.value)}
size="s"
/>
<ChatComposerActions>
<Button primary type="submit" disabled={!draft.trim()}>
Send
</Button>
</ChatComposerActions>
</ChatComposer>
</Stack>
);
}
Props
| Prop | Type | Default | Notes |
|---|---|---|---|
childrenRequired | ReactNode | — | — |
label | string | 'Tool activity' | — |