Skip to content

Commit

Permalink
more dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiasAurel committed Oct 23, 2023
1 parent 5d61f8b commit 0548359
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/big-interactive-pages/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default function Editor({ persistenceState, cookies }: EditorProps) {
<div class={styles.page}>
<Navbar persistenceState={persistenceState} />

<div class={styles.pageMain} style={{ backgroundColor: isDark.value ? "#2f2f2f" : "#fafed7" }}>
<div class={styles.pageMain}>
<div className={styles.codeContainer}>
<CodeMirror
class={styles.code}
Expand Down
5 changes: 5 additions & 0 deletions src/components/codemirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default function CodeMirror(props: CodeMirrorProps) {
const parent = useRef<HTMLDivElement>(null)
const [editorRef, setEditorRef] = useState<EditorView>();

// set dark mode on render
useEffect(() => { if (window.matchMedia("(prefers-color-scheme: dark)").matches) isDark.value = true }, []);

// Alert the parent to code changes (not reactive)
const onCodeChangeRef = useRef(props.onCodeChange)
useEffect(() => { onCodeChangeRef.current = props.onCodeChange }, [props.onCodeChange])
Expand All @@ -35,6 +38,8 @@ export default function CodeMirror(props: CodeMirrorProps) {
}, () => onRunShortcutRef.current?.());

const setEditorTheme = () => {
const shouldBeDarkMode = window.matchMedia("(prefers-color-scheme: dark)").matches;
console.log("shouldBeDarkMode = ", shouldBeDarkMode);
if (isDark.value) {
editorRef?.dispatch({
effects: StateEffect.appendConfig.of(oneDark)
Expand Down
1 change: 1 addition & 0 deletions src/components/navbar-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IoAdd, IoLogoGithub, IoOpenOutline } from 'react-icons/io5'
import Button from './design-system/button'
import styles from './navbar.module.css'
import { SessionInfo } from '../lib/game-saving/account'
import { isDark } from '../lib/state'

interface MainNavbarProps {
session: SessionInfo | null
Expand Down
6 changes: 6 additions & 0 deletions src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ body {
position: relative;
}

@media (prefers-color-scheme: dark) {
body {
background: #2f2f2f;
}
}

a {
color: var(--accent);
text-decoration: none;
Expand Down
5 changes: 5 additions & 0 deletions src/pages/gallery/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ games
body {
overflow-y: scroll;
}
@media (prefers-color-scheme: dark) {
body {
color: white;
}
}

.copy-container > h1 {
margin-bottom: 12px;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ if (session && session.session.full) {
</div>
</section>

<section class='credits wrapper'>
<section style="color: black;" class='credits wrapper'>
<div class='container limit-text'>
<p>
Sprig was developed by a team at Hack Club with assistance from Brian Silverman (who helped develop Scratch and
Expand Down
5 changes: 5 additions & 0 deletions src/pages/~/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ if (games.length === 0 && unnamedGames.length > 0) {
flex-direction: column;
overflow: hidden;
}
@media (prefers-color-scheme: dark) {
body {
color: white;
}
}

.columns {
flex: 1;
Expand Down

0 comments on commit 0548359

Please sign in to comment.