| banksean | ae3724e | 2025-07-18 16:52:37 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Demo module for theme-toggle component |
| 3 | */ |
| 4 | |
| 5 | import { DemoModule } from "./demo-framework/types"; |
| 6 | import { demoUtils } from "./demo-fixtures/index"; |
| 7 | import { ThemeService } from "../theme-service.js"; |
| 8 | |
| 9 | const demo: DemoModule = { |
| 10 | title: "Theme Toggle Demo", |
| 11 | description: |
| 12 | "Three-way theme toggle: light mode, dark mode, and system preference", |
| 13 | imports: ["../sketch-theme-toggle"], |
| 14 | styles: ["/dist/tailwind.css"], |
| 15 | |
| 16 | setup: async (container: HTMLElement) => { |
| 17 | // Initialize the theme service |
| 18 | const themeService = ThemeService.getInstance(); |
| 19 | themeService.initializeTheme(); |
| 20 | // Create demo sections |
| 21 | const basicSection = demoUtils.createDemoSection( |
| 22 | "Three-Way Theme Toggle", |
| 23 | "Click the toggle button to cycle through: light → dark → system → light", |
| 24 | ); |
| 25 | |
| 26 | const toggleContainer = document.createElement("div"); |
| 27 | toggleContainer.className = |
| 28 | "flex items-center gap-4 p-4 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700"; |
| 29 | toggleContainer.innerHTML = ` |
| 30 | <sketch-theme-toggle></sketch-theme-toggle> |
| 31 | <div class="text-sm text-gray-600 dark:text-gray-400"> |
| 32 | <div class="font-medium mb-1">Theme modes:</div> |
| 33 | <div class="space-y-1"> |
| 34 | <div>☀️ Light mode - Always light theme</div> |
| 35 | <div>🌙 Dark mode - Always dark theme</div> |
| 36 | <div>💻 System theme - Follows OS preference</div> |
| 37 | </div> |
| 38 | </div> |
| 39 | `; |
| 40 | basicSection.appendChild(toggleContainer); |
| 41 | |
| 42 | // Visual test elements section |
| 43 | const visualSection = demoUtils.createDemoSection( |
| 44 | "Visual Test Elements", |
| 45 | "Elements that demonstrate the theme switching behavior", |
| 46 | ); |
| 47 | |
| 48 | const visualContainer = document.createElement("div"); |
| 49 | visualContainer.className = "space-y-4"; |
| 50 | visualContainer.innerHTML = ` |
| 51 | <div class="bg-white dark:bg-gray-800 p-4 rounded border border-gray-200 dark:border-gray-600"> |
| 52 | <h4 class="font-medium text-gray-900 dark:text-gray-100 mb-2">Test Card</h4> |
| 53 | <p class="text-gray-600 dark:text-gray-300"> |
| 54 | This card should switch between light and dark styling when you toggle the theme. |
| 55 | </p> |
| 56 | </div> |
| 57 | |
| 58 | <div class="flex gap-3"> |
| 59 | <button class="px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded transition-colors"> |
| 60 | Primary Button |
| 61 | </button> |
| 62 | <button class="px-4 py-2 bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 rounded transition-colors"> |
| 63 | Secondary Button |
| 64 | </button> |
| 65 | </div> |
| 66 | |
| 67 | <div class="grid grid-cols-3 gap-4"> |
| 68 | <div class="bg-white dark:bg-gray-800 p-3 rounded border border-gray-200 dark:border-gray-600"> |
| 69 | <div class="text-sm font-medium text-gray-900 dark:text-gray-100">Light Background</div> |
| 70 | <div class="text-xs text-gray-500 dark:text-gray-400">Should be dark in dark mode</div> |
| 71 | </div> |
| 72 | <div class="bg-gray-100 dark:bg-gray-800 p-3 rounded border border-gray-200 dark:border-gray-600"> |
| 73 | <div class="text-sm font-medium text-gray-900 dark:text-gray-100">Gray Background</div> |
| 74 | <div class="text-xs text-gray-500 dark:text-gray-400">Should be darker in dark mode</div> |
| 75 | </div> |
| 76 | <div class="bg-gray-200 dark:bg-gray-700 p-3 rounded border border-gray-200 dark:border-gray-600"> |
| 77 | <div class="text-sm font-medium text-gray-900 dark:text-gray-100">Darker Background</div> |
| 78 | <div class="text-xs text-gray-500 dark:text-gray-400">Should be lighter in dark mode</div> |
| 79 | </div> |
| 80 | </div> |
| 81 | `; |
| 82 | visualSection.appendChild(visualContainer); |
| 83 | |
| 84 | // Features section |
| 85 | const featuresSection = demoUtils.createDemoSection( |
| 86 | "Features", |
| 87 | "Key capabilities of the theme toggle component", |
| 88 | ); |
| 89 | |
| 90 | const featuresContainer = document.createElement("div"); |
| 91 | featuresContainer.className = |
| 92 | "bg-blue-50 dark:bg-blue-900/20 p-6 rounded-lg border border-blue-200 dark:border-blue-800"; |
| 93 | featuresContainer.innerHTML = ` |
| 94 | <ul class="space-y-2 text-sm text-blue-800 dark:text-blue-200"> |
| 95 | <li>• Three-way toggle: light → dark → system → light</li> |
| 96 | <li>• Icons: ☀️ (light), 🌙 (dark), 💻 (system)</li> |
| 97 | <li>• System mode follows OS dark/light preference</li> |
| 98 | <li>• Theme preference persists across page reloads</li> |
| 99 | <li>• Emits theme-changed events for component coordination</li> |
| 100 | <li>• Smooth transitions between themes</li> |
| 101 | <li>• Uses localStorage for preference storage</li> |
| 102 | </ul> |
| 103 | `; |
| 104 | featuresSection.appendChild(featuresContainer); |
| 105 | |
| 106 | // Add all sections to container |
| 107 | container.appendChild(basicSection); |
| 108 | container.appendChild(visualSection); |
| 109 | container.appendChild(featuresSection); |
| 110 | }, |
| 111 | |
| 112 | cleanup: async () => { |
| 113 | // Clean up any event listeners or resources if needed |
| 114 | // The theme toggle component handles its own cleanup |
| 115 | }, |
| 116 | }; |
| 117 | |
| 118 | export default demo; |