joyent-portal/packages/ui-toolkit/src/layout/root-container.js

65 lines
1.3 KiB
JavaScript
Raw Normal View History

import { Component } from 'react';
import { injectGlobal } from 'styled-components';
import FontFaceObserver from 'fontfaceobserver';
import { fontFaces } from '../typography/fonts';
import theme from '../theme';
import { loadedFontFamily } from '../typography';
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`
[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};
}
`;
Promise.all(observers.map(obs => obs.load())).then(() => {
document.documentElement.className += ' fonts-loaded';
});
}
render() {
return this.props.children;
}
}
export default withTheme(RootContainer);