Преглед изворни кода

feat: custom markdown editor toolbar icon

node пре 6 година
родитељ
комит
40fb59e72c
5 измењених фајлова са 64 додато и 3 уклоњено
  1. 7
    1
      README.md
  2. 4
    0
      src/App.css
  3. 29
    1
      src/App.js
  4. 23
    0
      src/MarkdownEditor/index.js
  5. 1
    1
      src/RichEditor/index.js

+ 7
- 1
README.md Прегледај датотеку

@@ -7,4 +7,10 @@
7 7
 File sizes after gzip:
8 8
 
9 9
   186.26 KB (+149.06 KB)  build/static/js/main.2563472b.js
10
-  21.28 KB (+20.99 KB)    build/static/css/main.e0d26ea8.css
10
+  21.28 KB (+20.99 KB)    build/static/css/main.e0d26ea8.css
11
+
12
+
13
+  File sizes after gzip:
14
+
15
+  195.79 KB (+9.53 KB)  build/static/js/main.d730d269.js
16
+  21.28 KB              build/static/css/main.4c86779f.css

+ 4
- 0
src/App.css Прегледај датотеку

@@ -0,0 +1,4 @@
1
+.main {
2
+  width: 100%;
3
+  padding: 20px;
4
+}

+ 29
- 1
src/App.js Прегледај датотеку

@@ -1,11 +1,39 @@
1 1
 import React, { Component } from 'react';
2
+import { library } from '@fortawesome/fontawesome-svg-core'
3
+import { 
4
+    faBold, 
5
+    faHeading,
6
+    faItalic,
7
+    faStrikethrough,
8
+    faLink,
9
+    faQuoteRight,
10
+    faCode,
11
+    faImage,
12
+    faListUl,
13
+    faListOl,
14
+    faTasks,
15
+ } from '@fortawesome/free-solid-svg-icons'
2 16
 import RichEditor from './RichEditor';
3 17
 import MarkdownEditor from './MarkdownEditor';
18
+import './App.css'
19
+
20
+
21
+library.add(faBold)
22
+library.add(faHeading)
23
+library.add(faItalic)
24
+library.add(faStrikethrough)
25
+library.add(faLink)
26
+library.add(faQuoteRight)
27
+library.add(faCode)
28
+library.add(faImage)
29
+library.add(faListUl)
30
+library.add(faListOl)
31
+library.add(faTasks)
4 32
 
5 33
 class App extends Component {
6 34
   render() {
7 35
     return (
8
-      <div classNAme="main">
36
+      <div className="main">
9 37
         <RichEditor />
10 38
         <hr></hr>
11 39
         <MarkdownEditor />

+ 23
- 0
src/MarkdownEditor/index.js Прегледај датотеку

@@ -2,6 +2,27 @@ import * as React from "react";
2 2
 import ReactMde from 'react-mde';
3 3
 import * as Showdown from "showdown";
4 4
 import 'react-mde/lib/styles/css/react-mde-all.css';
5
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
6
+
7
+
8
+const icons = {
9
+    "bold": <FontAwesomeIcon icon="bold" />,
10
+    "heading": <FontAwesomeIcon icon="heading" />,
11
+    "italic": <FontAwesomeIcon icon="italic" />,
12
+    "strikethrough": <FontAwesomeIcon icon="strikethrough" />,
13
+    "link": <FontAwesomeIcon icon="link" />,
14
+    "quote-right": <FontAwesomeIcon icon="quote-right" />,
15
+    "code": <FontAwesomeIcon icon="code" />,
16
+    "image": <FontAwesomeIcon icon="image" />,
17
+    "list-ul": <FontAwesomeIcon icon="list-ul" />,
18
+    "list-ol": <FontAwesomeIcon icon="list-ol" />,
19
+    "tasks": <FontAwesomeIcon icon="tasks" />,
20
+  };
21
+
22
+  const iconProvider = (name) => {
23
+    return icons[name] || "❓";
24
+  };
25
+  
5 26
 
6 27
 export default class MarkdownEditor extends React.Component {
7 28
 
@@ -21,6 +42,8 @@ export default class MarkdownEditor extends React.Component {
21 42
         return (
22 43
             <div className="container">
23 44
                 <ReactMde
45
+                    layout="horizontal"
46
+                    buttonContentOptions={{ iconProvider }}
24 47
                     onChange={this.handleValueChange}
25 48
                     editorState={this.state.mdeState}
26 49
                     generateMarkdownPreview={(markdown) => Promise.resolve(this.converter.makeHtml(markdown))}

+ 1
- 1
src/RichEditor/index.js Прегледај датотеку

@@ -37,7 +37,7 @@ export default class RichEditor extends React.Component {
37 37
 
38 38
         const { editorState } = this.state
39 39
         return (
40
-            <div className="my-component">
40
+            <div>
41 41
                 <BraftEditor
42 42
                     value={editorState}
43 43
                     onChange={this.handleEditorChange}