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