demo.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var React = require('react');
  2. var ReactDOM = require('react-dom');
  3. var SimpleMDEReact = require('../../src/index');
  4. var Editor = require('./Editor');
  5. let counter = 1;
  6. module.exports = React.createClass({
  7. getInitialState() {
  8. return {
  9. textValue1: "I am the initial value. Erase me, or try the button above.",
  10. textValue2: "Focus this text area and then use the Up and Down arrow keys to see the `extraKeys` prop in action"
  11. }
  12. },
  13. extraKeys() {
  14. return {
  15. Up: function(cm) {
  16. cm.replaceSelection(" surprise. ");
  17. },
  18. Down: function(cm) {
  19. cm.replaceSelection(" surprise again! ");
  20. }
  21. };
  22. },
  23. handleChange1(value) {
  24. this.setState({
  25. textValue1: value
  26. });
  27. },
  28. handleChange2(value) {
  29. this.setState({
  30. textValue2: value
  31. });
  32. },
  33. handleTextChange() {
  34. this.setState({
  35. textValue1: `Changing text by setting new state. ${counter++}`
  36. });
  37. },
  38. render() {
  39. return (
  40. <div className='container container-narrow'>
  41. <div className="page-header">
  42. <h1>
  43. <a href="https://github.com/benrlodge/react-simplemde-editor">react-simplemde-editor</a>
  44. </h1>
  45. <p className="lead">
  46. A React.js wrapper for <a href="https://github.com/NextStepWebs/simplemde-markdown-editor">simplemde-markdown-editor</a>.
  47. </p>
  48. </div>
  49. <button style={{display: "inline-block", margin: "10px 0"}} onClick={this.handleTextChange}>
  50. Click me to update the textValue outside of the editor
  51. </button>
  52. <Editor
  53. label="Markdown Editor"
  54. value={this.state.textValue1}
  55. handleEditorChange={this.handleChange1}
  56. />
  57. <hr />
  58. <Editor
  59. value={this.state.textValue2}
  60. handleEditorChange={this.handleChange2}
  61. extraKeys={this.extraKeys()}
  62. />
  63. </div>
  64. )
  65. }
  66. });