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

Commit b88ac82

Browse files
committed
extend divider-example
1 parent b3409fa commit b88ac82

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @flow
2+
3+
import React, { Component } from 'react'
4+
import { insertEntityBlock } from '@djsp/utils'
5+
6+
type Props = {
7+
editorState: EditorState,
8+
setEditorState: EditorState => void,
9+
}
10+
11+
class InsertDivider extends Component<Props> {
12+
onClick = event => {
13+
event.stopPropagation()
14+
15+
const { setEditorState, editorState } = this.props;
16+
setEditorState(insertEntityBlock(editorState, 'divider'))
17+
}
18+
19+
render() {
20+
return (
21+
<button
22+
type="button"
23+
onClick={this.onClick}>
24+
Insert divider
25+
</button>
26+
)
27+
}
28+
}
29+
30+
export default InsertDivider

examples/divider-example/src/index.js

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

44
import { EditorState, convertFromRaw } from 'draft-js'
5-
import { EditorContainer, Editor } from '@djsp/core'
5+
import { EditorContainer, Editor, Plugin } from '@djsp/core'
66
import AtomicBlock from '@djsp/atomic-block'
7-
import '@djsp/atomic-block/dist/index.css'
7+
import InsertDivider from './InsertDivider'
88
import './styles.css'
99

1010
const rawContent = {
@@ -51,8 +51,12 @@ class App extends Component {
5151
<Editor />
5252

5353
<AtomicBlock type="divider">
54-
{() => <hr className="divider" />}
54+
{({ isFocused }) => <hr className={isFocused ? 'divider focused' : 'divider'} />}
5555
</AtomicBlock>
56+
57+
<Plugin>{
58+
({ editorState, setEditorState }) => <InsertDivider editorState={editorState} setEditorState={setEditorState} />
59+
}</Plugin>
5660
</EditorContainer>
5761
</div>
5862
)

examples/divider-example/src/styles.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ body {
3232
letter-spacing: 48px; /* increase space between dots */
3333
content: '•••';
3434
}
35+
36+
.divider:hover {
37+
border-radius: 2px;
38+
box-shadow: 0 0 0 2px #D2E3F7;
39+
}
40+
41+
.divider.focused {
42+
border-radius: 2px;
43+
box-shadow: 0 0 0 2px #ACCEF7;
44+
}

0 commit comments

Comments
 (0)