From 92a1bfba50f2b7f9aa9e9af0b4b1f9724cae1e26 Mon Sep 17 00:00:00 2001 From: Aditya Chandra Date: Sat, 14 Sep 2024 15:28:59 +0700 Subject: [PATCH 1/9] added(ui): theme-switch in navigation --- resources/js/app.js | 3 + resources/js/theme-switch.js | 61 ++++++++++++++++++++ resources/views/layouts/navigation.blade.php | 10 ++++ tailwind.config.js | 2 + 4 files changed, 76 insertions(+) create mode 100644 resources/js/theme-switch.js diff --git a/resources/js/app.js b/resources/js/app.js index a782cf3c0..c2b0adb7f 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -64,4 +64,7 @@ Alpine.data('bookmarkButton', bookmarkButton); import { viewCreate } from './view-cerate.js'; Alpine.data('viewCreate', viewCreate); +import { themeSwitch } from './theme-switch.js'; +Alpine.data('themeSwitch', themeSwitch); + Livewire.start() diff --git a/resources/js/theme-switch.js b/resources/js/theme-switch.js new file mode 100644 index 000000000..504eee71e --- /dev/null +++ b/resources/js/theme-switch.js @@ -0,0 +1,61 @@ +const themeSwitch = () => ({ + + theme: 'dark', // default theme + + availableModes: ['dark', 'light', 'system'], + + modeIndex: 0, + + init() { + const currentTheme = localStorage.getItem('theme') || this.theme + + this.modeIndex = this.availableModes.indexOf(currentTheme) + + this.setTheme(currentTheme) + }, + + setTheme(theme) { + this.theme = theme + localStorage.setItem('theme', theme) + + if (theme === 'dark') { + this.setDarkMode() + return + } + + if (theme === 'light') { + this.setLightMode() + return + } + + this.setSystemMode() + }, + + setLightMode() { + document.documentElement.classList.remove('dark') + document.documentElement.classList.add(this.theme) + }, + + setDarkMode() { + document.documentElement.classList.remove('light') + document.documentElement.classList.add(this.theme) + }, + + setSystemMode() { + document.documentElement.classList.remove('dark', 'light') + }, + + toggleTheme() { + const newModeIndex = (this.modeIndex + 1) % 3 + + this.modeIndex = newModeIndex + this.setTheme(this.availableModes[newModeIndex]) + }, + + toggleThemeButtonText() { + return this.theme.charAt(0).toUpperCase() + this.theme.slice(1) + } + +}) + +export { themeSwitch } \ No newline at end of file diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index cbf478df4..050cb93b7 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -98,6 +98,16 @@ class="inline-flex items-center rounded-md border border-transparent bg-slate-90 + +
+ + + + + + +
+
{{ __('About') }} diff --git a/tailwind.config.js b/tailwind.config.js index 2bbd5c800..e34dd8b9a 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -12,6 +12,8 @@ export default { "./resources/js/**/*.js", ], + darkMode: 'selector', + theme: { extend: { fontFamily: { From 17d2c5d1ed5d19b02b01e9de5f989b8f51661196 Mon Sep 17 00:00:00 2001 From: Aditya Chandra Date: Sat, 14 Sep 2024 16:16:26 +0700 Subject: [PATCH 2/9] chore: take out 'system' in available modes --- resources/js/theme-switch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/js/theme-switch.js b/resources/js/theme-switch.js index 504eee71e..b2716f435 100644 --- a/resources/js/theme-switch.js +++ b/resources/js/theme-switch.js @@ -2,7 +2,7 @@ const themeSwitch = () => ({ theme: 'dark', // default theme - availableModes: ['dark', 'light', 'system'], + availableModes: ['dark', 'light'], // e.g. system modeIndex: 0, @@ -46,7 +46,7 @@ const themeSwitch = () => ({ }, toggleTheme() { - const newModeIndex = (this.modeIndex + 1) % 3 + const newModeIndex = (this.modeIndex + 1) % this.availableModes.length this.modeIndex = newModeIndex this.setTheme(this.availableModes[newModeIndex]) From 7dcf8f2c0b54699a8af5eb85880e6b27a06b22af Mon Sep 17 00:00:00 2001 From: Aditya Chandra Date: Sat, 14 Sep 2024 16:20:32 +0700 Subject: [PATCH 3/9] update: dark mode in app layouts, navigation, and footer --- .../components/dropdown-button.blade.php | 2 +- .../views/components/dropdown-link.blade.php | 2 +- resources/views/components/dropdown.blade.php | 2 +- resources/views/components/footer.blade.php | 20 +++++------ .../views/components/image-lightbox.blade.php | 4 +-- resources/views/layouts/app.blade.php | 4 +-- resources/views/layouts/navigation.blade.php | 34 +++++++++---------- 7 files changed, 33 insertions(+), 35 deletions(-) diff --git a/resources/views/components/dropdown-button.blade.php b/resources/views/components/dropdown-button.blade.php index 77756f9d0..31409236f 100644 --- a/resources/views/components/dropdown-button.blade.php +++ b/resources/views/components/dropdown-button.blade.php @@ -1,3 +1,3 @@ - diff --git a/resources/views/components/dropdown-link.blade.php b/resources/views/components/dropdown-link.blade.php index 7d48286ee..2a7a6d7eb 100644 --- a/resources/views/components/dropdown-link.blade.php +++ b/resources/views/components/dropdown-link.blade.php @@ -1,5 +1,5 @@ merge(['class' => 'block w-full px-4 py-2 text-start text-sm leading-5 text-slate-400 hover:bg-slate-800 transition duration-150 ease-in-out']) }} + {{ $attributes->merge(['class' => 'block w-full px-4 py-2 text-start text-sm leading-5 dark:text-slate-400 text-slate-600 dark:hover:bg-slate-800 hover:bg-slate-200 transition duration-150 ease-in-out']) }} wire:navigate > {{ $slot }} diff --git a/resources/views/components/dropdown.blade.php b/resources/views/components/dropdown.blade.php index 49411bec9..9b578774e 100644 --- a/resources/views/components/dropdown.blade.php +++ b/resources/views/components/dropdown.blade.php @@ -1,4 +1,4 @@ -@props(['align' => 'right', 'width' => '48', 'contentClasses' => 'bg-slate-900 py-1 text-slate-500', 'dropdownClasses' => '']) +@props(['align' => 'right', 'width' => '48', 'contentClasses' => 'dark:bg-slate-900 bg-slate-100 dark:border-none border border-slate-100 py-1 text-slate-500', 'dropdownClasses' => '']) @php switch ($align) { diff --git a/resources/views/components/footer.blade.php b/resources/views/components/footer.blade.php index 569c9b75b..a82bfd499 100644 --- a/resources/views/components/footer.blade.php +++ b/resources/views/components/footer.blade.php @@ -1,4 +1,4 @@ -