MCPcopy Create free account
hub / github.com/chokcoco/iCSS / applyTheme

Function applyTheme

website/app/lib/theme.ts:32–50  ·  view source on GitHub ↗
(theme: Theme)

Source from the content-addressed store, hash-verified

30}
31
32export function applyTheme(theme: Theme) {
33 if (typeof window === 'undefined') return;
34
35 const root = document.documentElement;
36 const systemTheme = getSystemTheme();
37
38 // 移除所有主题类
39 root.classList.remove('light', 'dark');
40
41 // 应用主题
42 if (theme === 'system') {
43 root.classList.add(systemTheme);
44 } else {
45 root.classList.add(theme);
46 }
47
48 // 保存到 localStorage
49 localStorage.setItem('theme', theme);
50}
51
52export function getStoredTheme(): Theme {
53 if (typeof window === 'undefined') return 'system';

Callers 2

setThemeFunction · 0.90
initializeThemeFunction · 0.85

Calls 1

getSystemThemeFunction · 0.85

Tested by

no test coverage detected