",
7 | "dependencies": {
8 | "babel-plugin-styled-components": "^1.10.7",
9 | "gatsby": "^2.20.12",
10 | "gatsby-plugin-styled-components": "^3.2.1",
11 | "prop-types": "^15.7.2",
12 | "react": "^16.12.0",
13 | "react-dom": "^16.12.0",
14 | "react-helmet": "^5.2.1",
15 | "styled-components": "^5.1.0",
16 | "terser": "^4.6.11"
17 | },
18 | "devDependencies": {
19 | "prettier": "^1.19.1"
20 | },
21 | "keywords": [
22 | "gatsby"
23 | ],
24 | "license": "MIT",
25 | "scripts": {
26 | "build": "gatsby build",
27 | "develop": "gatsby develop",
28 | "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
29 | "start": "npm run develop",
30 | "serve": "gatsby serve",
31 | "clean": "gatsby clean",
32 | "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
33 | },
34 | "repository": {
35 | "type": "git",
36 | "url": "https://github.com/gatsbyjs/gatsby-starter-default"
37 | },
38 | "bugs": {
39 | "url": "https://github.com/gatsbyjs/gatsby/issues"
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/components/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import { ThemeProvider } from './ThemeContext';
4 | import GlobalStyles from './GlobalStyles';
5 |
6 | function App({ children }) {
7 | return (
8 |
9 |
10 | {children}
11 |
12 | );
13 | }
14 |
15 | export default App;
16 |
--------------------------------------------------------------------------------
/src/components/BrightTitle.js:
--------------------------------------------------------------------------------
1 | import styled from 'styled-components';
2 |
3 | export default styled.h1`
4 | color: var(--color-primary);
5 | font-size: 64px;
6 | font-weight: bold;
7 | `;
8 |
--------------------------------------------------------------------------------
/src/components/DarkToggle.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import { ThemeContext } from './ThemeContext';
4 |
5 | const DarkToggle = () => {
6 | const { colorMode, setColorMode } = React.useContext(ThemeContext);
7 |
8 | if (!colorMode) {
9 | return null;
10 | }
11 |
12 | return (
13 |
23 | );
24 | };
25 |
26 | export default DarkToggle;
27 |
--------------------------------------------------------------------------------
/src/components/GlobalStyles.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import { createGlobalStyle } from 'styled-components';
4 |
5 | const GlobalStyles = createGlobalStyle`
6 | *, *:before, *:after {
7 | box-sizing: border-box;
8 | font-family: Futura, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
9 | Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
10 |
11 | }
12 |
13 | body {
14 | background: var(--color-background);
15 | color: var(--color-text);
16 | }
17 |
18 | a {
19 | color: var(--color-secondary);
20 | }
21 | `;
22 |
23 | export default GlobalStyles;
24 |
--------------------------------------------------------------------------------
/src/components/Header.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import styled from 'styled-components';
3 |
4 | import { ThemeContext } from './ThemeContext';
5 |
6 | import DarkToggle from './DarkToggle';
7 |
8 | const Header = ({ siteTitle }) => {
9 | return (
10 |
11 | {siteTitle}
12 |
13 |
14 | );
15 | };
16 |
17 | const Wrapper = styled.header`
18 | display: flex;
19 | justify-content: space-between;
20 | padding: 16px;
21 | `;
22 |
23 | export default Header;
24 |
--------------------------------------------------------------------------------
/src/components/Layout.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Layout component that queries for data
3 | * with Gatsby's useStaticQuery component
4 | *
5 | * See: https://www.gatsbyjs.org/docs/use-static-query/
6 | */
7 |
8 | import React from 'react';
9 | import PropTypes from 'prop-types';
10 | import { useStaticQuery, graphql } from 'gatsby';
11 |
12 | import Header from './Header';
13 |
14 | const Layout = ({ children }) => {
15 | const data = useStaticQuery(graphql`
16 | query SiteTitleQuery {
17 | site {
18 | siteMetadata {
19 | title
20 | }
21 | }
22 | }
23 | `);
24 |
25 | return (
26 | <>
27 |
34 |
35 |
36 | {children}
37 |
38 | >
39 | );
40 | };
41 |
42 | Layout.propTypes = {
43 | children: PropTypes.node.isRequired,
44 | };
45 |
46 | export default Layout;
47 |
--------------------------------------------------------------------------------
/src/components/ThemeContext.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import {
4 | COLORS,
5 | COLOR_MODE_KEY,
6 | INITIAL_COLOR_MODE_CSS_PROP,
7 | } from '../constants';
8 |
9 | export const ThemeContext = React.createContext();
10 |
11 | export const ThemeProvider = ({ children }) => {
12 | const [colorMode, rawSetColorMode] = React.useState(undefined);
13 |
14 | React.useEffect(() => {
15 | const root = window.document.documentElement;
16 |
17 | // Because colors matter so much for the initial page view, we're
18 | // doing a lot of the work in gatsby-ssr. That way it can happen before
19 | // the React component tree mounts.
20 | const initialColorValue = root.style.getPropertyValue(
21 | INITIAL_COLOR_MODE_CSS_PROP
22 | );
23 |
24 | rawSetColorMode(initialColorValue);
25 | }, []);
26 |
27 | const contextValue = React.useMemo(() => {
28 | function setColorMode(newValue) {
29 | const root = window.document.documentElement;
30 |
31 | localStorage.setItem(COLOR_MODE_KEY, newValue);
32 |
33 | Object.entries(COLORS).forEach(([name, colorByTheme]) => {
34 | const cssVarName = `--color-${name}`;
35 |
36 | root.style.setProperty(cssVarName, colorByTheme[newValue]);
37 | });
38 |
39 | rawSetColorMode(newValue);
40 | }
41 |
42 | return {
43 | colorMode,
44 | setColorMode,
45 | };
46 | }, [colorMode, rawSetColorMode]);
47 |
48 | return (
49 |
50 | {children}
51 |
52 | );
53 | };
54 |
--------------------------------------------------------------------------------
/src/constants.js:
--------------------------------------------------------------------------------
1 | export const COLORS = {
2 | text: {
3 | light: 'hsl(0deg, 0%, 10%)', // white
4 | dark: 'hsl(0deg, 0%, 100%)', // near-black
5 | },
6 | background: {
7 | light: 'hsl(0deg, 0%, 100%)', // white
8 | dark: 'hsl(250deg, 70%, 7%)', // navy navy blue
9 | },
10 | primary: {
11 | light: 'hsl(340deg, 100%, 40%)', // Pinkish-red
12 | dark: 'hsl(50deg, 100%, 50%)', // Yellow
13 | },
14 | secondary: {
15 | light: 'hsl(250deg, 100%, 50%)', // Purplish-blue
16 | dark: 'hsl(190deg, 100%, 40%)', // Cyan
17 | },
18 | // Grays, scaling from least-noticeable to most-noticeable
19 | gray300: {
20 | light: 'hsl(0deg, 0%, 70%)',
21 | dark: 'hsl(0deg, 0%, 30%)',
22 | },
23 | gray500: {
24 | light: 'hsl(0deg, 0%, 50%)',
25 | dark: 'hsl(0deg, 0%, 50%)',
26 | },
27 | gray700: {
28 | light: 'hsl(0deg, 0%, 30%)',
29 | dark: 'hsl(0deg, 0%, 70%)',
30 | },
31 | };
32 |
33 | export const COLOR_MODE_KEY = 'color-mode';
34 | export const INITIAL_COLOR_MODE_CSS_PROP = '--initial-color-mode';
35 |
--------------------------------------------------------------------------------
/src/pages/404.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | import Layout from '../components/Layout';
4 |
5 | const NotFoundPage = () => (
6 |
7 | NOT FOUND
8 | You just hit a route that doesn't exist... the sadness.
9 |
10 | );
11 |
12 | export default NotFoundPage;
13 |
--------------------------------------------------------------------------------
/src/pages/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Link } from 'gatsby';
3 |
4 | import Layout from '../components/Layout';
5 | import BrightTitle from '../components/BrightTitle';
6 |
7 | const IndexPage = () => (
8 |
9 | Hello world!
10 | Welcome to your new Gatsby site.
11 | Now go build something great.
12 | Go to page 2
13 |
14 | );
15 |
16 | export default IndexPage;
17 |
--------------------------------------------------------------------------------
/src/pages/page-2.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Link } from 'gatsby';
3 |
4 | import Layout from '../components/Layout';
5 |
6 | const SecondPage = () => (
7 |
8 | Hi from the second page
9 | Welcome to page 2
10 | Go back to the homepage
11 |
12 | );
13 |
14 | export default SecondPage;
15 |
--------------------------------------------------------------------------------