import React from 'react'; import PropTypes from 'prop-types'; import Select from 'react-select'; import AceEditor from 'react-ace'; import 'brace/mode/css'; import 'brace/theme/github'; import ModalTrigger from '../../components/ModalTrigger'; const propTypes = { initialCss: PropTypes.string, triggerNode: PropTypes.node.isRequired, onChange: PropTypes.func, templates: PropTypes.array, }; const defaultProps = { initialCss: '', onChange: () => {}, templates: [], }; class CssEditor extends React.PureComponent { constructor(props) { super(props); this.state = { css: props.initialCss, 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; } } changeCssTemplate(opt) { this.changeCss(opt.css); } renderTemplateSelector() { if (this.props.templates) { return (
Load a template