diff --git a/resources/js/app.js b/resources/js/app.js index c689b7bdf..b44019f19 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,5 +1,42 @@ import './../../vendor/power-components/livewire-powergrid/dist/powergrid'; +/** + * Dark mode toggle + */ +document.addEventListener('alpine:init', () => { + Alpine.store('darkMode', { + mode: 'light', + + init() { + if (localStorage.theme === 'dark') { this.dark() } + else if (localStorage.theme === 'light') { this.light() } + else { this.system() } + }, + + dark() { + document.documentElement.classList.add('dark') + localStorage.theme = 'dark' + this.mode = 'dark' + }, + system() { + if (window.matchMedia('(prefers-color-scheme: dark)').matches) { + document.documentElement.classList.add('dark') + } + else { + document.documentElement.classList.remove('dark') + } + localStorage.theme = 'system' + this.mode = 'system' + }, + light() { + document.documentElement.classList.remove('dark') + localStorage.theme = 'light' + this.mode = 'light' + } + }) +}) + + /** * Copy short url to clipboard * diff --git a/resources/views/components/theme-toggle.blade.php b/resources/views/components/theme-toggle.blade.php new file mode 100644 index 000000000..5a48ea612 --- /dev/null +++ b/resources/views/components/theme-toggle.blade.php @@ -0,0 +1,37 @@ +
+ + + + + +
diff --git a/resources/views/layouts/auth.blade.php b/resources/views/layouts/auth.blade.php index 227a3ee93..44aac0db0 100644 --- a/resources/views/layouts/auth.blade.php +++ b/resources/views/layouts/auth.blade.php @@ -8,11 +8,14 @@ @yield('title') | {{ config('app.name') }} + @livewireStyles @vite(['resources/css/main.css', 'resources/js/app.js']) @yield('content') + + @livewireScripts diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php index f51b4c430..67f1deb85 100644 --- a/resources/views/partials/header.blade.php +++ b/resources/views/partials/header.blade.php @@ -7,23 +7,27 @@
- +
+ - {{-- Mobile hamburger menu button --}} -
- + + + {{-- Mobile hamburger menu button --}} +
+ +
diff --git a/tailwind.config.js b/tailwind.config.js index b4715584e..e71e3ecdb 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -16,6 +16,7 @@ export default { presets: [ presetPowerGrid, ], + darkMode: 'class', theme: { extend: { colors: {