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

77 lines
1.9 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
2016-08-11 18:21:32 -03:00
import RawEditor from './MarkdownControlElements/RawEditor';
import VisualEditor from './MarkdownControlElements/VisualEditor';
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-08-17 09:52:06 -03:00
constructor(props) {
2016-08-11 18:21:32 -03:00
super(props);
this.useVisualEditor = this.useVisualEditor.bind(this);
this.useRawEditor = this.useRawEditor.bind(this);
}
2016-08-17 09:52:06 -03:00
useVisualEditor() {
2016-08-11 18:21:32 -03:00
this.props.switchVisualMode(true);
}
2016-08-17 09:52:06 -03:00
useRawEditor() {
2016-08-11 18:21:32 -03:00
this.props.switchVisualMode(false);
}
renderEditor() {
const { editor, onChange, onAddMedia, getMedia, value } = this.props;
if (editor.get('useVisualMode')) {
return (
<div>
<button onClick={this.useRawEditor}>Switch to Raw Editor</button>
<VisualEditor
onChange={onChange}
onAddMedia={onAddMedia}
getMedia={getMedia}
2016-08-17 09:52:06 -03:00
registeredComponents={editor.get('registeredComponents')}
2016-08-11 18:21:32 -03:00
value={value}
/>
</div>
);
} else {
return (
<div>
<button onClick={this.useVisualEditor}>Switch to Visual Editor</button>
<RawEditor
onChange={onChange}
onAddMedia={onAddMedia}
getMedia={getMedia}
value={value}
/>
</div>
);
}
}
2016-05-30 16:55:32 -07:00
render() {
return (
2016-08-11 18:21:32 -03:00
<div>
{ this.renderEditor() }
</div>
2016-08-01 16:41:55 -03:00
);
2016-05-30 16:55:32 -07:00
}
}
2016-08-01 16:41:55 -03:00
export default MarkdownControl;
MarkdownControl.propTypes = {
2016-08-11 18:21:32 -03:00
editor: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
2016-08-08 18:51:53 -03:00
onAddMedia: PropTypes.func.isRequired,
getMedia: PropTypes.func.isRequired,
2016-08-11 18:21:32 -03:00
switchVisualMode: PropTypes.func.isRequired,
value: PropTypes.node,
};
2016-08-11 18:21:32 -03:00
export default connect(
state => ({ editor: state.editor }),
{ switchVisualMode }
)(MarkdownControl);