MCPcopy Index your code
hub / github.com/coder/coder / ThemeProvider

Function ThemeProvider

site/src/contexts/ThemeProvider.tsx:30–65  ·  view source on GitHub ↗
({ children })

Source from the content-addressed store, hash-verified

28import { usePreferredColorScheme } from "#/theme/usePreferredColorScheme";
29
30export const ThemeProvider: FC<PropsWithChildren> = ({ children }) => {
31 const { metadata } = useEmbeddedMetadata();
32 const appearanceSettingsQuery = useQuery(
33 appearanceSettings(metadata.userAppearance),
34 );
35 const preferredColorScheme = usePreferredColorScheme();
36
37 const settings =
38 appearanceSettingsQuery.data ?? metadata.userAppearance?.value ?? {};
39 const state = migrateLegacyPreference(settings);
40 const concreteName = resolveActiveThemeName(state, preferredColorScheme);
41
42 useEffect(() => {
43 const root = document.documentElement;
44 // Embedded pages manage theme independently.
45 if (root.dataset.embedTheme) {
46 return;
47 }
48 root.classList.add(concreteName);
49 root.classList.add(baseModeFor(concreteName));
50
51 return () => {
52 if (!root.dataset.embedTheme) {
53 root.classList.remove(...CONCRETE_THEMES);
54 }
55 };
56 }, [concreteName]);
57
58 const theme = themes[concreteName];
59
60 return (
61 <StyledEngineProvider injectFirst>
62 <ThemeOverride theme={theme}>{children}</ThemeOverride>
63 </StyledEngineProvider>
64 );
65};
66
67// This is being added to allow Tailwind classes to be used with MUI components. https://mui.com/material-ui/integrations/interoperability/#tailwind-css
68const cache = createCache({

Callers

nothing calls this directly

Calls 7

appearanceSettingsFunction · 0.90
usePreferredColorSchemeFunction · 0.90
migrateLegacyPreferenceFunction · 0.90
resolveActiveThemeNameFunction · 0.90
baseModeForFunction · 0.90
removeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected