blob: f70f72f556da623c66beb0b63b8e4d24bc71c3ac [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 );
banksean3d1308e2025-07-29 17:20:10 +000033 rangePickerElement.className = `
34 w-full max-w-3xl my-5 p-4 border border-gray-300 dark:border-gray-600
35 rounded-lg bg-white dark:bg-gray-800
banksean2be768e2025-07-18 16:41:39 +000036 `;
37
38 // Set up the git service
39 (rangePickerElement as any).gitService = mockGitService;
40
41 // Create status display
42 const statusDisplay = document.createElement("div");
banksean3d1308e2025-07-29 17:20:10 +000043 statusDisplay.className = `
44 p-3 my-4 bg-gray-50 dark:bg-gray-800 rounded border
45 border-gray-200 dark:border-gray-700 font-mono text-sm leading-relaxed
banksean2be768e2025-07-18 16:41:39 +000046 `;
47 statusDisplay.innerHTML = `
48 <div><strong>Status:</strong> No range selected</div>
49 <div><strong>Events:</strong> None</div>
50 `;
51
52 // Listen for range change events
53 rangePickerElement.addEventListener("range-change", (event: any) => {
54 const range = event.detail.range;
55 const fromShort = range.from ? range.from.substring(0, 7) : "N/A";
56 const toShort = range.to ? range.to.substring(0, 7) : "Uncommitted";
57
58 statusDisplay.innerHTML = `
59 <div><strong>Status:</strong> Range selected</div>
60 <div><strong>From:</strong> ${fromShort}</div>
61 <div><strong>To:</strong> ${toShort}</div>
62 <div><strong>Events:</strong> range-change fired at ${new Date().toLocaleTimeString()}</div>
63 `;
64 });
65
66 // Add components to sections
67 basicSection.appendChild(rangePickerElement);
68 statusSection.appendChild(statusDisplay);
69
70 // Add sections to container
71 container.appendChild(basicSection);
72 container.appendChild(statusSection);
73
74 // Add some demo instructions
75 const instructionsDiv = document.createElement("div");
banksean3d1308e2025-07-29 17:20:10 +000076 instructionsDiv.className = `
77 my-5 p-4 bg-blue-50 dark:bg-blue-900/20 rounded
78 border-l-4 border-blue-500 dark:border-blue-400
banksean2be768e2025-07-18 16:41:39 +000079 `;
80 instructionsDiv.innerHTML = `
81 <h3 style="margin: 0 0 8px 0; color: #1976d2;">Demo Instructions:</h3>
82 <ul style="margin: 8px 0; padding-left: 20px;">
83 <li>Click on the dropdown to see available commits</li>
84 <li>Select different commits to see range changes</li>
85 <li>The component defaults to diffing against uncommitted changes</li>
86 <li>Watch the status display for real-time event updates</li>
87 </ul>
88 `;
89 container.appendChild(instructionsDiv);
90 },
91
92 cleanup: () => {
93 // Clean up any event listeners or resources if needed
94 console.log("Cleaning up sketch-diff-range-picker demo");
95 },
96};
97
98export default demo;