-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.tsx
46 lines (42 loc) · 1.5 KB
/
index.tsx
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
import React from 'react'
import { AnyObject } from '@financial-times/anvil-types-generic'
import { getBootstrapJS, formatConfigJSON } from '@financial-times/anvil-ui-bootstrap'
import { corePolyfillServiceUrl, enhancedPolyfillServiceUrl } from './polyfill'
import DocumentHead, { TDocumentHeadProps } from './components/DocumentHead'
interface Props extends TDocumentHeadProps {
children?: any
initialProps?: AnyObject
coreScriptsToLoad: string[]
enhancedScriptsToLoad: string[]
}
export default function Shell(props: Props) {
const coreScripts = [corePolyfillServiceUrl, ...props.coreScriptsToLoad]
const enhancedScripts = [enhancedPolyfillServiceUrl, ...props.enhancedScriptsToLoad]
const bootstrapConfig = formatConfigJSON(coreScripts, enhancedScripts)
return (
<html className="no-js core">
<head>
<DocumentHead {...props} />
<script
id="initial-props"
type="application/json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(props.initialProps) }}
/>
<script
id="bootstrap-config"
type="application/json"
dangerouslySetInnerHTML={{ __html: bootstrapConfig }}
/>
<script dangerouslySetInnerHTML={{ __html: getBootstrapJS() }} />
</head>
<Body contents={props.children} />
</html>
)
}
function Body({ contents }) {
if (typeof contents === 'string') {
return <body dangerouslySetInnerHTML={{ __html: contents }} />
} else {
return <body>{contents}</body>
}
}