Skip to content

Commit e1bb5bf

Browse files
committed
Improve 404
1 parent bcf2ae4 commit e1bb5bf

File tree

7 files changed

+65
-10
lines changed

7 files changed

+65
-10
lines changed

src/components/header/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
}
1818
}
1919

20+
&--primary {
21+
position: static;
22+
background: var(--primary-color);
23+
}
24+
2025
&--logo {
2126
width: 10rem;
2227
height: 10rem;

src/components/header/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import React, { Component } from 'react';
2+
import { Link, navigate } from 'gatsby';
3+
import classnames from 'classnames';
24

35
import Container from '../container';
46
import Logo from '../logo';
57

68
import './index.css';
79

810
export default class Header extends Component {
9-
onNavClick(e) {
11+
static defaultProps = {
12+
variant: 'transparent',
13+
};
14+
15+
onNavClick = e => {
1016
e.preventDefault();
1117

1218
const target = e.target;
1319
const destinationId = target.getAttribute('data-destination');
20+
21+
if (this.props.variant === 'primary') {
22+
navigate(`/#${destinationId}`);
23+
return;
24+
}
25+
1426
const destinationDom = window.document.querySelector(`#${destinationId}`);
1527

1628
if (!destinationDom) {
@@ -21,13 +33,21 @@ export default class Header extends Component {
2133
top: destinationDom.offsetTop,
2234
behavior: 'smooth',
2335
});
24-
}
36+
};
2537

2638
render() {
39+
const { variant } = this.props;
40+
2741
return (
28-
<div className="Header">
42+
<div
43+
className={classnames('Header', {
44+
'Header--primary': variant === 'primary',
45+
})}
46+
>
2947
<Container size="large">
30-
<Logo />
48+
<Link to="/">
49+
<Logo />
50+
</Link>
3151
<ul className="Header--links">
3252
<li>
3353
<a

src/components/layout/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import Footer from '../footer';
5+
import Header from '../header';
56

67
import './reset.css';
78
import './theme.css';
89
import './fonts.css';
910
import './typography.css';
1011

11-
const Layout = ({ children }) => (
12+
const Layout = ({ children, is404 }) => (
1213
<>
14+
<Header variant={is404 ? 'primary' : 'transparent'} />
1315
<main>{children}</main>
1416
<Footer />
1517
</>

src/components/layout/theme.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,18 @@
2828
--grid-columns: 1fr 1fr 1fr;
2929
}
3030
}
31+
32+
#___gatsby {
33+
min-height: 100vh;
34+
}
35+
36+
#gatsby-focus-wrapper {
37+
display: flex;
38+
flex-direction: column;
39+
40+
min-height: 100vh;
41+
}
42+
43+
main {
44+
flex-grow: 1;
45+
}

src/pages/404.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.page-404 {
2+
margin-top: 5rem;
3+
margin-bottom: 5rem;
4+
}

src/pages/404.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ import React from 'react';
22

33
import Layout from '../components/layout';
44
import SEO from '../components/seo';
5+
import Container from '../components/container';
6+
7+
import './404.css';
58

69
const NotFoundPage = () => (
7-
<Layout>
10+
<Layout is404>
811
<SEO title="404: Not found" />
9-
<h1>NOT FOUND</h1>
10-
<p>You just hit a route that doesn&#39;t exist... the sadness.</p>
12+
<Container className="page-404" size="medium">
13+
<h1>Oh no :(</h1>
14+
<p>
15+
Can't find any{' '}
16+
<span role="image" aria-label="pizza">
17+
🍕
18+
</span>{' '}
19+
here
20+
</p>
21+
</Container>
1122
</Layout>
1223
);
1324

src/pages/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import React from 'react';
22

33
import Layout from '../components/layout';
44
import SEO from '../components/seo';
5-
import Header from '../components/header';
65
import Hero from '../components/hero';
76
import PastEvents from '../components/past-events';
87
import ContactUs from '../components/contact-us';
98

109
export default props => (
1110
<Layout>
1211
<SEO title="Home" />
13-
<Header />
1412
<Hero />
1513
<PastEvents />
1614
<ContactUs />

0 commit comments

Comments
 (0)