Skip to content

Commit 03bcd31

Browse files
committed
dark-mode: make it happen
1 parent e35cbb7 commit 03bcd31

20 files changed

+166
-209
lines changed

gatsby-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
`gatsby-plugin-styled-components`,
1010
`gatsby-plugin-react-helmet`,
1111
`gatsby-alias-imports`,
12+
'gatsby-plugin-use-dark-mode',
1213
{
1314
resolve: `gatsby-source-filesystem`,
1415
options: {

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"gatsby-plugin-sharp": "^2.6.10",
2121
"gatsby-plugin-sitemap": "^2.4.4",
2222
"gatsby-plugin-styled-components": "^3.3.3",
23+
"gatsby-plugin-use-dark-mode": "^1.1.2",
2324
"gatsby-plugin-web-font-loader": "^1.0.4",
2425
"gatsby-remark-images": "^3.3.9",
2526
"gatsby-remark-prismjs": "^3.5.3",
@@ -32,7 +33,8 @@
3233
"react": "^16.13.1",
3334
"react-dom": "^16.13.1",
3435
"react-helmet": "^5.2.1",
35-
"styled-components": "^5.1.1"
36+
"styled-components": "^5.1.1",
37+
"use-dark-mode": "^2.3.1"
3638
},
3739
"devDependencies": {
3840
"@textlint-rule/textlint-rule-no-unmatched-pair": "^1.0.7",

src/components/GlobalStyle.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { createGlobalStyle } from 'styled-components'
2+
3+
const GlobalStyle = createGlobalStyle`
4+
body {
5+
background: var(--background);
6+
color: var(--text-primary);
7+
8+
&.light-mode {
9+
--background: #e7ebef;
10+
--text-primary: #1d2124;
11+
--text-secondary: #6a7884;
12+
--text-content: #333;
13+
--accent-primary: #29D455;
14+
}
15+
16+
&.dark-mode {
17+
--background: #191b1f;
18+
--text-primary: #FFF;
19+
--text-secondary: #FFFC;
20+
--text-content: #FFFC;
21+
--accent-primary: #29D455;
22+
}
23+
}
24+
25+
.gatsby-highlight {
26+
font-size: 15px;
27+
}
28+
29+
:not(pre) > code[class*="language-"] {
30+
font-size: 15px;
31+
padding: .1em .4em;
32+
}
33+
`
34+
35+
export default GlobalStyle

src/components/Header.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import styled from 'styled-components'
44
import Section from './Section'
55
import LogoMobile from './LogoMobile'
66
import LogoDesktop from './LogoDesktop'
7-
import { theme } from 'styles/theme'
7+
import { fonts, sizes } from 'styles/theme'
88
import { screen } from 'styles/screen'
99

1010
const Wrapper = styled(Section)`
1111
position: relative;
1212
width: 100%;
1313
1414
${screen.lg} {
15-
max-width: ${theme.light.sizes.max};
16-
width: ${theme.light.sizes.default};
15+
max-width: ${sizes.max};
16+
width: ${sizes.default};
1717
}
1818
`
1919

@@ -34,8 +34,7 @@ const WrapperLogoMobile = styled.div`
3434
`
3535

3636
const Nav = styled.nav`
37-
background: #e7ebef;
38-
color: ${theme.light.colors.primary};
37+
color: var(--text-secondary);
3938
padding: 15px 15px 25px 15px;
4039
margin: 0 auto;
4140
text-transform: uppercase;
@@ -52,9 +51,9 @@ const Logo = styled.a`
5251
width: 40%;
5352
5453
span {
55-
color: #6a7884 !important;
54+
color: var(--text-seconday) !important;
5655
display: inline-block;
57-
font-family: ${theme.light.fonts.text};
56+
font-family: ${fonts.text};
5857
font-size: 18px;
5958
font-weight: bold;
6059
letter-spacing: 0;
@@ -90,9 +89,9 @@ const Links = styled.div`
9089
9190
a {
9291
padding: 0;
93-
color: #333b43 !important;
92+
color: var(--text-primary);
9493
display: inline-block;
95-
font-family: ${theme.light.fonts.title};
94+
font-family: ${fonts.title};
9695
font-size: 12px;
9796
font-weight: 600;
9897
letter-spacing: 0;

src/components/Layout.js

+18-21
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,16 @@ import PropTypes from 'prop-types'
1111
import 'styles/typography.css'
1212
import 'styles/layout.css'
1313

14-
import styled, { createGlobalStyle } from 'styled-components'
14+
import styled from 'styled-components'
1515

16-
import { screen } from 'styles/screen'
17-
import { theme } from 'styles/theme'
18-
19-
import Header from './Header'
16+
import GlobalStyle from 'components/GlobalStyle'
17+
import Header from 'components/Header'
2018

21-
const GlobalStyle = createGlobalStyle`
22-
body {
23-
color: ${theme.light.colors.text}
24-
}
25-
`
19+
import { screen } from 'styles/screen'
20+
import { fonts } from 'styles/theme'
2621

2722
const Wrapper = styled.div`
28-
font-family: ${theme.light.fonts.text};
23+
font-family: ${fonts.text};
2924
padding: 15px 7px 15px 0;
3025
margin: 0 auto;
3126
width: 100%;
@@ -47,16 +42,18 @@ const Section = styled.div`
4742
}
4843
`
4944

50-
const Layout = ({ children }) => (
51-
<div>
52-
<GlobalStyle />
53-
54-
<Wrapper>
55-
<Header />
56-
<Section>{children}</Section>
57-
</Wrapper>
58-
</div>
59-
)
45+
const Layout = ({ children }) => {
46+
return (
47+
<div>
48+
<GlobalStyle />
49+
50+
<Wrapper>
51+
<Header />
52+
<Section>{children}</Section>
53+
</Wrapper>
54+
</div>
55+
)
56+
}
6057

6158
Layout.propTypes = {
6259
children: PropTypes.node.isRequired,

src/components/Link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Link = styled.a`
44
display: block;
55
font-size: 20px;
66
font-weight: 500;
7-
color: #333;
7+
color: var(--text-primary);
88
margin-bottom: 40px;
99
padding: 15px 0;
1010
line-height: 1.5em;

src/components/LogoDesktop.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/LogoMobile.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/PostAuthor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styled from 'styled-components'
44
import { screen } from 'styles/screen'
55

66
const Author = styled.div`
7-
color: #151b1f;
7+
color: var(--text-primary);
88
display: inline-block;
99
1010
font-weight: bold;

src/components/PostDate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components'
22

33
const PostDate = styled.div`
4-
color: #1d2124;
4+
color: var(--text-primary);
55
font-size: 12px;
66
font-weight: 500;
77
letter-spacing: 0;

src/components/PostLink.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import styled from 'styled-components'
33

4-
import { theme } from 'styles/theme'
4+
import { fonts } from 'styles/theme'
55
import { screen } from 'styles/screen'
66
import PostAuthor from './PostAuthor'
77

@@ -18,8 +18,8 @@ const Block = styled.div`
1818
const Publication = styled(Block)`
1919
display: inline-block;
2020
width: 100%;
21-
color: #6a7884;
22-
font-family: ${theme.light.fonts.title};
21+
color: var(--text-primary);
22+
font-family: ${fonts.title};
2323
font-size: 14px;
2424
letter-spacing: 0;
2525
@@ -30,7 +30,6 @@ const Publication = styled(Block)`
3030

3131
const Date = styled.div`
3232
display: inline-block;
33-
color: #1d2124;
3433
font-size: 12px;
3534
font-weight: 500;
3635
letter-spacing: 0;
@@ -44,7 +43,7 @@ const Date = styled.div`
4443
`
4544

4645
const Article = styled(Block)`
47-
color: #1d2124;
46+
color: var(--text-primary);
4847
display: inline-block;
4948
width: 100%;
5049
@@ -54,11 +53,11 @@ const Article = styled(Block)`
5453
`
5554

5655
const Title = styled.h1`
57-
font-family: ${theme.light.fonts.title};
56+
font-family: ${fonts.title};
5857
font-size: 24px;
5958
font-weight: bold;
6059
letter-spacing: 0;
61-
line-height: 1em;
60+
line-height: 1.5em;
6261
margin-bottom: 10px;
6362
6463
a {
@@ -68,15 +67,15 @@ const Title = styled.h1`
6867

6968
const Text = styled.p`
7069
margin: 20px 0 10px 0;
71-
font-family: ${theme.light.fonts.text};
70+
font-family: ${fonts.text};
7271
font-size: 17px;
7372
font-weight: 400;
7473
`
7574

7675
const ReadMore = styled.a`
77-
color: #6a7884;
76+
color: var(--text-secondary);
7877
display: block;
79-
font-family: ${theme.light.fonts.title};
78+
font-family: ${fonts.title};
8079
font-size: 14px;
8180
font-weight: bold;
8281
letter-spacing: 0;

src/components/Section.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import styled from 'styled-components'
22

3-
import { theme } from 'styles/theme'
3+
import { sizes } from 'styles/theme'
44
import { screen } from 'styles/screen'
55

66
const Section = styled.div`
77
margin: 0 auto;
88
width: 100%;
99
1010
${screen.lg} {
11-
max-width: ${theme.light.sizes.max};
12-
width: ${theme.light.sizes.default};
11+
max-width: ${sizes.max};
12+
width: ${sizes.default};
1313
}
1414
`
1515

0 commit comments

Comments
 (0)