- Implement theme switching functionality with a new ThemeController - Add ToastController for displaying notifications - Update various views for improved layout and styling - Introduce animations for toast notifications These changes enhance the user experience by allowing users to switch between light and dark themes and receive feedback through toast notifications. The UI has been improved for better accessibility and aesthetics.
25 lines
677 B
JavaScript
25 lines
677 B
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
// Connects to data-controller="theme"
|
|
export default class extends Controller {
|
|
static targets = ["toggle"]
|
|
|
|
connect() {
|
|
this.initTheme()
|
|
}
|
|
|
|
initTheme() {
|
|
const savedTheme = localStorage.getItem('theme')
|
|
if(savedTheme) {
|
|
document.documentElement.setAttribute('data-theme', savedTheme)
|
|
this.toggleTarget.checked = savedTheme === 'dark'
|
|
}
|
|
}
|
|
|
|
toggle(event) {
|
|
const newTheme = event.target.checked ? 'dark' : 'light'
|
|
document.documentElement.setAttribute('data-theme', newTheme)
|
|
localStorage.setItem('theme', newTheme)
|
|
}
|
|
}
|