Skip to content

Commit 7dbec96

Browse files
committed
Bg on front splash
1 parent 697af57 commit 7dbec96

File tree

10 files changed

+204
-28
lines changed

10 files changed

+204
-28
lines changed

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ module.exports = {
1212
env: {
1313
browser: true,
1414
},
15+
parserOptions: {
16+
sourceType: 'module',
17+
},
1518
overrides: [
1619
{
1720
files: ['gatsby-*.js'],
1821
parserOptions: {
19-
sourceType: 'script',
22+
sourceType: 'module',
2023
ecmaVersion: 2015,
2124
},
2225
env: {

gatsby-browser.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
* See: https://www.gatsbyjs.org/docs/browser-apis/
55
*/
66

7-
// You can delete this file if you're not using it
7+
export const onClientEntry = () => {
8+
// IntersectionObserver polyfill for gatsby-background-image (Safari, IE)
9+
if (typeof window.IntersectionObserver === `undefined`) {
10+
import(`intersection-observer`)
11+
console.log(`# IntersectionObserver is polyfilled!`)
12+
}
13+
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
"dependencies": {
88
"classnames": "^2.2.6",
99
"gatsby": "^2.15.28",
10+
"gatsby-background-image": "^0.8.17",
1011
"gatsby-image": "^2.2.23",
1112
"gatsby-plugin-manifest": "^2.2.20",
1213
"gatsby-plugin-netlify": "^2.1.17",
1314
"gatsby-plugin-offline": "^3.0.11",
1415
"gatsby-plugin-preload-fonts": "^1.0.14",
1516
"gatsby-plugin-react-helmet": "^3.1.10",
1617
"gatsby-plugin-sass": "^2.1.17",
17-
"gatsby-plugin-sharp": "^2.2.27",
18+
"gatsby-plugin-sharp": "^2.2.36",
1819
"gatsby-source-filesystem": "^2.1.28",
19-
"gatsby-transformer-sharp": "^2.2.19",
20+
"gatsby-transformer-sharp": "^2.3.2",
2021
"inter-ui": "^3.10.0",
22+
"intersection-observer": "^0.7.0",
2123
"node-sass": "^4.12.0",
2224
"prop-types": "^15.7.2",
2325
"react": "^16.10.1",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react'
2+
import { graphql, useStaticQuery } from 'gatsby'
3+
import BackgroundImage from 'gatsby-background-image'
4+
import styled from 'styled-components'
5+
6+
const SectionBaseWithBg = ({ children, className, backgroundImage }) => {
7+
const images = useStaticQuery(
8+
graphql`
9+
query {
10+
splashFront: file(relativePath: { eq: "splash-front.png" }) {
11+
childImageSharp {
12+
fluid(quality: 90, maxWidth: 3360) {
13+
...GatsbyImageSharpFluid_withWebp
14+
}
15+
}
16+
}
17+
}
18+
`
19+
)
20+
21+
const image = images[backgroundImage]
22+
console.log(image)
23+
return (
24+
<BackgroundImage
25+
Tag="section"
26+
className={className}
27+
fluid={image.childImageSharp.fluid}
28+
backgroundColor={`#040e18`}
29+
>
30+
{children}
31+
</BackgroundImage>
32+
)
33+
}
34+
35+
const StyledSectionBaseWithBg = styled(SectionBaseWithBg)`
36+
width: 100%;
37+
background-position: bottom center;
38+
background-repeat: repeat-y;
39+
background-size: cover;
40+
`
41+
42+
export default StyledSectionBaseWithBg

src/components/sections/base.js

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

33
import classNames from 'classnames'
44

5-
const SectionBase = ({ children, style, theme }) => {
5+
import SectionBaseWithBg from './base-with-bg'
6+
7+
const SectionBase = ({ children, style, theme, backgroundImage }) => {
68
let sectionClasses = classNames('section', {
79
[`section--${theme}`]: theme,
810
[`section--${style}`]: style,
911
})
10-
return <section className={sectionClasses}>{children}</section>
12+
if (backgroundImage) {
13+
return (
14+
<SectionBaseWithBg
15+
className={sectionClasses}
16+
backgroundImage={backgroundImage}
17+
>
18+
{children}
19+
</SectionBaseWithBg>
20+
)
21+
} else {
22+
return <section className={sectionClasses}>{children}</section>
23+
}
1124
}
1225

1326
export default SectionBase

src/components/sections/splash.js

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

33
import SectionBase from './base'
44

5-
const SectionSplash = ({ children }) => (
6-
<SectionBase theme="dark" style="splash">
5+
const SectionSplash = ({ children, backgroundImage }) => (
6+
<SectionBase theme="dark" style="splash" backgroundImage={backgroundImage}>
77
<div className="wrapper">{children}</div>
88
</SectionBase>
99
)

src/images/splash-front.png

7.83 MB
Loading

src/pages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const IndexPage = () => (
1414
<Layout>
1515
<SEO title="Home" />
1616
<div className="u-height--viewport u-display--flex u-flex-direction--column">
17-
<SectionSplash>
17+
<SectionSplash backgroundImage="splashFront">
1818
<div className="section__content">
1919
<h1 className="u-margin-top--xl">Secure, fast & easy.</h1>
2020
<p className="u-font-size--large">

src/stylesheets/components/_section.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
&--splash {
2929
padding: 0;
3030
flex: 1;
31+
background-size: cover;
3132
}
3233

3334
&--splash & {

0 commit comments

Comments
 (0)