Skip to content

Commit a7504d7

Browse files
committed
website: add dark mode.
1 parent b5e562f commit a7504d7

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

website/src/component/Container/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ interface ContainerProps extends React.HTMLAttributes<HTMLDivElement> {
1010

1111
export default function Container(props: ContainerProps) {
1212
const { data, children, path = '' } = props;
13-
console.log(path)
1413
return (
1514
<Fragment>
1615
<Header enableStyle={/\/(team)/.test(path)} showBorder={/\/(home)/.test(path)} path={path} />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:root[data-theme=dark] {
2+
filter: invert(1);
3+
background-color: #fff;
4+
img {
5+
filter: invert(1);
6+
}
7+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useEffect } from 'react';
2+
import { useState } from 'react';
3+
import { Switch } from 'uiw';
4+
import './index.module.less';
5+
6+
export default function DarkMode() {
7+
const theme = localStorage.getItem('theme');
8+
const [dark, setDark] = useState(!!theme);
9+
useEffect(() => {
10+
document.documentElement.dataset.theme = dark ? 'dark' : '';
11+
}, [dark]);
12+
return (
13+
<Switch
14+
checked={dark}
15+
data-checked="🌞"
16+
data-unchecked="🌛"
17+
onChange={(evn) => {
18+
if (evn.target.checked) {
19+
localStorage.setItem('theme', '1')
20+
} else {
21+
localStorage.removeItem('theme')
22+
}
23+
setDark(evn.target.checked);
24+
}}
25+
style={{ marginTop: 5, marginLeft: 10, marginRight: 10 }}
26+
/>
27+
);
28+
}

website/src/component/Header/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Link, NavLink } from 'react-router-dom';
22
import pkg from '@uiw/react-native/package.json';
33
import styles from './index.module.less';
4+
import DarkMode from '../DarkMode';
45
import { ReactComponent } from '../../assets/logo-dark.svg';
56
import { ReactComponent as Github } from '../../assets/github.svg';
67

@@ -42,6 +43,7 @@ export default function Header(props: HeaderProps) {
4243
<a target="__blank" href="https://github.com/uiwjs/react-native-uiw/issues">问题反馈</a>
4344
<a target="__blank" href="https://uiwjs.github.io/#/components">Web 组件</a>
4445
<NavLink to="/team">团队</NavLink>
46+
<DarkMode />
4547
<a target="__blank" href="https://github.com/uiwjs/react-native-uiw">
4648
<Github />
4749
</a>

website/src/pages/team/index.module.less

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
margin: 20px;
5858
transition: all .3s;
5959
opacity: 0.75;
60-
filter: grayscale(100%);
61-
filter: gray;
60+
// filter: grayscale(100%);
61+
// filter: gray;
6262
}
6363
span {
6464
transition: color .3s;
@@ -69,8 +69,8 @@
6969
}
7070
&:hover img {
7171
box-shadow: 0px 0px 0px 5px #cccccc;
72-
transform: rotate(720deg) scale(.9);
73-
filter: initial;
72+
transform: rotate(720deg) scale(.8);
73+
// filter: initial;
7474
opacity: 1;
7575
}
7676
}

0 commit comments

Comments
 (0)