import { Meta } from '@storybook/react-vite'; import { Chat, SessionMessages, ChatInput, SessionMessagePanel, SessionMessage, Session, AppBar } from 'reachat'; import { fakeSessions, legacyConversationSessions, sessionWithSources, sessionsWithFiles, createSendMessageHandler } from './examples'; import { useState } from 'react'; import Placeholder from './assets/placeholder.svg?react'; import PlaceholderDark from './assets/placeholder-dark.svg?react'; import ReachatLogo from './assets/logo.svg?react'; import IconSearch from './assets/search.svg?react'; import IconClose from './assets/close-fill.svg?react'; import { IconButton } from 'reablocks'; export default { title: 'Demos/Chat', component: Chat } as Meta; export const Compact = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState([ ...fakeSessions, ...sessionsWithFiles, ...sessionWithSources ]); return (
{ const newId = (sessions.length + 1).toLocaleString(); setSessions([ ...sessions, { id: newId, title: `New Session #${newId}`, createdAt: new Date(), updatedAt: new Date(), messages: [] } ]); setActiveId(newId); }} onSelectSession={setActiveId} onDeleteSession={() => alert('delete!')} onSendMessage={createSendMessageHandler(setSessions, activeId)} >
); }; export const FullScreen = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState([ ...fakeSessions, ...sessionsWithFiles, ...sessionWithSources ]); return (
{ const newId = (sessions.length + 1).toLocaleString(); setSessions([ ...sessions, { id: newId, title: `New Session #${newId}`, createdAt: new Date(), updatedAt: new Date(), messages: [] } ]); setActiveId(newId); }} onSelectSession={setActiveId} onDeleteSession={() => alert('delete!')} onSendMessage={createSendMessageHandler(setSessions, activeId)} >
); }; export const Empty = () => { const [activeId, setActiveId] = useState(); const [sessions, setSessions] = useState([]); return (
{ const newId = (sessions.length + 1).toLocaleString(); setSessions([ ...sessions, { id: newId, title: `New Session #${newId}`, createdAt: new Date(), updatedAt: new Date(), messages: [] } ]); setActiveId(newId); }} onSelectSession={setActiveId} onDeleteSession={() => alert('delete!')} onSendMessage={createSendMessageHandler(setSessions, activeId)} >

Welcome to Reachat, a UI library for effortlessly building and customizing chat experiences with Tailwind.

} > {messages => messages.map((message, index) => ( )) } ); }; export const WithAppBar = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState([ ...fakeSessions, ...sessionsWithFiles, ...sessionWithSources ]); return (
{ const newId = (sessions.length + 1).toLocaleString(); setSessions([ ...sessions, { id: newId, title: `New Session #${newId}`, createdAt: new Date(), updatedAt: new Date(), messages: [] } ]); setActiveId(newId); }} onSelectSession={setActiveId} onDeleteSession={() => alert('delete!')} onSendMessage={createSendMessageHandler(setSessions, activeId)} >
} />
); }; /** * Backwards compatibility: sessions that still use the deprecated * `conversations` field are converted to messages internally, so legacy * data keeps rendering without any changes. */ export const LegacyConversations = () => { const [activeId, setActiveId] = useState( legacyConversationSessions[0].id ); const [sessions, setSessions] = useState( legacyConversationSessions ); return (
alert('delete!')} onSendMessage={message => setSessions(prev => prev.map(session => session.id === activeId ? { ...session, conversations: [ ...session.conversations, { id: Date.now().toString(), question: message, response: 'This is a response to your question.', createdAt: new Date() } ] } : session ) ) } >
); };