Skip to content

Instantly share code, notes, and snippets.

@SilencerWeb
Created July 23, 2019 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SilencerWeb/6e1953a08b764737b362fa26f6150884 to your computer and use it in GitHub Desktop.
Save SilencerWeb/6e1953a08b764737b362fa26f6150884 to your computer and use it in GitHub Desktop.
import * as React from 'react'
import { StickyContainer, Sticky } from 'react-sticky'
import { OfferSection, OfferSidebar, OfferInformationForm } from 'components/pages/offer'
import { Layout } from 'components/shared'
import { OfferPageContext } from 'context'
import { getWindowOuterWidth } from 'libs'
import { breakpoint } from 'variables'
// eslint-disable-next-line import/no-default-export
export default class extends React.Component {
state = {
values: null,
errors: null,
windowOuterWidth: getWindowOuterWidth()
}
updateValuesAndErrors = ({ values, errors }) => {
this.setState({ values, errors })
}
handleWindowResize = () => this.setState({ windowOuterWidth: getWindowOuterWidth() })
componentDidMount() {
this.setState({ windowOuterWidth: getWindowOuterWidth() })
window.addEventListener('resize', this.handleWindowResize)
}
componentWillUnmount() {
window.removeEventListener('resize', this.handleWindowResize)
}
render() {
const pageMetadata = {
title: 'Offer',
description: 'Offer'
}
const contextValue = {
values: this.state.values,
errors: this.state.errors,
updateValuesAndErrors: this.updateValuesAndErrors
}
return (
<OfferPageContext.Provider value={contextValue}>
<Layout pageMetadata={pageMetadata} headerType="minimalistic">
{
this.state.windowOuterWidth < breakpoint.smMd
? (
<OfferSection>
<StickyContainer>
<Sticky>
{({ style }) => (
<div style={{ ...style, zIndex: 9 }}>
<OfferSidebar />
</div>
)}
</Sticky>
<OfferInformationForm />
</StickyContainer>
</OfferSection>
)
: (
<OfferSection>
<OfferSidebar />
<OfferInformationForm />
</OfferSection>
)
}
</Layout>
</OfferPageContext.Provider>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment