diff --git a/src/App.svelte b/src/App.svelte index 9f52c9a..bc686a3 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -7,6 +7,8 @@ let searchQuery = ''; let logos = []; let filteredLogos = []; + let theme = 'system'; + let mq; // Load logos from JSON file with cache busting onMount(async () => { @@ -32,8 +34,25 @@ } catch (error) { console.error('Error loading logos:', error); } + + const stored = localStorage.getItem('theme'); + if (stored === 'light' || stored === 'dark' || stored === 'system') { + theme = stored; + } + applyTheme(); + + // Listen for system theme changes if using system + mq = window.matchMedia('(prefers-color-scheme: dark)'); + mq.addEventListener('change', () => { + if (theme === 'system') applyTheme(); + }); }); + $: { + console.log('[theme] reactive theme:', theme); + applyTheme(); + } + $: { filteredLogos = logos.filter(logo => logo.name.toLowerCase().includes(searchQuery.toLowerCase()) @@ -69,39 +88,52 @@ link.click(); document.body.removeChild(link); } + + function applyTheme() { + let effectiveTheme = theme; + if (theme === 'system') { + effectiveTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; + } + document.documentElement.setAttribute('data-theme', effectiveTheme); + console.log('[theme] theme:', theme, 'effectiveTheme:', effectiveTheme); + } + + function setTheme(newTheme) { + theme = newTheme; + localStorage.setItem('theme', newTheme); + console.log('[theme] setTheme:', newTheme); + applyTheme(); + }
-
-

Logo Gallery

-

Collection of company and brand logos for your projects

- -
diff --git a/src/components/LogoGrid.svelte b/src/components/LogoGrid.svelte index 914c289..f5708c6 100644 --- a/src/components/LogoGrid.svelte +++ b/src/components/LogoGrid.svelte @@ -52,25 +52,23 @@