blob: a65cb82505399575d6130a7ae6cc2c6777f42df9 [file] [log] [blame]
bankseancdb08a52025-07-02 20:28:29 +00001/* eslint-disable @typescript-eslint/no-explicit-any */
2/**
3 * Demo module for sketch-todo-panel component
4 */
5
6import { DemoModule } from "./demo-framework/types";
7import { demoUtils } from "./demo-fixtures/index";
8
9// Sample todo data
10const sampleTodoList = {
11 items: [
12 {
13 id: "task-1",
14 status: "completed" as const,
15 task: "Convert sketch-todo-panel.ts to inherit from SketchTailwindElement",
16 },
17 {
18 id: "task-2",
19 status: "in-progress" as const,
20 task: "Test the converted element to ensure it works correctly",
21 },
22 {
23 id: "task-3",
24 status: "queued" as const,
25 task: "Add unit tests for the todo panel component",
26 },
27 {
28 id: "task-4",
29 status: "queued" as const,
30 task: "Update documentation with new implementation details",
31 },
32 ],
33};
34
35const largeTodoList = {
36 items: [
37 {
38 id: "task-1",
39 status: "completed" as const,
40 task: "Implement authentication system with JWT tokens",
41 },
42 {
43 id: "task-2",
44 status: "completed" as const,
45 task: "Set up database migrations and schema",
46 },
47 {
48 id: "task-3",
49 status: "in-progress" as const,
50 task: "Build responsive dashboard with real-time updates and complex data visualization components",
51 },
52 {
53 id: "task-4",
54 status: "queued" as const,
55 task: "Add file upload functionality with drag and drop support",
56 },
57 {
58 id: "task-5",
59 status: "queued" as const,
60 task: "Implement comprehensive test suite including unit, integration, and end-to-end tests",
61 },
62 {
63 id: "task-6",
64 status: "queued" as const,
65 task: "Deploy to production environment with monitoring and logging",
66 },
67 {
68 id: "task-7",
69 status: "queued" as const,
70 task: "Create user documentation and API guides",
71 },
72 ],
73};
74
75const demo: DemoModule = {
76 title: "Todo Panel Demo",
77 description:
78 "Interactive todo list panel showing task progress and allowing comments",
79 imports: ["../sketch-todo-panel"],
80 styles: ["/dist/tailwind.css"],
81
82 setup: async (container: HTMLElement) => {
83 // Create demo sections
84 const basicSection = demoUtils.createDemoSection(
85 "Basic Todo Panel",
86 "Shows a typical todo list with different task statuses",
87 );
88
89 const statesSection = demoUtils.createDemoSection(
90 "Different States",
91 "Loading, error, and empty states",
92 );
93
94 const largeListSection = demoUtils.createDemoSection(
95 "Large Todo List",
96 "Scrollable list with longer task descriptions",
97 );
98
99 // Basic todo panel with sample data
100 const basicPanel = document.createElement("sketch-todo-panel") as any;
101 basicPanel.id = "basic-panel";
102 basicPanel.visible = true;
103 basicPanel.style.cssText =
104 "height: 300px; border: 1px solid #e0e0e0; display: block;";
105
106 // Set the data after a short delay to show it populating
107 setTimeout(() => {
108 basicPanel.updateTodoContent(JSON.stringify(sampleTodoList));
109 }, 100);
110
111 // Loading state panel
112 const loadingPanel = document.createElement("sketch-todo-panel") as any;
113 loadingPanel.id = "loading-panel";
114 loadingPanel.visible = true;
115 loadingPanel.loading = true;
116 loadingPanel.style.cssText =
117 "height: 150px; border: 1px solid #e0e0e0; display: block; margin-right: 10px; flex: 1;";
118
119 // Error state panel
120 const errorPanel = document.createElement("sketch-todo-panel") as any;
121 errorPanel.id = "error-panel";
122 errorPanel.visible = true;
123 errorPanel.error = "Failed to load todo data";
124 errorPanel.style.cssText =
125 "height: 150px; border: 1px solid #e0e0e0; display: block; margin-right: 10px; flex: 1;";
126
127 // Empty state panel
128 const emptyPanel = document.createElement("sketch-todo-panel") as any;
129 emptyPanel.id = "empty-panel";
130 emptyPanel.visible = true;
131 emptyPanel.updateTodoContent("");
132 emptyPanel.style.cssText =
133 "height: 150px; border: 1px solid #e0e0e0; display: block; flex: 1;";
134
135 // Large list panel
136 const largePanel = document.createElement("sketch-todo-panel") as any;
137 largePanel.id = "large-panel";
138 largePanel.visible = true;
139 largePanel.style.cssText =
140 "height: 400px; border: 1px solid #e0e0e0; display: block;";
141 largePanel.updateTodoContent(JSON.stringify(largeTodoList));
142
143 // Create states container
144 const statesContainer = document.createElement("div");
145 statesContainer.style.cssText = "display: flex; gap: 10px; margin: 10px 0;";
146 statesContainer.appendChild(loadingPanel);
147 statesContainer.appendChild(errorPanel);
148 statesContainer.appendChild(emptyPanel);
149
150 // Add state labels
151 const loadingLabel = document.createElement("div");
152 loadingLabel.textContent = "Loading State";
153 loadingLabel.style.cssText =
154 "font-weight: bold; margin-bottom: 8px; flex: 1; text-align: center;";
155
156 const errorLabel = document.createElement("div");
157 errorLabel.textContent = "Error State";
158 errorLabel.style.cssText =
159 "font-weight: bold; margin-bottom: 8px; flex: 1; text-align: center;";
160
161 const emptyLabel = document.createElement("div");
162 emptyLabel.textContent = "Empty State";
163 emptyLabel.style.cssText =
164 "font-weight: bold; margin-bottom: 8px; flex: 1; text-align: center;";
165
166 const labelsContainer = document.createElement("div");
167 labelsContainer.style.cssText =
168 "display: flex; gap: 10px; margin-bottom: 5px;";
169 labelsContainer.appendChild(loadingLabel);
170 labelsContainer.appendChild(errorLabel);
171 labelsContainer.appendChild(emptyLabel);
172
173 // Add event listener for comment events
174 const eventLog = document.createElement("div");
175 eventLog.style.cssText =
176 "margin-top: 20px; padding: 10px; background: #f5f5f5; border-radius: 4px; font-family: monospace; font-size: 12px;";
177 eventLog.innerHTML =
178 "<strong>Event Log:</strong> (try clicking the 💬 button on in-progress or queued items)<br>";
179
180 const logEvent = (message: string) => {
181 const timestamp = new Date().toLocaleTimeString();
182 eventLog.innerHTML += `<div>[${timestamp}] ${message}</div>`;
183 eventLog.scrollTop = eventLog.scrollHeight;
184 };
185
186 // Listen for todo comment events
187 [basicPanel, largePanel].forEach((panel) => {
188 panel.addEventListener("todo-comment", (event: any) => {
189 logEvent(
190 `Todo comment received: "${event.detail.comment.substring(0, 50)}..."`,
191 );
192 });
193 });
194
195 // Assemble the demo
196 basicSection.appendChild(basicPanel);
197
198 statesSection.appendChild(labelsContainer);
199 statesSection.appendChild(statesContainer);
200
201 largeListSection.appendChild(largePanel);
202
203 container.appendChild(basicSection);
204 container.appendChild(statesSection);
205 container.appendChild(largeListSection);
206 container.appendChild(eventLog);
207 },
208
209 cleanup: () => {
210 // Remove any event listeners if needed
211 const panels = document.querySelectorAll("sketch-todo-panel");
212 panels.forEach((panel) => {
213 (panel as any).removeEventListener("todo-comment", () => {});
214 });
215 },
216};
217
218export default demo;