diff --git a/packages/web/components/top_bar.tsx b/packages/web/components/top_bar.tsx index e75e1b9..3476843 100644 --- a/packages/web/components/top_bar.tsx +++ b/packages/web/components/top_bar.tsx @@ -1,5 +1,6 @@ -import { faRunning, faHome } from "@fortawesome/free-solid-svg-icons"; +import { faRunning, faHome, faSun, faMoon } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { useEffect, useState } from "react"; import { Notification } from "../types"; function prettyName(s: string | undefined): string { @@ -14,6 +15,7 @@ export function TopBar({ unsavedChanges, notifications, onClick, + onThemeClick, onHomeClick, onActionClick, lhs, @@ -23,11 +25,15 @@ export function TopBar({ unsavedChanges: boolean; notifications: Notification[]; onClick: () => void; + onThemeClick: () => void; onHomeClick: () => void; onActionClick: () => void; lhs?: React.ReactNode; rhs?: React.ReactNode; }) { + + const [theme, setTheme] = useState(localStorage.theme ?? 'light'); + return (
{lhs} @@ -71,6 +77,16 @@ export function TopBar({ > +
diff --git a/packages/web/editor.tsx b/packages/web/editor.tsx index f2a7380..b8a8b20 100644 --- a/packages/web/editor.tsx +++ b/packages/web/editor.tsx @@ -719,6 +719,13 @@ export class Editor { onClick={() => { dispatch({ type: "start-navigate" }); }} + onThemeClick={() => { + if (localStorage.theme === 'dark') + localStorage.theme = 'light'; + else + localStorage.theme = 'dark'; + document.documentElement.dataset.theme = localStorage.theme; + }} onHomeClick={() => { editor.navigate(""); }} diff --git a/packages/web/index.html b/packages/web/index.html index 54b5861..da846ef 100644 --- a/packages/web/index.html +++ b/packages/web/index.html @@ -13,8 +13,10 @@ overflow: hidden; } + - diff --git a/packages/web/styles/main.scss b/packages/web/styles/main.scss index 056846f..4bc7e2d 100644 --- a/packages/web/styles/main.scss +++ b/packages/web/styles/main.scss @@ -1,5 +1,6 @@ @use "editor.scss"; @use "filter_box.scss"; +@use "theme.scss"; @font-face { font-family: "iA-Mono"; diff --git a/packages/web/styles/theme.css b/packages/web/styles/theme.scss similarity index 85% rename from packages/web/styles/theme.css rename to packages/web/styles/theme.scss index 972dd12..571d40f 100644 --- a/packages/web/styles/theme.css +++ b/packages/web/styles/theme.scss @@ -270,3 +270,42 @@ font-size: 75%; line-height: 75%; } + +html[data-theme="dark"] { + #sb-root { + background-color: #555; + color: rgb(200, 200, 200); + } + + #sb-top { + background-color: rgb(38, 38, 38); + border-bottom: rgb(62, 62, 62) 1px solid; + color: rgb(200, 200, 200); + } + + .sb-saved { + color: rgb(225, 225, 225); + } + + .sb-filter-box, + /* duplicating the class name to increase specificity */ + .sb-help-text.sb-help-text { + color: #ccc; + background-color: rgb(38, 38, 38); + } + + .sb-help-text { + border-bottom: 1px solid #6c6c6c; + } + + .sb-code, + .sb-line-fenced-code, + .sb-task-marker { + background-color: #333; + } + + .sb-notifications > div { + border: rgb(197, 197, 197) 1px solid; + background-color: #333; + } +}