Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User can choose whether to initialize markdown editor with edit mode … #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Example/components/ExampleWithOnChangeContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var ExampleWithOnChangeContent = React.createClass({
<MarkdownEditor
initialContent='My initial content'
iconsSet='materialize-ui'
onContentChange={this._onContentChange} />
onContentChange={this._onContentChange}
editMode
/>
</div>
);
},
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ React.render(<TestComponent />, document.getElementById('content'));
Optional props:

- ```onContentChange```, function to be called on each content change, getting the new content as an argument (as the property name says!)
- ```editMode```, can choose whether to initialize markdown editor with edit mode or preview mode. `true` by default
- ```styles```, see [Styling](#styling) below

You can also listen to content changes on the editor. If you are using Reflux, by listening to the changes on ```MarkdownEditorContentStore```.
Expand Down
13 changes: 8 additions & 5 deletions src/MarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ var MarkdownEditor = React.createClass({
initialContent: React.PropTypes.string.isRequired,
iconsSet: React.PropTypes.oneOf(['font-awesome', 'materialize-ui']).isRequired,
onContentChange: React.PropTypes.func,
editorTabs: React.PropTypes.bool
editorTabs: React.PropTypes.bool,
editMode: React.PropTypes.bool
},

getInitialState: function() {
var uniqueInstanceRef = Math.random().toString(36).substring(7)
return {content: this.props.initialContent, inEditMode: true, instanceRef: uniqueInstanceRef};
var uniqueInstanceRef = Math.random().toString(36).substring(7);
return {content: this.props.initialContent, inEditMode: this.props.editMode, instanceRef: uniqueInstanceRef};
},

render: function() {
Expand Down Expand Up @@ -71,7 +72,8 @@ var MarkdownEditor = React.createClass({
{editorMenu}
<MarkdownEditorTabs styles={{ styleMarkdownEditorTabs: this.props.styles.styleMarkdownEditorTabs,
styleTab: this.props.styles.styleTab,
styleActiveTab: this.props.styles.styleActiveTab}} />
styleActiveTab: this.props.styles.styleActiveTab}}
editMode={this.state.inEditMode} />
</div>
{divContent}
</div>
Expand Down Expand Up @@ -177,7 +179,8 @@ MarkdownEditor.defaultProps = {
'right': '20px',
'top': '10px'
}
}
},
editMode: true
}

module.exports = MarkdownEditor;
6 changes: 5 additions & 1 deletion src/components/MarkdownEditorTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ var objectAssign = require('object-assign');
var MarkdownEditorTabs = React.createClass({
mixins: [Reflux.ListenerMixin],

propTypes: {
editMode: React.PropTypes.bool
},

getInitialState: function() {
return {
activeTab: 0
activeTab: this.props.editMode ? 0 : 1
};
},

Expand Down