* types * Working, but messy * Add InputColor component * types * Show default theme values when not customized * Support custom theme on team sign-in page * Payload validation * Custom theme on shared documents * Improve theme validation * Team -> Workspace in settings
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { ThemeProvider } from "styled-components";
|
|
import GlobalStyles from "@shared/styles/globals";
|
|
import { TeamPreference, UserPreference } from "@shared/types";
|
|
import useBuildTheme from "~/hooks/useBuildTheme";
|
|
import useStores from "~/hooks/useStores";
|
|
import { TooltipStyles } from "./Tooltip";
|
|
|
|
const Theme: React.FC = ({ children }) => {
|
|
const { auth, ui } = useStores();
|
|
const theme = useBuildTheme(
|
|
auth.team?.getPreference(TeamPreference.CustomTheme) ||
|
|
auth.config?.customTheme ||
|
|
undefined
|
|
);
|
|
|
|
React.useEffect(() => {
|
|
window.dispatchEvent(
|
|
new CustomEvent("theme-changed", {
|
|
detail: { isDark: ui.resolvedTheme === "dark" },
|
|
})
|
|
);
|
|
}, [ui.resolvedTheme]);
|
|
|
|
return (
|
|
<ThemeProvider theme={theme}>
|
|
<>
|
|
<TooltipStyles />
|
|
<GlobalStyles
|
|
useCursorPointer={auth.user?.getPreference(
|
|
UserPreference.UseCursorPointer,
|
|
true
|
|
)}
|
|
/>
|
|
{children}
|
|
</>
|
|
</ThemeProvider>
|
|
);
|
|
};
|
|
|
|
export default observer(Theme);
|