MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / themeFn

Function themeFn

apps/start/src/components/theme-provider.tsx:62–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60
61const themeScript = (() => {
62 function themeFn() {
63 try {
64 // Read theme from cookie
65 const cookies = document.cookie.split('; ');
66 const themeCookie = cookies.find((c) => c.startsWith('ui-theme='));
67 const storedTheme = themeCookie ? themeCookie.split('=')[1] : 'system';
68 const validTheme = ['light', 'dark', 'system'].includes(storedTheme)
69 ? storedTheme
70 : 'system';
71
72 if (validTheme === 'system') {
73 const systemTheme = window.matchMedia('(prefers-color-scheme: dark)')
74 .matches
75 ? 'dark'
76 : 'light';
77 document.documentElement.classList.add(systemTheme, 'system');
78 } else {
79 document.documentElement.classList.add(validTheme);
80 }
81 } catch (e) {
82 const systemTheme = window.matchMedia('(prefers-color-scheme: dark)')
83 .matches
84 ? 'dark'
85 : 'light';
86 document.documentElement.classList.add(systemTheme, 'system');
87 }
88 }
89 return `(${themeFn.toString()})();`;
90})();
91

Callers

nothing calls this directly

Calls 1

addMethod · 0.45

Tested by

no test coverage detected