MCPcopy
hub / github.com/simstudioai/sim / syncThemeToNextThemes

Function syncThemeToNextThemes

apps/sim/lib/core/utils/theme.ts:10–35  ·  view source on GitHub ↗
(theme: 'system' | 'light' | 'dark')

Source from the content-addressed store, hash-verified

8 * @param theme - The desired theme ('system', 'light', or 'dark')
9 */
10export function syncThemeToNextThemes(theme: 'system' | 'light' | 'dark') {
11 if (typeof window === 'undefined') return
12
13 const oldValue = localStorage.getItem('sim-theme')
14 localStorage.setItem('sim-theme', theme)
15
16 window.dispatchEvent(
17 new StorageEvent('storage', {
18 key: 'sim-theme',
19 newValue: theme,
20 oldValue: oldValue,
21 storageArea: localStorage,
22 url: window.location.href,
23 })
24 )
25
26 const root = document.documentElement
27 root.classList.remove('light', 'dark')
28
29 if (theme === 'system') {
30 const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
31 root.classList.add(systemTheme)
32 } else {
33 root.classList.add(theme)
34 }
35}
36
37/**
38 * Gets the current theme from next-themes localStorage

Callers 3

useGeneralSettingsFunction · 0.90
prefetchGeneralSettingsFunction · 0.90
useUpdateGeneralSettingFunction · 0.90

Calls 4

getItemMethod · 0.80
setItemMethod · 0.80
removeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected