Skip to content

Commit 41a5777

Browse files
authored
(site) Add dark mode style (#258)
Use Tailwind 2.0's ability to use class-based dark mode. The dark-mode switch comes from: - https://github.com/donavon/use-dark-mode - https://github.com/wKovacs64/gatsby-plugin-use-dark-mode - https://github.com/JoseRFelix/react-toggle-dark-mode To extend tailwind-typography, use the CSS @adamwathan shared in [this comment](tailwindlabs/tailwindcss-typography#69 (comment)).
1 parent 0e45a94 commit 41a5777

14 files changed

+326
-56
lines changed

Diff for: gatsby-config.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ module.exports = {
4343
{
4444
resolve: `gatsby-remark-vscode`,
4545
options: {
46-
theme: `Tomorrow`,
46+
theme: {
47+
default: `Tomorrow`,
48+
parentSelector: {
49+
"body.dark": "Tomorrow Night",
50+
},
51+
},
4752
extensions: [`elixir-ls`, `viml`, `vscode-themes/tomorrow`],
4853
},
4954
},
@@ -150,5 +155,15 @@ module.exports = {
150155
],
151156
},
152157
},
158+
{
159+
resolve: "gatsby-plugin-use-dark-mode",
160+
options: {
161+
classNameDark: "dark",
162+
classNameLight: "light",
163+
storageKey: "darkMode",
164+
element: "html",
165+
minify: true,
166+
},
167+
},
153168
],
154169
};

Diff for: package.json

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"gatsby-plugin-react-helmet": "^3.1.18",
3939
"gatsby-plugin-sharp": "^2.14.4",
4040
"gatsby-plugin-typescript": "^2.4.19",
41+
"gatsby-plugin-use-dark-mode": "^1.3.0",
4142
"gatsby-remark-autolink-headers": "^2.2.3",
4243
"gatsby-remark-copy-linked-files": "^2.1.33",
4344
"gatsby-remark-external-links": "0.0.4",
@@ -53,7 +54,9 @@
5354
"react": "^16.12.0",
5455
"react-dom": "^16.12.0",
5556
"react-helmet": "^5.2.1",
57+
"react-toggle-dark-mode": "^1.0.4",
5658
"typescript": "^4.3.5",
59+
"use-dark-mode": "^2.3.1",
5760
"viml": "XadillaX/vscode-language-viml",
5861
"vscode-themes": "Microsoft/vscode-themes"
5962
},

Diff for: src/components/DarkModeToggle.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from "react";
2+
3+
import useDarkMode from "use-dark-mode";
4+
import { DarkModeSwitch } from "react-toggle-dark-mode";
5+
6+
function DarkModeToggle() {
7+
const { value: isDarkMode, toggle: toggle } = useDarkMode(false, {
8+
classNameDark: "dark",
9+
classNameLight: "light",
10+
});
11+
12+
return (
13+
<DarkModeSwitch
14+
checked={isDarkMode}
15+
onChange={toggle}
16+
size={18}
17+
moonColor={"#A78BFA"} // purple-400
18+
sunColor={"white"}
19+
/>
20+
);
21+
}
22+
23+
export default DarkModeToggle;

Diff for: src/components/Footer.tsx

+12-7
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,44 @@ import * as React from "react";
33

44
function Footer() {
55
return (
6-
<div className="flex justify-between py-4 px-1 bg-green-800 text-white">
6+
<div className="flex justify-between py-4 px-1 bg-green-800 text-white dark:bg-gray-800 dark:text-purple-400">
77
<div className="flex flex-col pl-5 my-auto">
8-
<Link to="/" className="hover:text-black">
8+
<Link to="/" className="hover:text-black dark:hover:text-white">
99
Home
1010
</Link>
1111
<div className="group">
1212
<a
1313
href="https://github.com/tmr08c/"
1414
target="blank"
15-
className="group-hover:text-black"
15+
className="group-hover:text-black dark:group-hover:text-white"
1616
>
1717
{/* GitHub Logo SVG generated from Jekyll version of blog */}
1818
<svg viewBox="0 0 16 16" className="w-5 h-5 inline fill-current">
1919
<path d="M7.999,0.431c-4.285,0-7.76,3.474-7.76,7.761 c0,3.428,2.223,6.337,5.307,7.363c0.388,0.071,0.53-0.168,0.53-0.374c0-0.184-0.007-0.672-0.01-1.32 c-2.159,0.469-2.614-1.04-2.614-1.04c-0.353-0.896-0.862-1.135-0.862-1.135c-0.705-0.481,0.053-0.472,0.053-0.472 c0.779,0.055,1.189,0.8,1.189,0.8c0.692,1.186,1.816,0.843,2.258,0.645c0.071-0.502,0.271-0.843,0.493-1.037 C4.86,11.425,3.049,10.76,3.049,7.786c0-0.847,0.302-1.54,0.799-2.082C3.768,5.507,3.501,4.718,3.924,3.65 c0,0,0.652-0.209,2.134,0.796C6.677,4.273,7.34,4.187,8,4.184c0.659,0.003,1.323,0.089,1.943,0.261 c1.482-1.004,2.132-0.796,2.132-0.796c0.423,1.068,0.157,1.857,0.077,2.054c0.497,0.542,0.798,1.235,0.798,2.082 c0,2.981-1.814,3.637-3.543,3.829c0.279,0.24,0.527,0.713,0.527,1.437c0,1.037-0.01,1.874-0.01,2.129 c0,0.208,0.14,0.449,0.534,0.373c3.081-1.028,5.302-3.935,5.302-7.362C15.76,3.906,12.285,0.431,7.999,0.431z" />
2020
</svg>
21-
<span className="text-sm ml-1 group-hover:text-black">@tmr08c</span>
21+
<span className="text-sm ml-1 group-hover:text-black dark:group-hover:text-white">
22+
@tmr08c
23+
</span>
2224
</a>
2325
</div>
2426
</div>
2527
<div className="flex flex-col items-end pr-5 my-auto">
26-
<Link to="/talks" className="hover:text-black">
28+
<Link to="/talks" className="hover:text-black dark:hover:text-white">
2729
Talks
2830
</Link>
2931
<div className="flex items-center">
30-
<Link to="/rss.xml" className="mr-3 hover:text-black">
32+
<Link
33+
to="/rss.xml"
34+
className="mr-3 hover:text-black dark:hover:text-white"
35+
>
3136
{/* Logo thanks to https://www.svgrepo.com/svg/95552/rss-sign */}
3237
<svg viewBox="0 0 461.432 461.432" className="h-3 w-3 fill-current">
3338
<defs />
3439
<path d="M125.896 398.928c0 33.683-27.308 60.999-61.022 60.999-33.684 0-61.006-27.316-61.006-60.999 0-33.729 27.322-61.038 61.006-61.038 33.714 0 61.022 27.308 61.022 61.038zM0 229.636c0 8.441 6.606 15.379 15.036 15.809 60.318 3.076 100.885 25.031 138.248 62.582 36.716 36.864 60.071 89.759 64.082 137.769.686 8.202 7.539 14.524 15.77 14.524h56.701c4.344 0 8.498-1.784 11.488-4.935a15.852 15.852 0 004.333-11.729c-8.074-158.152-130.669-278.332-289.013-286.23a15.846 15.846 0 00-11.709 4.344A15.848 15.848 0 000 173.247v56.389z" />
3540
<path d="M0 73.411c0 8.51 6.713 15.482 15.216 15.819 194.21 7.683 350.315 161.798 358.098 355.879.34 8.491 7.32 15.208 15.818 15.208h56.457c4.297 0 8.408-1.744 11.393-4.834a15.857 15.857 0 004.441-11.552C453.181 199.412 261.024 9.27 16.38 1.121A15.844 15.844 0 004.838 5.568 15.842 15.842 0 000 16.954v56.457z" />
3641
</svg>
3742
</Link>
38-
<Link to="/blog" className="hover:text-black">
43+
<Link to="/blog" className="hover:text-black dark:hover:text-white">
3944
Blog
4045
</Link>
4146
</div>

Diff for: src/components/Header.tsx

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Link, StaticQuery, graphql } from "gatsby";
22
import * as React from "react";
33

4+
import DarkModeToggle from "./DarkModeToggle";
5+
46
function Header(): JSX.Element {
57
return (
68
<StaticQuery
@@ -14,7 +16,7 @@ function Header(): JSX.Element {
1416
}
1517
`}
1618
render={(data) => (
17-
<nav className="flex items-center justify-between flex-wrap bg-green-800 px-6 py-12 mb-5 text-white">
19+
<nav className="flex items-center justify-between flex-wrap bg-green-800 px-6 py-12 mb-5 text-white dark:bg-gray-800 dark:border-b-4 dark:border-double dark:border-purple-400 dark:text-purple-400">
1820
<div className="flex flex-no-shrink">
1921
<Link
2022
to="/"
@@ -23,16 +25,22 @@ function Header(): JSX.Element {
2325
{data.site.siteMetadata.title}
2426
</Link>
2527
</div>
26-
<div className="justify-end flex mr-4">
27-
<div className="text-xl">
28-
<Link to="/talks" className="mr-6 hover:text-black">
29-
Talks
30-
</Link>
28+
<div className="justify-end flex mr-4 text-xl items-center">
29+
<Link
30+
to="/talks"
31+
className="mr-6 hover:text-black dark:hover:text-white"
32+
>
33+
Talks
34+
</Link>
35+
36+
<Link
37+
to="/blog"
38+
className="mr-6 hover:text-black dark:hover:text-white"
39+
>
40+
Blog
41+
</Link>
3142

32-
<Link to="/blog" className="hover:text-black">
33-
Blog
34-
</Link>
35-
</div>
43+
<DarkModeToggle />
3644
</div>
3745
</nav>
3846
)}

Diff for: src/components/Layout.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import Footer from "./Footer";
44
import Header from "./Header";
55

66
const Layout: React.SFC = ({ children }) => (
7-
<>
7+
<div className="dark:bg-gray-800 dark:text-white">
88
<Header />
99
<main className="min-h-screen mx-auto px-4 py-8 max-w-2xl sm:px-6 sm:py-12 lg:max-w-3xl lg:py-16 2xl:max-w-4xl xl:px-0">
1010
{children}
1111
</main>
1212
<Footer />
13-
</>
13+
</div>
1414
);
1515

1616
export default Layout;

Diff for: src/components/talks/Talk.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const Talk: React.SFC<TalkProps> = ({ talk }) => {
2626
</span>
2727
</h3>
2828
<div
29-
className="text-gray-800"
29+
className="text-gray-800 dark:text-gray-300"
3030
dangerouslySetInnerHTML={{ __html: talk.description }}
3131
/>
3232
</div>

Diff for: src/css/tailwind_setup.css

+19-19
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
*
1010
* @import "tailwindcss/base";
1111
*/
12-
@tailwind base;
12+
@tailwind base;
1313

14-
/**
14+
/**
1515
* This injects any component classes registered by plugins.
1616
*
1717
* If using `postcss-import`, use this import instead:
1818
*
1919
* @import "tailwindcss/components";
2020
*/
21-
@tailwind components;
21+
@tailwind components;
2222

23-
/**
23+
/**
2424
* Here you would add any of your custom component classes; stuff that you'd
2525
* want loaded *before* the utilities so that the utilities could still
2626
* override them.
2727
*
2828
* Example:
29-
*
29+
3030
* .btn { ... }
3131
* .form-input { ... }
3232
*
@@ -36,33 +36,33 @@
3636
* @import "components/forms";
3737
*/
3838

39-
/* Custom styling for KBD element */
40-
kbd {
41-
@apply text-gray-800;
42-
@apply text-sm;
39+
/* Custom styling for KBD element */
40+
kbd {
41+
@apply text-gray-800;
42+
@apply text-sm;
4343

44-
@apply bg-gray-100;
44+
@apply bg-gray-100;
4545

46-
@apply border-gray-400;
47-
@apply border;
48-
@apply rounded-sm;
46+
@apply border-gray-400;
47+
@apply border;
48+
@apply rounded-sm;
4949

50-
@apply shadow;
50+
@apply shadow;
5151

52-
@apply px-1;
53-
}
52+
@apply px-1;
53+
}
5454

55-
/**
55+
/**
5656
* This injects all of Tailwind's utility classes, generated based on your
5757
* config file.
5858
*
5959
* If using `postcss-import`, use this import instead:
6060
*
6161
* @import "tailwindcss/utilities";
6262
*/
63-
@tailwind utilities;
63+
@tailwind utilities;
6464

65-
/**
65+
/**
6666
* Here you would add any custom utilities you need that don't come out of the
6767
* box with Tailwind.
6868
*

Diff for: src/pages/blog.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class IndexPage extends React.Component<IndexPageProps, {}> {
4646
<h3 className="text-3xl hover:text-purple-400 duration-300 transition-colors">
4747
<Link to={node.fields.slug}>{title}</Link>
4848
</h3>
49-
<small className="italic text-gray-600">
49+
<small className="italic text-gray-600 dark:text-gray-400">
5050
{node.frontmatter.date}
5151
</small>
5252
<p
53-
className="text-gray-700 mt-1"
53+
className="text-gray-700 mt-1 dark:text-gray-300"
5454
dangerouslySetInnerHTML={{ __html: node.excerpt }}
5555
/>
5656
</div>

Diff for: src/pages/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class IndexPage extends React.Component<{}, {}> {
1010
render() {
1111
return (
1212
<>
13-
<div className="object-cover min-h-screen bg-green-800">
13+
<div className="object-cover min-h-screen bg-green-800 dark:bg-gray-800">
1414
<SEO
1515
title="Home"
1616
keywords={[
@@ -43,7 +43,7 @@ class IndexPage extends React.Component<{}, {}> {
4343
<Selfie />
4444

4545
<h2 className="text-xl lg:text-2xl font-thin p-6">
46-
I am a Software Developer &amp; Engineering Manager
46+
Software Developer &amp; Engineering Manager
4747
</h2>
4848
</div>
4949
</div>

Diff for: src/pages/talks.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TalksPage extends React.Component<TalkPageProps, {}> {
3131
<Layout>
3232
<SEO title="Talks" keywords={["programming", "conference talks"]} />
3333
<h1 className="text-center text-5xl font-bold mb-5">Talks</h1>
34-
<div className="text-md text-gray-600 italic mb-8">
34+
<div className="text-md text-gray-600 italic mb-8 dark:text-gray-400">
3535
Below are some talks that I have given over time. When possible, I
3636
have provided links to slides and/or code.
3737
</div>

Diff for: src/templates/blog-post.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const EditOnGitHubLink = ({
4747
const linkToIssues = `${repoLink}/issues`;
4848

4949
return (
50-
<div className="text-center font-light text-sm md:text-sm text-gray-600 italic mb-10 xl:mb-8">
50+
<div className="text-center font-light text-sm md:text-sm text-gray-600 italic mb-10 xl:mb-8 dark:text-gray-300">
5151
Notice something wrong? Please consider{" "}
5252
<a
5353
href={linkToPostInRepo}
@@ -79,23 +79,27 @@ const OtherPostsNav = ({
7979
next: PostInfo;
8080
}) => {
8181
return (
82-
<div className="text-gray-600 grid grid-flow-col grid-cols-3 justify-items-stretch align-middle items-center text-xs sm:text-sm lg:text-base">
82+
<div className="text-gray-600 grid grid-flow-col grid-cols-3 justify-items-stretch align-middle items-center text-xs sm:text-sm lg:text-base dark:text-gray-300">
8383
{previous ? (
84-
<Link to={previous.fields.slug} rel="prev" className="flex flex-row">
84+
<Link
85+
to={previous.fields.slug}
86+
rel="prev"
87+
className="flex flex-row hover:text-purple-400"
88+
>
8589
<span className="self-center flex-none mr-2"></span>
8690
<span>{previous.frontmatter.title}</span>
8791
</Link>
8892
) : (
8993
<span></span>
9094
)}
91-
<Link to="/blog" className="text-center">
95+
<Link to="/blog" className="text-center hover:text-purple-400">
9296
- All Posts -
9397
</Link>
9498
{next ? (
9599
<Link
96100
to={next.fields.slug}
97101
rel="next"
98-
className="flex flex-row justify-right"
102+
className="flex flex-row justify-right hover:text-purple-400"
99103
>
100104
<span className="text-right">{next.frontmatter.title}</span>
101105
<span className="self-center flex-none ml-2"></span>
@@ -115,13 +119,13 @@ class BlogPostTemplate extends React.Component<BlogPostTemplateProps, {}> {
115119

116120
return (
117121
<Layout>
118-
<article className="prose prose-sm sm:prose lg:prose-lg xl:prose-xl">
122+
<article className="prose prose-sm sm:prose lg:prose-lg xl:prose-xl dark:prose-light">
119123
<SEO title={post.frontmatter.title} description={post.excerpt} />
120124
<h1>{post.frontmatter.title}</h1>
121125
<div dangerouslySetInnerHTML={{ __html: post.html }} />
122126
</article>
123127

124-
<div className="flex justify-end text-xs md:text-sm text-gray-600 font-light italic mb-2">
128+
<div className="flex justify-end text-xs md:text-sm text-gray-600 font-light italic mb-2 dark:text-gray-400">
125129
<time dateTime={post.frontmatter.date}>{post.frontmatter.date}</time>
126130
</div>
127131

0 commit comments

Comments
 (0)