Skip to content

Commit

Permalink
Support prefers color scheme dark (#17)
Browse files Browse the repository at this point in the history
* add global dark theme styles

* add dark mode to documentation pages

* update styles
  • Loading branch information
EthanThatOneKid authored Mar 31, 2024
1 parent d9a653a commit 866a955
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
3 changes: 2 additions & 1 deletion components/doc/doc_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export default function DocContent(props: DocContentProps) {
<meta property="og:title" content={title} />
<link rel="stylesheet" href="/md.css" />

<Hljs id="github" />
{/* Choose an ID: https://highlightjs.org/examples */}
<Hljs id="github-dark-dimmed" />
<script src="/copy.js" defer></script>
</Head>

Expand Down
6 changes: 3 additions & 3 deletions components/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export interface NavProps {
export default function Nav(props: NavProps) {
return (
<nav class="nav">
<a href="/">
<h1>jsonx</h1>
</a>
<h1>
<a href="/">jsonx</a>
</h1>

<ToC
nodes={nodes}
Expand Down
45 changes: 44 additions & 1 deletion static/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

::selection {
background-color: #f0a8ff;
background-color: rgba(240, 168, 255, 0.5);
}

body {
Expand All @@ -20,6 +20,14 @@ body {
font-size: 1.2em;
}

a:visited {
color: #833bff;
}

a:hover {
color: #e045ff;
}

.nav {
grid-area: nav;
margin: 0 1em;
Expand All @@ -29,6 +37,10 @@ body {
font-size: 1.5em;
}

.nav h1 a {
text-decoration: none;
}

.nav ul {
padding: 0;
margin-left: 1em;
Expand Down Expand Up @@ -67,6 +79,37 @@ body {
margin-left: 1em;
}

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

h1,
h2,
h3,
h4,
h5,
h6,
p,
a,
ul,
ol {
color: #ddd;
}

hr {
border-color: #333;
}

a:visited {
color: #c671ff;
}

a:hover {
color: #f0a8ff;
}
}

@media (min-width: 768px) {
body {
grid-template-columns: 1fr 3fr 1fr;
Expand Down
26 changes: 24 additions & 2 deletions static/md.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.markdown-body {
margin: 0 auto;
line-height: 1.5;
margin-bottom: 2em;
}

@media (min-width: 768px) {
Expand Down Expand Up @@ -73,8 +74,10 @@

.markdown-body pre,
.markdown-body code {
background-color: #f8f8f8;
border: 1px solid #ddd;
font-family: monospace;
color: #ddd;
background-color: #44475a;
border: 1px solid #282a36;
border-radius: 3px;
padding: 0.1em 0.2em;
}
Expand All @@ -89,6 +92,7 @@
overflow-x: auto;
white-space: pre-wrap;
word-break: break-all;
border: none;
}

.markdown-body pre {
Expand All @@ -102,16 +106,34 @@
text-decoration: underline;
text-underline-offset: 0.3em;
padding: 0.2em 0.9em;
color: #bbb;
}

.markdown-body pre button {
position: absolute;
top: 5px;
right: 5px;
height: 2em;
color: #bbb;
background-color: #303241;
}

.markdown-body kbd {
border-radius: 3px;
padding: 1px 2px 0;
border: 1px solid black;
background-color: #f7f7f7;
font-family: monospace;
}

.markdown-body img:not(:has([width]), :has([height])) {
max-width: 100%;
height: auto;
}

@media (prefers-color-scheme: dark) {
.markdown-body blockquote {
background-color: rgba(255, 255, 255, 0.1);
border-left: 0.25em solid #44475a;
}
}

0 comments on commit 866a955

Please sign in to comment.