static-cms/src/components/Widgets/MarkdownControl.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
import registry from '../../lib/registry';
2016-08-11 18:21:32 -03:00
import RawEditor from './MarkdownControlElements/RawEditor';
import VisualEditor from './MarkdownControlElements/VisualEditor';
2016-08-18 10:51:38 -03:00
import { processEditorPlugins } from './richText';
2016-08-11 18:21:32 -03:00
import { connect } from 'react-redux';
import { switchVisualMode } from '../../actions/editor';
2016-08-03 10:30:42 -03:00
2016-08-01 16:41:55 -03:00
class MarkdownControl extends React.Component {
2016-10-03 14:33:48 +02:00
static propTypes = {
editor: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
onAddMedia: PropTypes.func.isRequired,
getMedia: PropTypes.func.isRequired,
switchVisualMode: PropTypes.func.isRequired,
value: PropTypes.node,
};
2016-08-11 18:21:32 -03:00
constructor(props) {
super(props);
this.state = { mode: 'visual' };
}
2016-08-18 10:51:38 -03:00
componentWillMount() {
processEditorPlugins(registry.getEditorComponents());
2016-08-18 10:51:38 -03:00
}
handleMode = (mode) => {
this.setState({ mode });
2016-10-03 14:25:27 +02:00
};
2016-08-11 18:21:32 -03:00
render() {
const { onChange, onAddMedia, onRemoveMedia, getMedia, value } = this.props;
const { mode } = this.state;
if (mode === 'visual') {
2016-08-11 18:21:32 -03:00
return (
<div className="cms-editor-visual">
2016-08-11 18:21:32 -03:00
<VisualEditor
onChange={onChange}
onAddMedia={onAddMedia}
onRemoveMedia={onRemoveMedia}
onMode={this.handleMode}
getMedia={getMedia}
value={value}
2016-08-11 18:21:32 -03:00
/>
</div>
);
}
return (
<div className="cms-editor-raw">
<RawEditor
onChange={onChange}
onAddMedia={onAddMedia}
onRemoveMedia={onRemoveMedia}
onMode={this.handleMode}
getMedia={getMedia}
value={value}
/>
</div>
);
2016-08-11 18:21:32 -03:00
}
2016-05-30 16:55:32 -07:00
}
2016-08-11 18:21:32 -03:00
export default connect(
state => ({ editor: state.editor }),
{ switchVisualMode }
)(MarkdownControl);