({ children })
| 28 | import { usePreferredColorScheme } from "#/theme/usePreferredColorScheme"; |
| 29 | |
| 30 | export 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 |
| 68 | const cache = createCache({ |
nothing calls this directly
no test coverage detected