Skip to content

Commit

Permalink
Added option to render the toolbar on the bottom of the editor (#318)
Browse files Browse the repository at this point in the history
* Added option to render the toolbar on the bottom of the editor

* Fixed toolbar on bottom styling for the borders
  • Loading branch information
dec-senta authored and sstur committed Mar 21, 2019
1 parent f10c0e5 commit f18543f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/RichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Props = {
readOnly?: boolean;
disabled?: boolean; // Alias of readOnly
toolbarConfig?: ToolbarConfig;
toolbarOnBottom?: boolean;
blockStyleFn?: (block: ContentBlock) => ?string;
autoFocus?: boolean;
keyBindingFn?: (event: Object) => ?string;
Expand Down Expand Up @@ -96,6 +97,7 @@ export default class RichTextEditor extends Component {
readOnly,
disabled,
toolbarConfig,
toolbarOnBottom,
blockStyleFn,
customControls,
keyBindingFn,
Expand All @@ -121,6 +123,7 @@ export default class RichTextEditor extends Component {
editorToolbar = (
<EditorToolbar
rootStyle={toolbarStyle}
isOnBottom={toolbarOnBottom}
className={toolbarClassName}
keyEmitter={this._keyEmitter}
editorState={editorState}
Expand All @@ -133,7 +136,7 @@ export default class RichTextEditor extends Component {
}
return (
<div className={cx(styles.root, className)} style={rootStyle}>
{editorToolbar}
{ !toolbarOnBottom && editorToolbar }
<div className={combinedEditorClassName} style={editorStyle}>
<Editor
{...otherProps}
Expand All @@ -153,6 +156,7 @@ export default class RichTextEditor extends Component {
readOnly={readOnly}
/>
</div>
{ toolbarOnBottom && editorToolbar }
</div>
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib/EditorToolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
-ms-user-select: none;
user-select: none;
}

.onBottom {
border-top: 1px solid #ddd;
border-bottom: none;
}
5 changes: 3 additions & 2 deletions src/lib/EditorToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Props = {
toolbarConfig: ToolbarConfig;
customControls: Array<CustomControl>;
rootStyle?: Object;
isOnBottom?: boolean;
};

type State = {
Expand Down Expand Up @@ -66,7 +67,7 @@ export default class EditorToolbar extends Component {
}

render() {
let {className, toolbarConfig, rootStyle} = this.props;
let {className, toolbarConfig, rootStyle, isOnBottom} = this.props;
if (toolbarConfig == null) {
toolbarConfig = DefaultToolbarConfig;
}
Expand Down Expand Up @@ -94,7 +95,7 @@ export default class EditorToolbar extends Component {
}
});
return (
<div className={cx(styles.root, className)} style={rootStyle}>
<div className={cx(styles.root, (isOnBottom && styles.onBottom), className)} style={rootStyle}>
{buttonGroups}
{this._renderCustomControls()}
</div>
Expand Down

0 comments on commit f18543f

Please sign in to comment.