forked from ant-design/pro-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.tsx
62 lines (60 loc) · 1.81 KB
/
layout.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
import React, { useEffect, useState } from 'react';
import Layout from 'dumi-theme-default/src/layout';
import { ConfigProvider } from 'antd';
import { IRouteComponentProps } from 'umi';
import zhCN from 'antd/es/locale/zh_CN';
import moment from 'moment';
import Darkreader from 'react-darkreader';
import 'moment/locale/zh-cn';
import './layout.less';
moment.locale('zh-cn');
export default ({ children, ...props }: IRouteComponentProps) => {
const colorScheme = window.matchMedia('(prefers-color-scheme: dark)').matches && 'dark';
const defaultDarken = localStorage.getItem('procomponents_dark_theme') || colorScheme;
useEffect(() => {
(function (h, o, t, j, a, r) {
// @ts-ignore
h.hj =
// @ts-ignore
h.hj ||
function () {
// @ts-ignore
(h.hj.q = h.hj.q || []).push(arguments);
};
// @ts-ignore
h._hjSettings = { hjid: 2036108, hjsv: 6 };
a = o.getElementsByTagName('head')[0];
r = o.createElement('script');
r.async = 1;
// @ts-ignore
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
a.appendChild(r);
})(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=');
}, []);
return (
<>
<div
style={{
position: 'fixed',
right: 8,
top: 20,
zIndex: 999,
}}
>
<Darkreader
defaultDarken={defaultDarken === 'dark'}
onChange={(check) => {
if (!check) {
localStorage.setItem('procomponents_dark_theme', 'light');
return;
}
localStorage.setItem('procomponents_dark_theme', 'dark');
}}
/>
</div>
<ConfigProvider locale={zhCN}>
<Layout {...props}>{children}</Layout>
</ConfigProvider>
</>
);
};