-
Notifications
You must be signed in to change notification settings - Fork 3
/
Document.tsx
75 lines (66 loc) · 1.93 KB
/
Document.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {
Links,
LiveReload,
Meta,
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import type { ColorScheme } from '@mantine/core';
import { MantineProvider, ColorSchemeProvider } from '@mantine/core';
import { useState } from "react";
import { AppShell } from "./AppShell";
import { useEmotionCache } from '@mantine/core';
// import { getCache } from '@mantine/core';
import { useContext, useEffect } from "react";
import { ClientStyleContext } from "~/context";
import { StylesPlaceholder } from "@mantine/remix";
interface DocumentProps {
children: React.ReactNode;
}
export function Document({ children }: DocumentProps) {
const [colorScheme, setColorScheme] = useState<ColorScheme>('light');
const toggleColorScheme = (value?: ColorScheme) =>
setColorScheme(value || (colorScheme === 'dark' ? 'light' : 'dark'));
const clientStyleData = useContext(ClientStyleContext);
const mantineCache = useEmotionCache()
useEffect(() => {
const cache = mantineCache
cache.sheet.container = document.head;
const tags = cache.sheet.tags;
cache.sheet.flush();
tags.forEach((tag) => {
(cache.sheet as any)._insertTag(tag);
});
clientStyleData?.reset();
}, []);
return (
<html lang="en">
<head>
<Meta />
<Links />
<StylesPlaceholder />
</head>
<body>
<ColorSchemeProvider colorScheme={colorScheme} toggleColorScheme={toggleColorScheme}>
<MantineProvider
theme={{
colorScheme,
colors: {
white: ["#ffffff"]
}
}}
withGlobalStyles
withNormalizeCSS
>
<AppShell>
{children}
</AppShell>
</MantineProvider>
</ColorSchemeProvider>
<ScrollRestoration />
<Scripts />
{process.env.NODE_ENV === "development" && <LiveReload />}
</body>
</html>
);
}