diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index 1138116..018a35a 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -1,10 +1,20 @@ - + Métro Travel @@ -44,6 +54,38 @@ À propos + + + + Theme + + + + + + OS Default + + + + + + Dark + + + + + + Light + + + + diff --git a/src/components/ThemeIcon.vue b/src/components/ThemeIcon.vue new file mode 100644 index 0000000..8a2be84 --- /dev/null +++ b/src/components/ThemeIcon.vue @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + diff --git a/src/handle-theme.js b/src/handle-theme.js index 8646a4b..e8bb1ea 100644 --- a/src/handle-theme.js +++ b/src/handle-theme.js @@ -2,12 +2,18 @@ const darkModeMedia = window.matchMedia('(prefers-color-scheme: dark)'); darkModeMedia.addEventListener('change', setTheme); -function setTheme() { - const theme = darkModeMedia.matches ? 'dark' : 'light'; - document.documentElement.setAttribute('data-theme', theme); - document.documentElement.setAttribute('data-bs-theme', theme); +export function setTheme(theme) { + const realTheme = theme === 'auto' ? (darkModeMedia.matches ? 'dark' : 'light') : theme; + document.documentElement.setAttribute('data-theme', realTheme); + document.documentElement.setAttribute('data-bs-theme', realTheme); + localStorage.setItem('theme', theme); } export function initTheme() { - setTheme(); + const theme = localStorage.getItem('theme') || 'auto'; + setTheme(theme); +} + +export function getCurrentTheme() { + return localStorage.getItem('theme') || 'light'; } diff --git a/src/map.js b/src/map.js index 1745c0a..403d4c5 100644 --- a/src/map.js +++ b/src/map.js @@ -20,7 +20,7 @@ class ParisMap { this.#arrondissements = arrondissements; this.#stations = stations; this.#lines = lines; - this.#svg = d3.select('svg'); + this.#svg = d3.select('svg#carte'); this.#remove(); this.#g = this.#svg.append('g'); this.#arrondissementsNode = this.#g.append('g');