-
Notifications
You must be signed in to change notification settings - Fork 11
/
BackgroundSection.js
118 lines (107 loc) · 3.71 KB
/
BackgroundSection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React from 'react'
import { graphql, useStaticQuery } from 'gatsby'
import styled from 'styled-components'
import Img from 'gatsby-image'
import BackgroundImage from 'gatsby-background-image'
// Use the following to support legacy browsers like IE11:
// import BackgroundImage from 'gatsby-background-image-es5'
import { generateMedia } from 'styled-media-query'
import { StyledFullScreenWrapper } from './SharedStyledComponents'
const media = generateMedia()
/**
* In this functional component a <BackgroundImage /> is compared to an <Img />.
* @param className string className(s) from styled-components.
* @param children nodes Child-components from index.js
* @return {*}
* @constructor
*/
const BackgroundSection = ({ className, children }) => {
const { desktop } = useStaticQuery(
graphql`
query {
desktop: file(relativePath: { eq: "seamless-bg-desktop.jpg" }) {
childImageSharp {
fluid(quality: 90, maxWidth: 4160) {
...GatsbyImageSharpFluid_withWebp_tracedSVG
}
}
}
}
`
)
const imageData = desktop.childImageSharp.fluid
return (
<StyledFullScreenWrapper>
<div style={{ height: 4000, display: 'block' }}></div>
<StyledSymetryWrapper>
<BackgroundImage
Tag="section"
className={className}
// To style via external CSS see layout.css last examples:
// className="test"
fluid={imageData}
backgroundColor={`#040e18`}
// Title get's passed to both container and noscriptImg.
title="gbitest"
// style={{
// // Defaults are overwrite-able by setting one of the following:
// // backgroundSize: '',
// // backgroundPosition: '',
// // backgroundRepeat: '',
// }}
// To "force" the classic fading in of every image (especially on
// imageData change for fluid / fixed) by setting `soft` on `fadeIn`:
// fadeIn={`soft`}
// To be able to use stacking context changing elements yourself,
// set this to true to disable the "opacity hack":
// preserveStackingContext={true}
// You can "safely" (look them up beforehand ; ) add other props:
id="gbitest"
role="img"
aria-label="gbitest"
>
{children}
</BackgroundImage>
</StyledSymetryWrapper>
<StyledSymetryWrapper>
<StyledWelcomeImage
fluid={imageData}
backgroundColor={`#040e18`}
objectFit="cover"
objectPosition="50% 50%"
/>
</StyledSymetryWrapper>
</StyledFullScreenWrapper>
)
}
const StyledSymetryWrapper = styled.div`
width: 50vw;
height: 100%;
overflow: hidden;
`
const StyledWelcomeImage = styled(Img)`
width: 100vw;
height: auto;
`
const StyledBackgroundSection = styled(BackgroundSection)`
width: 100vw;
// These three crucial styles (if existing) are directly parsed and added to
// the pseudo-elements without further ado (except when overwritten).
//background-repeat: repeat-y;
//background-position: left center;
//background-size: cover;
// With media-queries you have to overwrite the default options (see style={{}} above).
// ${media.lessThan('large')`
// background-size: cover;
// &:after, &:before {
// background-size: contain;
// }
// `}
// For pseudo-elements you have to overwrite the default options (see style={{}} above).
// See: https://github.com/timhagn/gatsby-background-image/#styling--passed-through-styles
//&:after, &:before {
// background-clip: content-box;
// background-size: contain;
//}
`
export default StyledBackgroundSection