Skip to content

Instantly share code, notes, and snippets.

@mzbac
Created August 31, 2016 01:00
Show Gist options
  • Save mzbac/b2f835d39ca6e604959d0de2132f581c to your computer and use it in GitHub Desktop.
Save mzbac/b2f835d39ca6e604959d0de2132f581c to your computer and use it in GitHub Desktop.
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