Basic feature implemented, very basic poc
This commit is contained in:
parent
216089a3e7
commit
48c0067076
118 changed files with 2113 additions and 20 deletions
28
app/javascript/controllers/theme_switcher_controller.js
Normal file
28
app/javascript/controllers/theme_switcher_controller.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
import Cookie from "../lib/cookies"
|
||||
|
||||
// Connects to data-controller="theme-switcher"
|
||||
export default class extends Controller {
|
||||
COOKIE_NAME = "modeTheme"
|
||||
|
||||
connect() {
|
||||
console.log("connect switcher")
|
||||
}
|
||||
|
||||
switch() {
|
||||
const cookieValue = Cookie.get(this.COOKIE_NAME);
|
||||
const newThemeValue = cookieValue == "dark" ? "light" : "dark";
|
||||
|
||||
Cookie.set("modeTheme", newThemeValue);
|
||||
window.document.getElementsByTagName("html")[0].setAttribute("data-bs-theme", newThemeValue);
|
||||
|
||||
const icon = this.element.getElementsByTagName("i")[0];
|
||||
if(newThemeValue == "dark") {
|
||||
icon.classList.remove("bi-sun-fill")
|
||||
icon.classList.add("bi-moon-stars-fill")
|
||||
} else {
|
||||
icon.classList.add("bi-sun-fill")
|
||||
icon.classList.remove("bi-moon-stars-fill")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue