Created
August 31, 2016 01:00
-
-
Save mzbac/b2f835d39ca6e604959d0de2132f581c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TextEditor.js | |
<div styleName="container"> | |
<Toolbar | |
editorState={editorState} | |
onChange={this.onEditorChange} | |
boundingRect={boundingRect} /> | |
<Editor | |
editorState={editorState} | |
onChange={this.onEditorChange} | |
customStyleMap={styleMap} | |
placeholder="Enter your text.." /> | |
</div> | |
The condition ive used to hide and show the toolbar is this: | |
Toolbar.js | |
const boundingRect = getVisibleSelectionRect(window); (passed from parent component) | |
const selectionState = editorState.getSelection(); | |
if (boundingRect && !selectionState.isCollapsed() && selectionState.getHasFocus()) { | |
var toolbar = | |
<div | |
styleName="container" | |
style={{top: boundingRect.top, left: boundingRect.left + boundingRect.width/2}}> | |
...buttons | |
</div> | |
} | |
//which is returned in render | |
return ( | |
<span> | |
{toolbar} | |
</span> | |
) | |
.container { | |
position: fixed; | |
transform: translate3d(-50%, calc(-100% - 5px), 0); | |
max-width: 300px; | |
z-index: 80; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment