대시보드 카드 on/off 토글 추가, 페이지 추가

This commit is contained in:
2025-06-11 22:54:01 +09:00
parent d3c6deaf96
commit f4d12c87eb
14 changed files with 532 additions and 68 deletions

View File

@@ -15,3 +15,6 @@ application.register("sidebar", SidebarController)
import TimerController from "./timer_controller"
application.register("timer", TimerController)
import ToggleController from "./toggle_controller"
application.register("toggle", ToggleController)

View File

@@ -5,6 +5,7 @@ import { useClickOutside } from 'stimulus-use'
export default class extends Controller {
connect() {
// useClickOutside(this)
console.log("modal stimulus")
this.boundHandleKeydown = this.handleKeydown.bind(this)
document.addEventListener("keydown", this.boundHandleKeydown)
window.addEventListener('modals:close', this.close.bind(this))

View File

@@ -0,0 +1,40 @@
// controllers/toggle_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["label", "dot", "background"]
connect() {
this.state = true
this.update()
}
toggle() {
this.state = !this.state
this.update()
}
update() {
if (this.state) {
this.labelTarget.textContent = "ON"
this.labelTarget.classList.add("text-notice")
this.labelTarget.classList.remove("text-gray-400")
this.dotTarget.classList.add("bg-notice")
this.dotTarget.classList.remove("bg-gray-400")
// this.backgroundTarget.classList.add("bg-on-content")
// this.backgroundTarget.classList.remove("bg-off-content")
} else {
this.labelTarget.textContent = "OFF"
this.labelTarget.classList.add("text-gray-400")
this.labelTarget.classList.remove("text-notice")
this.dotTarget.classList.add("bg-gray-400")
this.dotTarget.classList.remove("bg-notice")
// this.backgroundTarget.classList.add("bg-off-content")
// this.backgroundTarget.classList.remove("bg-on-content")
}
}
}