Skip to content
Klarhimmel UI

Agent chat

What can you change for me?
Reading your opening hours
npx shadcn add https://ui.klarhimmel.com/r/agent-chat.json https://ui.klarhimmel.com/r/chat-composer.json

Examples

  • Full

  • Chat start basic

DetailsAbout, usage, props and more

The chat every Klarhimmel app uses: an empty start with suggestions, the person's message as a bubble on the right, the reply as plain rich text with quiet actions, a small loader, the newest message scrolled to the top, and ChatComposer.

Preview

Where do we start?

Answers can be wrong.

agent-chat.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { ChatThread, ChatMessage, MessageActions } from '@/components/klarhimmel/ui/agent-chat';
import { ChatComposer } from '@/components/klarhimmel/ui/chat-composer';

export default function Example() {
  return (
    <Theme theme="brand">
      <ChatThread anchor="m2" composer={<ChatComposer label="Message" value="" onChange={() => {}} onSend={() => {}} />}>
        <ChatMessage from="user">What can you change for me?</ChatMessage>
        <ChatMessage from="assistant" actions={<MessageActions copyText="Your opening hours and menu." onRetry={() => {}} />}>
          <p>Your <strong>opening hours</strong> and menu.</p>
        </ChatMessage>
      </ChatThread>
    </Theme>
  );
}

Import

Import

import { ChatStart, ChatThread, ChatMessage, MessageActions, ChatLoader, ChatComposer } from '@/components/klarhimmel/ui/agent-chat';
Files
agent-chat.tsx, agent-chat.css, chat-composer.tsx, in components/klarhimmel/ui/. With it: menu, theme, utils. npm: lucide-react.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
ChatStart.greetingReactNoderequired
ChatStart.childrenReactNoderequiredThe ChatComposer.
ChatStart.suggestions{ label: string; icon?: ReactNode; onSelect: () => void }[][]Up to four: each fills or sends a first message.
ChatStart.classNamestring-Extra classes, merged after the component's own.
ChatThread.childrenReactNoderequired
ChatThread.composerReactNode-The ChatComposer, at the bottom of the view.
ChatThread.anchorstring | number-Changes on each send: the id of the newest user message.
ChatThread.scroll'page' | 'inner''page'page: scrolls with the page (default). inner: its own scroll area (give it a height), scrollbar hidden.
ChatThread.jumpLabelstring'Scroll to the bottom'
ChatThread.classNamestring-Extra classes, merged after the component's own.
ChatMessage.from'user' | 'assistant'required
ChatMessage.childrenReactNoderequired
ChatMessage.actionsReactNode-user: a bubble on the right. assistant: plain rich text (headings, bold, lists, code), its MessageActions under it.
ChatMessage.classNamestring-Extra classes, merged after the component's own.
MessageActions.rating'good' | 'bad' | null-The person's rating, so the pressed thumb stays pressed.
MessageActions.onRate(rating: 'good' | 'bad' | null) => void-
MessageActions.onRetry() => void-
MessageActions.copyTextstring-The reply as text: Copy copies it and says Copied.
MessageActions.more{ label: string; onSelect: () => void; danger?: boolean }[]-
MessageActions.labelsPartial<MessageActionsLabels>-
ChatLoader.labelstring'Answering'
ChatLoader.classNamestring-Extra classes, merged after the component's own.
ChatLoader.livebooleantrueThe Klarhimmel mark rising over its horizon where the reply will start; the label is for screen readers only. live: false inside a role=log, so it is not a second live region.
ChatComposer.labelstringrequiredRequired: names the text box (not shown).
ChatComposer.valuestringrequired
ChatComposer.onChange(value: string) => voidrequired
ChatComposer.onSend(text: string) => voidrequiredEnter or the send button, with text that may be sent. The app clears `value`.
ChatComposer.placeholderstring-
ChatComposer.busyboolean-An answer is streaming: send becomes stop (or a quiet Working without onStop). Typing goes on.
ChatComposer.onStop() => void-