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

Commit 1eb6e7a

Browse files
committed
add example for undo and redo
1 parent 69fffee commit 1eb6e7a

File tree

8 files changed

+14436
-0
lines changed

8 files changed

+14436
-0
lines changed

examples/undo-example/README.md

Lines changed: 2164 additions & 0 deletions
Large diffs are not rendered by default.

examples/undo-example/package-lock.json

Lines changed: 12113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/undo-example/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@djsp/undo-example",
3+
"homepage": "https://juliankrispel.github.io/djs-autocomplete",
4+
"version": "0.1.4",
5+
"private": true,
6+
"license": "MIT",
7+
"dependencies": {
8+
"@djsp/core": "^0.1.4",
9+
"react": "^16.2.0",
10+
"react-dom": "^16.2.0",
11+
"react-scripts": "^1.1.1"
12+
},
13+
"scripts": {
14+
"start": "react-scripts start",
15+
"build": "react-scripts build",
16+
"test": "react-scripts test --env=jsdom",
17+
"eject": "react-scripts eject"
18+
},
19+
"devDependencies": {
20+
"draft-js": "^0.10.5"
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta name="theme-color" content="#000000">
7+
8+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
9+
10+
<title>@djsp/suggestions</title>
11+
</head>
12+
13+
<body>
14+
<noscript>
15+
You need to enable JavaScript to run this app.
16+
</noscript>
17+
18+
<div id="root"></div>
19+
</body>
20+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { Component } from 'react'
2+
import { EditorState } from 'draft-js'
3+
4+
class RedoButton extends Component {
5+
6+
onClick = (event) => {
7+
event.stopPropagation();
8+
this.props.setEditorState(EditorState.redo(this.props.editorState));
9+
};
10+
11+
render() {
12+
return (
13+
<button
14+
disabled={ !this.props.editorState || this.props.editorState.getRedoStack().isEmpty() }
15+
type="button"
16+
onClick={this.onClick}
17+
>redo</button>
18+
)
19+
}
20+
}
21+
22+
export default RedoButton
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { Component } from 'react'
2+
import { EditorState } from 'draft-js'
3+
4+
class UndoButton extends Component {
5+
6+
onClick = (event) => {
7+
event.stopPropagation();
8+
this.props.setEditorState(EditorState.undo(this.props.editorState));
9+
};
10+
11+
render() {
12+
return (
13+
<button
14+
disabled={ !this.props.editorState || this.props.editorState.getUndoStack().isEmpty() }
15+
type="button"
16+
onClick={this.onClick}
17+
>undo</button>
18+
)
19+
}
20+
}
21+
22+
export default UndoButton

examples/undo-example/src/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { Component, Fragment } from 'react'
2+
import ReactDOM from 'react-dom'
3+
4+
import { EditorState, ContentState} from 'draft-js'
5+
import { EditorContainer, Editor, Plugin } from '@djsp/core'
6+
import UndoButton from './UndoButton.js'
7+
import RedoButton from './RedoButton.js'
8+
import './styles.css'
9+
10+
class App extends Component {
11+
state = {
12+
editorState: EditorState.createWithContent(
13+
ContentState.createFromText(
14+
'Just type something and click the undo and redo button!'
15+
)
16+
),
17+
}
18+
19+
onChange = editorState => this.setState({ editorState })
20+
21+
render() {
22+
return (
23+
<div>
24+
<EditorContainer
25+
editorState={this.state.editorState}
26+
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>
33+
<Editor />
34+
</EditorContainer>
35+
</div>
36+
)
37+
}
38+
}
39+
40+
ReactDOM.render(<App />, document.getElementById('root'))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
body {
2+
font-family: sans-serif;
3+
font-size: 1.8em;
4+
padding: 1em;
5+
background: #12312e;
6+
}
7+
8+
.public-DraftEditor-content {
9+
padding: 2em;
10+
border-radius: 5px;
11+
color: #fff;
12+
border: #555;
13+
background: #244a46;
14+
}
15+
16+
.autocomplete {
17+
margin-top: 1em;
18+
}
19+
20+
.list__item {
21+
display: block;
22+
padding: .5em;
23+
color: #ccc;
24+
background: transparent;
25+
transition: 100ms;
26+
}
27+
28+
.list__item--focused {
29+
color: #fff;
30+
padding-left: 1.2em;
31+
background: #2a6f51;
32+
border-radius: 5px;
33+
}

0 commit comments

Comments
 (0)