-
Notifications
You must be signed in to change notification settings - Fork 2
/
DoubleMarkdownComponent.jsx
56 lines (54 loc) · 1.94 KB
/
DoubleMarkdownComponent.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';
import Editor from './ReactMarkdownMediumEditor';
import Tabs, {TabPane} from 'rc-tabs';
import onResize from './mixins/on-resize';
import i18n from 'meteor/universe:i18n';
const T = i18n.createComponent('universe:react-markdown-wysiwyg');
export default React.createClass({
displayName: 'DoubleMarkdownComponent',
mixins: [onResize],
getInitialState () {
return {
activeKey: '1',
markdown: this.props.markdown
};
},
render () {
let style = {minHeight: this.state.height};
return (
<Tabs activeKey={this.state.activeKey} onChange={this.onChangeActiveTab}>
<TabPane tab={T.__('visual')} key="1">
<Editor
className={'editor' + (this.props.className? ' ' + this.props.className : '')}
style={style}
markdown={this.state.markdown}
onChange={this.onChange}
options={this.props.options}
/>
</TabPane>
<TabPane tab={T.__('markdown')} key="2">
<textarea className={'editor' + (this.props.className? ' ' + this.props.className: '')}
style={style}
value={this.state.markdown}
onChange={event => this.onChange(event.target.value)}
placeholder={T.__('typeYourText')}
/>
</TabPane>
</Tabs>
);
},
onChangeActiveTab (key) {
this.setState({
activeKey: key
});
},
onResize () {
this.setState({height: Math.max(ReactDOM.findDOMNode(this).clientHeight, 100)});
},
onChange (markdown) {
this.setState({markdown});
if (this.props.onChange) {
this.props.onChange(markdown);
}
}
});