Skip to content
This repository was archived by the owner on May 31, 2020. It is now read-only.

Commit 3778b9f

Browse files
committed
optimize structure for divider-example
1 parent b88ac82 commit 3778b9f

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed
Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
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'
46
import { insertEntityBlock } from '@djsp/utils'
57

68
type 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+
3049
export default InsertDivider

examples/divider-example/src/index.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React, { Component } from 'react'
22
import ReactDOM from 'react-dom'
33

44
import { 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'
76
import InsertDivider from './InsertDivider'
87
import './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
)

0 commit comments

Comments
 (0)