This repository was archived by the owner on May 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-16
lines changed
examples/divider-example/src Expand file tree Collapse file tree 2 files changed +27
-16
lines changed Original file line number Diff line number Diff line change 11// @flow
22
3- import React , { Component } from 'react'
3+ import React , { Component , Fragment } from 'react'
4+ import { Plugin } from '@djsp/core'
5+ import AtomicBlock from '@djsp/atomic-block'
46import { insertEntityBlock } from '@djsp/utils'
57
68type Props = {
79 editorState : EditorState ,
810 setEditorState : EditorState => void ,
911}
1012
11- class InsertDivider extends Component < Props > {
13+ class DividerButton extends Component < Props > {
1214 onClick = event => {
1315 event . stopPropagation ( )
1416
15- const { setEditorState, editorState } = this . props ;
17+ const { setEditorState, editorState } = this . props
1618 setEditorState ( insertEntityBlock ( editorState , 'divider' ) )
1719 }
1820
1921 render ( ) {
2022 return (
21- < button
22- type = "button"
23- onClick = { this . onClick } >
23+ < button type = "button" onClick = { this . onClick } >
2424 Insert divider
2525 </ button >
2626 )
2727 }
2828}
2929
30+ const InsertDivider = ( ) => (
31+ < Fragment >
32+ < AtomicBlock type = "divider" >
33+ { ( { isFocused } ) => (
34+ < hr className = { isFocused ? 'divider focused' : 'divider' } />
35+ ) }
36+ </ AtomicBlock >
37+
38+ < Plugin >
39+ { ( { editorState, setEditorState } ) => (
40+ < DividerButton
41+ editorState = { editorState }
42+ setEditorState = { setEditorState }
43+ />
44+ ) }
45+ </ Plugin >
46+ </ Fragment >
47+ )
48+
3049export default InsertDivider
Original file line number Diff line number Diff line change @@ -2,8 +2,7 @@ import React, { Component } from 'react'
22import ReactDOM from 'react-dom'
33
44import { EditorState , convertFromRaw } from 'draft-js'
5- import { EditorContainer , Editor , Plugin } from '@djsp/core'
6- import AtomicBlock from '@djsp/atomic-block'
5+ import { EditorContainer , Editor } from '@djsp/core'
76import InsertDivider from './InsertDivider'
87import './styles.css'
98
@@ -49,14 +48,7 @@ class App extends Component {
4948 editorState = { this . state . editorState }
5049 onChange = { this . onChange } >
5150 < Editor />
52-
53- < AtomicBlock type = "divider" >
54- { ( { isFocused } ) => < hr className = { isFocused ? 'divider focused' : 'divider' } /> }
55- </ AtomicBlock >
56-
57- < Plugin > {
58- ( { editorState, setEditorState } ) => < InsertDivider editorState = { editorState } setEditorState = { setEditorState } />
59- } </ Plugin >
51+ < InsertDivider />
6052 </ EditorContainer >
6153 </ div >
6254 )
You can’t perform that action at this time.
0 commit comments