Refactor Root layout theme and fonts. Encapsulate functions into separate files. Fix default theme handling when cookie is not set by fall-backing to the selected theme mode. (#103)
This commit is contained in:
committed by
GitHub
parent
b8e1bf3c18
commit
5a4bbb1716
16
apps/web/lib/root-theme.ts
Normal file
16
apps/web/lib/root-theme.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
type Theme = 'light' | 'dark' | 'system';
|
||||
|
||||
/**
|
||||
* @name getRootTheme
|
||||
* @description Get the root theme from the cookies or default theme.
|
||||
* @returns The root theme.
|
||||
*/
|
||||
export async function getRootTheme() {
|
||||
const cookiesStore = await cookies();
|
||||
|
||||
const themeCookie = cookiesStore.get('theme')?.value as Theme
|
||||
|
||||
return themeCookie ?? process.env.NEXT_PUBLIC_DEFAULT_THEME_MODE ?? 'light';
|
||||
}
|
||||
Reference in New Issue
Block a user