1import { Controller } from "@hotwired/stimulus" 2 3export default class extends Controller { 4 static targets = ["sunIcon", "moonIcon"] 5 6 connect() { 7 this.loadTheme() 8 } 9 10 toggle() { 11 const isDark = document.documentElement.classList.toggle("dark") 12 localStorage.setItem("theme", isDark ? "dark" : "light") 13 this.updateIcon(isDark) 14 } 15 16 loadTheme() { 17 const savedTheme = localStorage.getItem("theme") 18 const isDark = savedTheme === "dark" 19 20 if (isDark) { 21 document.documentElement.classList.add("dark") 22 } else { 23 document.documentElement.classList.remove("dark") 24 } 25 this.updateIcon(isDark) 26 } 27 28 updateIcon(isDark) { 29 if (this.hasSunIconTarget && this.hasMoonIconTarget) { 30 if (isDark) { 31 this.sunIconTarget.classList.remove("hidden") 32 this.moonIconTarget.classList.add("hidden") 33 } else { 34 this.sunIconTarget.classList.add("hidden") 35 this.moonIconTarget.classList.remove("hidden") 36 } 37 } 38 } 39}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.