Skip to content

Commit 50ded37

Browse files
committed
feat: support dark mode
1 parent 5fdead7 commit 50ded37

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Button } from '@blueprintjs/core'
2+
3+
import { useEffect, useState } from 'react'
4+
5+
export const ThemeSwitchButton = () => {
6+
const [theme, setTheme] = useState(localStorage.getItem('theme') || '')
7+
const handleThemeSwitch = () => {
8+
const isCurrentDark = theme === 'dark'
9+
setTheme(isCurrentDark ? 'light' : 'dark')
10+
localStorage.setItem('theme', isCurrentDark ? 'light' : 'dark')
11+
}
12+
useEffect(() => {
13+
if (theme == 'dark') {
14+
document.body.classList.add('bp4-dark')
15+
document.body.classList.add('dark')
16+
} else {
17+
document.body.classList.remove('bp4-dark')
18+
document.body.classList.remove('dark')
19+
}
20+
}, [theme])
21+
return (
22+
<Button
23+
className="mr-4"
24+
onClick={handleThemeSwitch}
25+
icon={theme === 'dark' ? 'moon' : 'flash'}
26+
></Button>
27+
)
28+
}

src/components/drawer/OperationDrawer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const OperationDrawer: FCC<{
55
}> = ({ title, children }) => {
66
return (
77
<section className="flex flex-col relative h-full">
8-
<div className="px-8 py-2 text-lg font-medium flex items-center bg-slate-100 shadow w-full h-12">
8+
<div className="px-8 py-2 text-lg font-medium flex items-center bg-slate-100 shadow w-full h-12 dark:bg-slate-900 dark:text-white">
99
{title}
1010
</div>
1111

src/components/editor/source/SourceEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const SourceEditor: FC<SourceEditorProps> = ({
7575
/>
7676
}
7777
>
78-
<div className="px-8 py-4 flex-grow flex flex-col bg-zinc-50">
78+
<div className="px-8 py-4 flex-grow flex flex-col bg-zinc-50 dark:bg-slate-900 dark:text-white">
7979
<Callout
8080
className=" [&_h4]:text-sm"
8181
intent="primary"
@@ -103,7 +103,7 @@ export const SourceEditor: FC<SourceEditorProps> = ({
103103
</Tooltip2>
104104
</div>
105105
<textarea
106-
className="mt-4 p-1 flex-grow bg-white text-xm font-mono resize-none focus:outline focus:outline-2 focus:outline-blue-300"
106+
className="mt-4 p-1 flex-grow bg-white text-xm font-mono resize-none focus:outline focus:outline-2 focus:outline-blue-300 dark:bg-slate-900 dark:text-white"
107107
value={text}
108108
onChange={(e) => setText(e.target.value)}
109109
onBlur={(e) => handleChange(e.target.value)}

src/layouts/AppLayout.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Button, IconName, Tag } from '@blueprintjs/core'
1+
import { Button, IconName, Navbar, Tag } from '@blueprintjs/core'
22

33
import { Link, NavLink } from 'react-router-dom'
44
import { FCC } from 'types'
55

66
import { AccountManager } from 'components/AccountManager'
77
import { BackToTop } from 'components/BackToTop'
8+
import { ThemeSwitchButton } from 'components/ThemeSwitchButton'
89

910
const LINKS: {
1011
to: string
@@ -23,10 +24,12 @@ const LINKS: {
2324
},
2425
]
2526

27+
// const darkMode = localStorage.getItem('darkMode') === 'true'
28+
2629
export const AppLayout: FCC = ({ children }) => (
27-
<div className="flex flex-col h-full w-full bg-zinc-50">
28-
<nav className="flex w-full px-8 py-2 items-center bg-zinc-100 shadow fixed h-14 z-10 whitespace-nowrap overflow-x-auto overflow-y-hidden">
29-
<Link to="/" className="flex items-center hover:no-underline">
30+
<div className="flex flex-col h-full w-full bg-zinc-50 ">
31+
<Navbar className="flex w-full px-8 py-2 items-center bg-zinc-100 shadow fixed h-14 z-10 whitespace-nowrap overflow-x-auto overflow-y-hidden">
32+
<Link to="/" className="flex items-center hover:no-underline ">
3033
<div className="select-none text-lg font-bold leading-none">
3134
MAA Copilot
3235
</div>
@@ -54,10 +57,11 @@ export const AppLayout: FCC = ({ children }) => (
5457

5558
<div className="flex-1" />
5659

60+
<ThemeSwitchButton />
5761
<AccountManager />
58-
</nav>
62+
</Navbar>
5963

60-
<div className="pt-14 pb-16">{children}</div>
64+
<div className="docs-content-wrapper pt-14 pb-16">{children}</div>
6165

6266
<BackToTop />
6367
</div>

src/styles/blueprint.less

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,17 @@ body {
233233
@apply select-none;
234234
}
235235
}
236+
237+
238+
.bp4-dark {
239+
.docs-content-wrapper {
240+
background-color: #2f343c;
241+
}
242+
.bp4-tag{
243+
background-color: #141c2b;
244+
}
245+
div,
246+
p,span {
247+
color: #fff;
248+
}
249+
}

tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ module.exports = {
1212
},
1313
},
1414
},
15+
darkMode: 'class',
1516
plugins: [],
1617
}

0 commit comments

Comments
 (0)