diff --git a/src/components/EditorWidgets/Markdown/MarkdownControl/Toolbar/Toolbar.js b/src/components/EditorWidgets/Markdown/MarkdownControl/Toolbar/Toolbar.js index 6f460c8e..f314b345 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownControl/Toolbar/Toolbar.js +++ b/src/components/EditorWidgets/Markdown/MarkdownControl/Toolbar/Toolbar.js @@ -27,7 +27,12 @@ export default class Toolbar extends React.Component { }; } - getToolbarButtonsList() { + isHidden = button => { + const { buttons } = this.props; + return List.isList(buttons) ? !buttons.includes(button) : false; + } + + render() { const { onMarkClick, onBlockClick, @@ -35,64 +40,18 @@ export default class Toolbar extends React.Component { selectionHasMark, selectionHasBlock, selectionHasLink, - disabled, - buttons - } = this.props; - - const toolbarButtons = [ - { type: 'bold', label: 'Bold', icon: 'bold', onClick: onMarkClick, isActive: selectionHasMark, disabled }, - { type: 'italic', label: 'Italic', icon: 'italic', onClick: onMarkClick, isActive: selectionHasMark, disabled }, - { type: 'code', label: 'Code', icon: 'code', onClick: onMarkClick, isActive: selectionHasMark, disabled }, - { type: 'link', label: 'Link', icon: 'link', onClick: onLinkClick, isActive: selectionHasLink, disabled }, - { type: 'heading-one', label: 'Header 1', icon: 'h1', onClick: onBlockClick, isActive: selectionHasBlock, disabled }, - { type: 'heading-two', label: 'Header 2', icon: 'h2', onClick: onBlockClick, isActive: selectionHasBlock, disabled }, - { type: 'quote', label: 'Quote', icon: 'quote', onClick: onBlockClick, isActive: selectionHasBlock, disabled }, - { type: 'code', label: 'Code Block', icon: 'code-block', onClick: onBlockClick, isActive: selectionHasBlock, disabled }, - { type: 'bulleted-list', label: 'Bulleted List', icon: 'list-bulleted', onClick: onBlockClick, isActive: selectionHasBlock, disabled }, - { type: 'numbered-list', label: 'Numbered List', icon: 'list-numbered', onClick: onBlockClick, isActive: selectionHasBlock, disabled } - ]; - - return buttons === undefined ? toolbarButtons : toolbarButtons.filter(button => buttons.includes(button.type)); - } - - renderToolbarButton(button) { - const { type, label, icon, onClick, isActive, disabled } = button; - return ; - } - - renderToolbarDropdown() { - const { plugins, disabled, onSubmit } = this.props; - - return ( -
- - } - > - {plugins && plugins.toList().map((plugin, idx) => ( - onSubmit(plugin.get('id'))} /> - ))} - -
- ); - } - - renderToolbarToggle() { - const { onToggleMode, rawMode, plugins, + onAddAsset, + getAsset, disabled, - className + onSubmit, + className, } = this.props; + const { activePlugin } = this.state; + /** * Because the toggle labels change font weight for active/inactive state, * we need to set estimated widths for them to maintain position without @@ -104,43 +63,142 @@ export default class Toolbar extends React.Component { const toggleOnLabelWidth = '70px'; return ( -
- - {toggleOffLabel} - - - - {toggleOnLabel} - -
- ); - } - - render() { - return ( -
+
- {this.getToolbarButtonsList().map((toolbarButton) => this.renderToolbarButton(toolbarButton))} - {this.renderToolbarDropdown()} + + + + + + + + + + +
+ + } + > + {plugins && plugins.toList().map((plugin, idx) => ( + onSubmit(plugin.get('id'))} /> + ))} + +
+
+
+ + {toggleOffLabel} + + + + {toggleOnLabel} +
- {this.renderToolbarToggle()}
); } diff --git a/src/components/EditorWidgets/Markdown/MarkdownControl/Toolbar/ToolbarButton.js b/src/components/EditorWidgets/Markdown/MarkdownControl/Toolbar/ToolbarButton.js index e01effe0..fe281046 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownControl/Toolbar/ToolbarButton.js +++ b/src/components/EditorWidgets/Markdown/MarkdownControl/Toolbar/ToolbarButton.js @@ -3,9 +3,13 @@ import React from 'react'; import c from 'classnames'; import { Icon } from 'UI'; -const ToolbarButton = ({ type, label, icon, onClick, isActive, disabled }) => { +const ToolbarButton = ({ type, label, icon, onClick, isActive, isHidden, disabled }) => { const active = isActive && type && isActive(type); + if (isHidden) { + return null; + } + return (