Basic setup, launch config and layout
This commit is contained in:
parent
535a051755
commit
1a3d172fe5
41 changed files with 382 additions and 105 deletions
|
|
@ -6,3 +6,6 @@ import { application } from "./application"
|
|||
|
||||
import HelloController from "./hello_controller"
|
||||
application.register("hello", HelloController)
|
||||
|
||||
import SetThemeController from "./set_theme_controller"
|
||||
application.register("set-theme", SetThemeController)
|
||||
|
|
|
|||
18
app/javascript/controllers/set_theme_controller.js
Normal file
18
app/javascript/controllers/set_theme_controller.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
import Cookie from "../lib/cookies"
|
||||
|
||||
// Connects to data-controller="set-theme"
|
||||
export default class extends Controller {
|
||||
COOKIE_NAME = "modeTheme";
|
||||
|
||||
connect() {
|
||||
const cookieValue = Cookie.get(this.COOKIE_NAME);
|
||||
console.log("cookieValue", cookieValue);
|
||||
if(cookieValue) {
|
||||
return true;
|
||||
}
|
||||
const darkMode = window.matchMedia("(prefers-color-scheme:dark)").matches ? "dark" : "light";
|
||||
Cookie.set(this.COOKIE_NAME, darkMode);
|
||||
window.document.getElementsByTagName("html")[0].setAttribute("data-bs-theme", darkMode)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue