This repository was archived by the owner on May 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed
examples/divider-example/src Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ import React, { Component } from 'react'
22import ReactDOM from 'react-dom'
33
44import { EditorState , convertFromRaw } from 'draft-js'
5- import { EditorContainer , Editor } from '@djsp/core'
5+ import { EditorContainer , Editor , Plugin } from '@djsp/core'
66import AtomicBlock from '@djsp/atomic-block'
7- import '@djsp/atomic-block/dist/index.css '
7+ import InsertDivider from './InsertDivider '
88import './styles.css'
99
1010const 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 )
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments