apply custom css for dashboard initially load (#4031)

This commit is contained in:
Grace Guo
2017-12-07 16:56:40 -08:00
committed by GitHub
parent 0a3d2fccd4
commit 61755f0b7d
2 changed files with 27 additions and 25 deletions

View File

@@ -30,30 +30,10 @@ class CssEditor extends React.PureComponent {
cssTemplateOptions: [],
};
}
componentWillMount() {
this.updateDom();
}
changeCss(css) {
this.setState({ css }, this.updateDom);
this.props.onChange(css);
}
updateDom() {
const css = this.state.css;
const className = 'CssEditor-css';
const head = document.head || document.getElementsByTagName('head')[0];
let style = document.querySelector('.' + className);
if (!style) {
style = document.createElement('style');
style.className = className;
style.type = 'text/css';
head.appendChild(style);
}
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.innerHTML = css;
}
this.setState({ css }, () => {
this.props.onChange(css);
});
}
changeCssTemplate(opt) {
this.changeCss(opt.css);