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

Commit 4cb24a6

Browse files
committed
add flowtype and fix lint error
1 parent 1eb6e7a commit 4cb24a6

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1+
// @flow
2+
13
import React, { Component } from 'react'
24
import { EditorState } from 'draft-js'
35

4-
class RedoButton extends Component {
6+
type Props = {
7+
editorState: EditorState,
8+
setEditorState: EditorState => void,
9+
}
510

6-
onClick = (event) => {
7-
event.stopPropagation();
8-
this.props.setEditorState(EditorState.redo(this.props.editorState));
9-
};
11+
class RedoButton extends Component<Props> {
12+
onClick = event => {
13+
event.stopPropagation()
14+
this.props.setEditorState(EditorState.redo(this.props.editorState))
15+
}
1016

1117
render() {
1218
return (
13-
<button
14-
disabled={ !this.props.editorState || this.props.editorState.getRedoStack().isEmpty() }
19+
<button
20+
disabled={
21+
!this.props.editorState ||
22+
this.props.editorState.getRedoStack().isEmpty()
23+
}
1524
type="button"
16-
onClick={this.onClick}
17-
>redo</button>
25+
onClick={this.onClick}>
26+
redo
27+
</button>
1828
)
1929
}
2030
}
2131

22-
export default RedoButton
32+
export default RedoButton
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
1+
// @flow
2+
13
import React, { Component } from 'react'
24
import { EditorState } from 'draft-js'
35

4-
class UndoButton extends Component {
6+
type Props = {
7+
editorState: EditorState,
8+
setEditorState: EditorState => void,
9+
}
510

6-
onClick = (event) => {
7-
event.stopPropagation();
8-
this.props.setEditorState(EditorState.undo(this.props.editorState));
9-
};
11+
class UndoButton extends Component<Props> {
12+
onClick = event => {
13+
event.stopPropagation()
14+
this.props.setEditorState(EditorState.undo(this.props.editorState))
15+
}
1016

1117
render() {
1218
return (
13-
<button
14-
disabled={ !this.props.editorState || this.props.editorState.getUndoStack().isEmpty() }
19+
<button
20+
disabled={
21+
!this.props.editorState ||
22+
this.props.editorState.getUndoStack().isEmpty()
23+
}
1524
type="button"
16-
onClick={this.onClick}
17-
>undo</button>
25+
onClick={this.onClick}>
26+
undo
27+
</button>
1828
)
1929
}
2030
}
2131

22-
export default UndoButton
32+
export default UndoButton

examples/undo-example/src/index.js

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

4-
import { EditorState, ContentState} from 'draft-js'
4+
import { EditorState, ContentState } from 'draft-js'
55
import { EditorContainer, Editor, Plugin } from '@djsp/core'
66
import UndoButton from './UndoButton.js'
77
import RedoButton from './RedoButton.js'
@@ -24,12 +24,20 @@ class App extends Component {
2424
<EditorContainer
2525
editorState={this.state.editorState}
2626
onChange={this.onChange}>
27-
<Plugin>{({ editorState, setEditorState }) => (
28-
<Fragment>
29-
<UndoButton editorState={editorState} setEditorState={setEditorState} />
30-
<RedoButton editorState={editorState} setEditorState={setEditorState} />
31-
</Fragment>
32-
)}</Plugin>
27+
<Plugin>
28+
{({ editorState, setEditorState }) => (
29+
<Fragment>
30+
<UndoButton
31+
editorState={editorState}
32+
setEditorState={setEditorState}
33+
/>
34+
<RedoButton
35+
editorState={editorState}
36+
setEditorState={setEditorState}
37+
/>
38+
</Fragment>
39+
)}
40+
</Plugin>
3341
<Editor />
3442
</EditorContainer>
3543
</div>

0 commit comments

Comments
 (0)