2017-09-20 12:30:53 +03:00
|
|
|
import { Component } from 'react';
|
2017-10-04 20:30:10 +03:00
|
|
|
import { injectGlobal } from 'styled-components';
|
2017-09-20 12:30:53 +03:00
|
|
|
import FontFaceObserver from 'fontfaceobserver';
|
|
|
|
import { fontFaces } from '../typography/fonts';
|
2017-10-04 20:30:10 +03:00
|
|
|
import theme from '../theme';
|
|
|
|
import { loadedFontFamily } from '../typography';
|
2017-09-20 12:30:53 +03:00
|
|
|
|
|
|
|
const families = Object.keys(
|
|
|
|
Object.values(fontFaces)
|
|
|
|
.map(({ family }) => family)
|
|
|
|
.reduce((sum, name) => Object.assign(sum, { [name]: 1 }), {})
|
|
|
|
);
|
|
|
|
|
|
|
|
const observers = families.map(name => new FontFaceObserver(name));
|
|
|
|
|
|
|
|
class RootContainer extends Component {
|
|
|
|
componentWillMount() {
|
|
|
|
// eslint-disable-next-line no-unused-expressions
|
|
|
|
injectGlobal`
|
2017-10-04 20:30:10 +03:00
|
|
|
[hidden] {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
html {
|
|
|
|
line-height: 1.15;
|
|
|
|
text-size-adjust: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
body {
|
|
|
|
font-size: 15px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
background: ${theme.background};
|
|
|
|
|
|
|
|
${loadedFontFamily};
|
|
|
|
}
|
|
|
|
|
|
|
|
html,
|
|
|
|
body,
|
|
|
|
#root {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.CodeMirror,
|
|
|
|
.ReactCodeMirror {
|
|
|
|
height: 100% !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.CodeMirror {
|
|
|
|
border: solid 1px ${theme.grey};
|
|
|
|
}
|
2017-09-20 12:30:53 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
Promise.all(observers.map(obs => obs.load())).then(() => {
|
|
|
|
document.documentElement.className += ' fonts-loaded';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return this.props.children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withTheme(RootContainer);
|