Files
outline/app/components/PageTheme.ts
Tom Moor 15b1069bcc chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
2021-11-29 06:40:55 -08:00

32 lines
874 B
TypeScript

import * as React from "react";
import { useTheme } from "styled-components";
import useStores from "~/hooks/useStores";
export default function PageTheme() {
const { ui } = useStores();
const theme = useTheme();
React.useEffect(() => {
// wider page background beyond the React root
if (document.body) {
document.body.style.background = theme.background;
}
// theme-color adjusts the title bar color for desktop PWA
const themeElement = document.querySelector('meta[name="theme-color"]');
if (themeElement) {
themeElement.setAttribute("content", theme.background);
}
// user-agent controls and scrollbars
const csElement = document.querySelector('meta[name="color-scheme"]');
if (csElement) {
csElement.setAttribute("content", ui.resolvedTheme);
}
}, [theme, ui.resolvedTheme]);
return null;
}