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