This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
159 lines (150 loc) · 3.8 KB
/
index.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import React from 'react'
import { compose } from 'react-apollo'
import {
Container,
RawHtml,
fontFamilies,
mediaQueries,
colors,
ColorContext
} from '@project-r/styleguide'
import Meta from './Meta'
import Header from './Header'
import Footer from './Footer'
import Box from './Box'
import ProlongBox from './ProlongBox'
import { HEADER_HEIGHT, HEADER_HEIGHT_MOBILE } from '../constants'
import { css } from 'glamor'
import withMe from '../../lib/apollo/withMe'
import withT from '../../lib/withT'
import withInNativeApp from '../../lib/withInNativeApp'
import 'glamor/reset'
css.global('html', { boxSizing: 'border-box' })
css.global('*, *:before, *:after', { boxSizing: 'inherit' })
css.global('body', {
width: '100%',
fontFamily: fontFamilies.sansSerifRegular
})
// avoid gray rects over links and icons on iOS
css.global('*', {
WebkitTapHighlightColor: 'transparent'
})
// avoid orange highlight, observed around full screen gallery, on Android
css.global('div:focus', {
outline: 'none'
})
const styles = {
bodyGrowerContainer: css({
minHeight: '100vh',
display: 'flex',
flexDirection: 'column'
}),
padHeader: css({
// minus 1px for first sticky hr from header
// - otherwise there is a jump when scroll 0 and opening hamburger
paddingTop: HEADER_HEIGHT_MOBILE - 1,
[mediaQueries.mUp]: {
paddingTop: HEADER_HEIGHT - 1
}
}),
bodyGrower: css({
flexGrow: 1
}),
content: css({
paddingTop: 40,
paddingBottom: 60,
[mediaQueries.mUp]: {
paddingTop: 80,
paddingBottom: 120
}
})
}
export const MainContainer = ({ children }) => (
<Container style={{ maxWidth: '840px' }}>{children}</Container>
)
export const Content = ({ children, style }) => (
<div {...styles.content} style={style}>
{children}
</div>
)
const Index = ({
t,
me,
children,
raw,
meta,
nav,
cover,
inNativeApp,
inNativeIOSApp,
onPrimaryNavExpandedChange,
primaryNavExpanded,
secondaryNav,
showSecondary,
formatColor,
headerAudioPlayer,
onSearchClick,
footer = true,
pullable,
dark
}) => (
<ColorContext.Provider value={dark && colors.negative}>
<div {...(footer || inNativeApp ? styles.bodyGrowerContainer : undefined)}>
{/* body growing only needed when rendering a footer */}
<div
{...(footer || inNativeApp ? styles.bodyGrower : undefined)}
{...(!cover ? styles.padHeader : undefined)}
>
{dark && (
<style
dangerouslySetInnerHTML={{
__html: `html, body { background-color: ${colors.negative.containerBg}; color: ${colors.negative.text}; }`
}}
/>
)}
{!!meta && <Meta data={meta} />}
<Header
dark={dark && !inNativeIOSApp}
me={me}
cover={cover}
onPrimaryNavExpandedChange={onPrimaryNavExpandedChange}
primaryNavExpanded={primaryNavExpanded}
secondaryNav={secondaryNav}
showSecondary={showSecondary}
formatColor={formatColor}
headerAudioPlayer={headerAudioPlayer}
pullable={pullable}
/>
<noscript>
<Box style={{ padding: 30 }}>
<RawHtml
dangerouslySetInnerHTML={{
__html: t('noscript')
}}
/>
</Box>
</noscript>
{me && me.prolongBeforeDate !== null && (
<ProlongBox
t={t}
prolongBeforeDate={me.prolongBeforeDate}
dark={dark}
/>
)}
{raw ? (
children
) : (
<MainContainer>
<Content>{children}</Content>
</MainContainer>
)}
</div>
{!inNativeApp && footer && <Footer />}
</div>
</ColorContext.Provider>
)
export default compose(
withMe,
withT,
withInNativeApp
)(Index)