nimuli/resources/js/app.js

35 lines
868 B
JavaScript

import '../css/app.css';
import './bootstrap';
import Alpine from 'alpinejs';
import Chart from 'chart.js/auto';
window.Chart = Chart;
// Theme store — reads localStorage, applies to <html data-theme>
Alpine.store('theme', {
current: localStorage.getItem('nimuli_theme') || document.documentElement.dataset.theme || 'dark',
init() {
this.apply(this.current);
},
apply(theme) {
this.current = theme;
document.documentElement.dataset.theme = theme;
localStorage.setItem('nimuli_theme', theme);
},
cycle() {
const order = ['dark', 'light', 'system'];
const next = order[(order.indexOf(this.current) + 1) % order.length];
this.apply(next);
},
});
// Sidebar drawer store — mobile open/close
Alpine.store('sidebar', {
open: false,
});
window.Alpine = Alpine;
Alpine.start();