import { Meta, StoryFn } from '@storybook/react-vite'; import { useState, useCallback } from 'react'; import { Chat, SessionMessages, ChatInput, SessionMessagePanel, Session, MentionItem, SlashCommandItem } from 'reachat'; import { fakeSessions, createSendMessageHandler } from './examples'; const UserIcon = () => ( ); const CommandIcon = () => ( ); const HelpIcon = () => ( ); const ClearIcon = () => ( ); const ImageIcon = () => ( ); export default { title: 'Demos/Enhanced Input', component: ChatInput } as Meta; const sampleUsers: MentionItem[] = [ { id: '1', label: 'John Doe', description: 'Engineering', icon: }, { id: '2', label: 'Jane Smith', description: 'Design', icon: }, { id: '3', label: 'Bob Wilson', description: 'Product', icon: }, { id: '4', label: 'Alice Brown', description: 'Marketing', icon: }, { id: '5', label: 'Charlie Davis', description: 'Sales', icon: } ]; const sampleCommands: SlashCommandItem[] = [ { id: 'help', label: 'help', description: 'Show available commands', icon: , shortcut: '?' }, { id: 'clear', label: 'clear', description: 'Clear the conversation', icon: }, { id: 'image', label: 'image', description: 'Generate an image', icon: , type: 'action' }, { id: 'code', label: 'code', description: 'Insert a code block', icon: , type: 'insert', value: '```\n\n```' }, { id: 'summarize', label: 'summarize', description: 'Summarize the conversation', icon: } ]; export const WithMentions: StoryFn = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState(fakeSessions); return (
); }; export const WithSlashCommands: StoryFn = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState(fakeSessions); const handleCommandSelect = useCallback( (item: SlashCommandItem, insertText: (text: string) => void) => { if (item.type === 'action') { console.log('Executing action:', item.label); insertText(''); } else if (item.value) { insertText(item.value); } }, [] ); return (
); }; export const WithAllFeatures: StoryFn = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState(fakeSessions); const handleCommandSelect = useCallback( (item: SlashCommandItem, insertText: (text: string) => void) => { if (item.type === 'action') { console.log('Executing action:', item.label); insertText(''); } else if (item.value) { insertText(item.value); } }, [] ); return (
); }; export const WithAsyncSearch: StoryFn = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState(fakeSessions); const searchUsers = useCallback(async (query: string): Promise => { await new Promise(resolve => setTimeout(resolve, 500)); const filtered = sampleUsers.filter( user => user.label.toLowerCase().includes(query.toLowerCase()) || user.description?.toLowerCase().includes(query.toLowerCase()) ); return filtered; }, []); return (
( No users found matching "{query}" ) }} />
); }; export const MultiLineEmpty: StoryFn = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState(fakeSessions); return (
); }; export const MultiLineWithContent: StoryFn = () => { const [activeId, setActiveId] = useState(fakeSessions[0].id); const [sessions, setSessions] = useState(fakeSessions); const defaultMultiLineText = `This is line one of the input. This is line two of the input. This is line three of the input. This is line four of the input. This is line five - you should scroll to see this. This is line six - still scrolling!`; return (
); };