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