| philip.zeyliger | 26bc659 | 2025-06-30 20:15:30 -0700 | [diff] [blame] | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
| Sean McCullough | b379592 | 2025-06-27 01:59:41 +0000 | [diff] [blame] | 2 | /** |
| 3 | * Demo fixture for sketch-chat-input component |
| 4 | */ |
| 5 | |
| 6 | import { DemoModule } from "./demo-framework/types"; |
| 7 | import { demoUtils } from "./demo-fixtures/index"; |
| 8 | |
| 9 | const demo: DemoModule = { |
| 10 | title: "Chat Input Component", |
| 11 | description: "Chat input with file upload and drag-and-drop support", |
| 12 | imports: ["../sketch-chat-input"], |
| 13 | |
| 14 | setup: async (container: HTMLElement) => { |
| 15 | // Create demo sections |
| 16 | const basicSection = demoUtils.createDemoSection( |
| 17 | "Basic Chat Input", |
| 18 | "Type a message and press Enter or click Send. Supports file drag-and-drop.", |
| 19 | ); |
| 20 | |
| 21 | const messagesSection = demoUtils.createDemoSection( |
| 22 | "Chat Messages", |
| 23 | "Sent messages will appear here", |
| 24 | ); |
| 25 | |
| 26 | // Create messages display |
| 27 | const messagesDiv = document.createElement("div"); |
| 28 | messagesDiv.id = "chat-messages"; |
| 29 | messagesDiv.className = |
| 30 | "min-h-[100px] max-h-[200px] overflow-y-auto border border-gray-300 rounded-md p-3 mb-3 bg-gray-50"; |
| 31 | |
| 32 | // Create chat input |
| 33 | const chatInput = document.createElement("sketch-chat-input") as any; |
| 34 | |
| 35 | // Add message display function |
| 36 | const addMessage = ( |
| 37 | message: string, |
| 38 | isUser: boolean = true, |
| 39 | timestamp?: Date, |
| 40 | ) => { |
| 41 | const messageDiv = document.createElement("div"); |
| 42 | messageDiv.className = `p-2 my-1 rounded max-w-xs ${ |
| 43 | isUser |
| 44 | ? "bg-blue-500 text-white ml-auto" |
| 45 | : "bg-gray-200 text-gray-900 mr-auto" |
| 46 | }`; |
| 47 | |
| 48 | const timeStr = timestamp |
| 49 | ? timestamp.toLocaleTimeString() |
| 50 | : new Date().toLocaleTimeString(); |
| 51 | messageDiv.innerHTML = ` |
| 52 | <div class="text-sm">${message}</div> |
| 53 | <div class="text-xs opacity-70 mt-1">${timeStr}</div> |
| 54 | `; |
| 55 | |
| 56 | messagesDiv.appendChild(messageDiv); |
| 57 | messagesDiv.scrollTop = messagesDiv.scrollHeight; |
| 58 | }; |
| 59 | |
| 60 | // Handle send events |
| 61 | chatInput.addEventListener("send-chat", (evt: any) => { |
| 62 | const message = evt.detail.message; |
| 63 | if (message.trim()) { |
| 64 | addMessage(message, true); |
| 65 | |
| 66 | // Simulate bot response after a delay |
| 67 | setTimeout(() => { |
| 68 | const responses = [ |
| 69 | "Message received!", |
| 70 | "Thanks for sharing that.", |
| 71 | "I see you uploaded a file.", |
| 72 | "Processing your request...", |
| 73 | "How can I help you further?", |
| 74 | ]; |
| 75 | const randomResponse = |
| 76 | responses[Math.floor(Math.random() * responses.length)]; |
| 77 | addMessage(randomResponse, false); |
| 78 | }, 1500); |
| 79 | } |
| 80 | }); |
| 81 | |
| 82 | // Add initial messages |
| 83 | addMessage("Welcome to the chat input demo!", false); |
| 84 | addMessage("Try typing a message or dragging files here.", false); |
| 85 | |
| 86 | // Control buttons |
| 87 | const controlsDiv = document.createElement("div"); |
| 88 | controlsDiv.className = "mt-4 space-x-2"; |
| 89 | |
| 90 | const clearButton = demoUtils.createButton("Clear Chat", () => { |
| 91 | messagesDiv.innerHTML = ""; |
| 92 | addMessage("Chat cleared!", false); |
| 93 | }); |
| 94 | |
| 95 | const presetButton = demoUtils.createButton("Load Sample Message", () => { |
| 96 | chatInput.content = |
| 97 | "I need help with implementing a file upload feature. Can you review the attached screenshot?"; |
| 98 | }); |
| 99 | |
| 100 | const multilineButton = demoUtils.createButton("Multiline Message", () => { |
| 101 | chatInput.content = |
| 102 | "Here's a multiline message:\n\n1. First point\n2. Second point\n3. Third point\n\nWhat do you think?"; |
| 103 | }); |
| 104 | |
| 105 | controlsDiv.appendChild(clearButton); |
| 106 | controlsDiv.appendChild(presetButton); |
| 107 | controlsDiv.appendChild(multilineButton); |
| 108 | |
| 109 | // File upload status section |
| 110 | const statusSection = demoUtils.createDemoSection( |
| 111 | "Upload Status", |
| 112 | "Current upload status and file handling", |
| 113 | ); |
| 114 | |
| 115 | const statusDiv = document.createElement("div"); |
| 116 | statusDiv.className = |
| 117 | "bg-blue-50 border border-blue-200 rounded p-3 text-sm"; |
| 118 | statusDiv.innerHTML = ` |
| 119 | <div>✓ Drag and drop files onto the chat input</div> |
| 120 | <div>✓ Paste images from clipboard</div> |
| 121 | <div>✓ Multiple file uploads supported</div> |
| 122 | <div>✓ Upload progress indication</div> |
| 123 | `; |
| 124 | |
| 125 | statusSection.appendChild(statusDiv); |
| 126 | |
| 127 | // Assemble the demo |
| 128 | messagesSection.appendChild(messagesDiv); |
| 129 | basicSection.appendChild(chatInput); |
| 130 | basicSection.appendChild(controlsDiv); |
| 131 | |
| 132 | container.appendChild(messagesSection); |
| 133 | container.appendChild(basicSection); |
| 134 | container.appendChild(statusSection); |
| 135 | }, |
| 136 | }; |
| 137 | |
| 138 | export default demo; |