blob: 48337157bdf50fe7cbc7b7ee958cb5016980f4bc [file] [log] [blame]
banksean2be768e2025-07-18 16:41:39 +00001/* eslint-disable @typescript-eslint/no-explicit-any */
2/**
3 * Demo module for sketch-diff-range-picker component
4 */
5
6import { DemoModule } from "./demo-framework/types";
7import { demoUtils } from "./demo-fixtures/index";
8import { MockGitDataService } from "./mock-git-data-service";
9
10const demo: DemoModule = {
11 title: "Diff Range Picker Demo",
12 description: "Component for selecting commit ranges for diff views",
13 imports: ["../sketch-diff-range-picker"],
14
15 setup: async (container: HTMLElement) => {
16 // Create demo sections
17 const basicSection = demoUtils.createDemoSection(
18 "Basic Range Picker",
19 "Select commit ranges for diff views with dropdown interface",
20 );
21
22 const statusSection = demoUtils.createDemoSection(
23 "Range Selection Status",
24 "Shows the currently selected range and events",
25 );
26
27 // Create mock git service
28 const mockGitService = new MockGitDataService();
29
30 // Create the component
31 const rangePickerElement = document.createElement(
32 "sketch-diff-range-picker",
33 );
34 rangePickerElement.style.cssText = `
35 width: 100%;
36 max-width: 800px;
37 margin: 20px 0;
38 padding: 16px;
39 border: 1px solid #e0e0e0;
40 border-radius: 8px;
41 background: white;
42 `;
43
44 // Set up the git service
45 (rangePickerElement as any).gitService = mockGitService;
46
47 // Create status display
48 const statusDisplay = document.createElement("div");
49 statusDisplay.style.cssText = `
50 padding: 12px;
51 margin: 16px 0;
banksean1ee0bc62025-07-22 23:24:18 +000052 background: var(--demo-fixture-section-bg);
banksean2be768e2025-07-18 16:41:39 +000053 border-radius: 6px;
54 border: 1px solid #e9ecef;
55 font-family: monospace;
56 font-size: 14px;
57 line-height: 1.4;
58 `;
59 statusDisplay.innerHTML = `
60 <div><strong>Status:</strong> No range selected</div>
61 <div><strong>Events:</strong> None</div>
62 `;
63
64 // Listen for range change events
65 rangePickerElement.addEventListener("range-change", (event: any) => {
66 const range = event.detail.range;
67 const fromShort = range.from ? range.from.substring(0, 7) : "N/A";
68 const toShort = range.to ? range.to.substring(0, 7) : "Uncommitted";
69
70 statusDisplay.innerHTML = `
71 <div><strong>Status:</strong> Range selected</div>
72 <div><strong>From:</strong> ${fromShort}</div>
73 <div><strong>To:</strong> ${toShort}</div>
74 <div><strong>Events:</strong> range-change fired at ${new Date().toLocaleTimeString()}</div>
75 `;
76 });
77
78 // Add components to sections
79 basicSection.appendChild(rangePickerElement);
80 statusSection.appendChild(statusDisplay);
81
82 // Add sections to container
83 container.appendChild(basicSection);
84 container.appendChild(statusSection);
85
86 // Add some demo instructions
87 const instructionsDiv = document.createElement("div");
88 instructionsDiv.style.cssText = `
89 margin: 20px 0;
90 padding: 16px;
banksean1ee0bc62025-07-22 23:24:18 +000091 background: var(--demo-instruction-bg);
banksean2be768e2025-07-18 16:41:39 +000092 border-radius: 6px;
93 border-left: 4px solid #2196f3;
94 `;
95 instructionsDiv.innerHTML = `
96 <h3 style="margin: 0 0 8px 0; color: #1976d2;">Demo Instructions:</h3>
97 <ul style="margin: 8px 0; padding-left: 20px;">
98 <li>Click on the dropdown to see available commits</li>
99 <li>Select different commits to see range changes</li>
100 <li>The component defaults to diffing against uncommitted changes</li>
101 <li>Watch the status display for real-time event updates</li>
102 </ul>
103 `;
104 container.appendChild(instructionsDiv);
105 },
106
107 cleanup: () => {
108 // Clean up any event listeners or resources if needed
109 console.log("Cleaning up sketch-diff-range-picker demo");
110 },
111};
112
113export default demo;