File tree Expand file tree Collapse file tree 4 files changed +17
-15
lines changed
Expand file tree Collapse file tree 4 files changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -14,20 +14,23 @@ import {
1414const appName =
1515 import . meta. env . VITE_APP_NAME || 'Laravel' ;
1616
17- // window.appearance = 'system';
1817
19- // // Initialize appearance
20- // if (typeof window !== 'undefined') {
21- // const appearance = localStorage.getItem('appearance') || 'system';
22- // window.appearance = appearance;
18+ /*
19+ * Dark/Light Mode Initialization
20+ * - This needs to be added to every page so that way the correct appearance is loaded
21+ */
22+ ( function ( ) {
23+ const savedAppearance = localStorage . getItem ( 'appearance' ) || 'system' ;
24+ const prefersDark = window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
2325
24- // const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
25- // const shouldBeDark = appearance === 'dark' || (appearance === 'system' && prefersDark);
26+ const isDark =
27+ savedAppearance === 'dark' ||
28+ ( savedAppearance === 'system' && prefersDark ) ;
2629
27- // if (shouldBeDark ) {
28- // document.body .classList.add('dark');
29- // }
30- // }
30+ if ( isDark ) {
31+ document . documentElement . classList . add ( 'dark' ) ;
32+ }
33+ } ) ( ) ;
3134
3235createInertiaApp ( {
3336 title : ( title ) => `${ title } - ${ appName } ` ,
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export function useAppearance() {
1010
1111 const applyTheme = ( mode : Appearance ) => {
1212 const isDark = mode === 'dark' || ( mode === 'system' && prefersDark ( ) ) ;
13- document . body . classList . toggle ( 'dark' , isDark ) ;
13+ document . documentElement . classList . toggle ( 'dark' , isDark ) ;
1414 } ;
1515
1616 const updateAppearance = ( mode : Appearance ) => {
Original file line number Diff line number Diff line change 55 <meta name =" viewport" content =" width=device-width, initial-scale=1" >
66
77 <title inertia >{{ config (' app.name' , ' Laravel' ) } } </title >
8-
9- <!-- Scripts -->
8+
109 @routes
1110 @viteReactRefresh
1211 @vite ([' resources/js/app.tsx' , " resources/js/Pages/{$page [' component' ]}.tsx" ] )
Original file line number Diff line number Diff line change 3030 Route::get ('settings/password ' , [PasswordController::class, 'edit ' ])->name ('password.edit ' );
3131 Route::put ('settings/password ' , [PasswordController::class, 'update ' ])->name ('password.update ' );
3232
33- Route::get ('settings/appearance ' , function () {
33+ Route::get ('settings/appearance ' , function () {
3434 return Inertia::render ('Settings/Appearance ' );
3535 })->name ('appearance ' );
3636
You can’t perform that action at this time.
0 commit comments