Skip to content

Instantly share code, notes, and snippets.

@ignaciojvig
Created July 27, 2020 18:02
Show Gist options
  • Save ignaciojvig/fe3ce9d64c340ef4fe47e8017c2074ba to your computer and use it in GitHub Desktop.
Save ignaciojvig/fe3ce9d64c340ef4fe47e8017c2074ba to your computer and use it in GitHub Desktop.

Revisions

  1. ignaciojvig created this gist Jul 27, 2020.
    49 changes: 49 additions & 0 deletions AntDesign + Jodit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    import React, { useState, useRef, useEffect } from 'react';
    import ReactDOMServer from 'react-dom/server'
    import logo from './logo.svg';
    import JoditEditor from "jodit-react";
    import { ShrinkOutlined } from '@ant-design/icons'
    import 'jodit';
    import 'jodit/build/jodit.min.css';
    import './App.css';

    function App() {
    const editor = useRef(null)
    const [docContent, setDocContent] = useState('Vamboooora')
    const config = {
    uploader: {
    insertImageAsBase64URI: true
    },
    extraButtons: [
    {
    name: 'inserir Data',
    exec: (editor) => {
    editor.s.insertHTML((new Date).toDateString())
    }
    },
    {
    name: 'inserir componente Ant',
    exec: (editor) => {
    editor.s.insertHTML(ReactDOMServer.renderToString(<ShrinkOutlined />))
    }
    }
    ],
    buttons: ['bold'],
    readonly: false // all options from https://xdsoft.net/jodit/doc/
    }

    return (
    <div className="App">
    <JoditEditor
    ref={editor}
    value={docContent}
    config={config}
    tabIndex={1} // tabIndex of textarea
    onBlur={newContent => setDocContent(newContent)} // preferred to use only this option to update the content for performance reasons
    onChange={newContent => { console.log(newContent); }}
    />
    </div>
    );
    }

    export default App;