Skip to content

Commit

Permalink
Add hidden option to toolbox (#1220)
Browse files Browse the repository at this point in the history
* Add hidden option to toolbox

* Use false in order to hide toolbox

* Add comment what false means

* Add issue #1221 to changelog

Co-authored-by: t.hata <[email protected]>
  • Loading branch information
hata6502 and t.hata authored Aug 27, 2020
1 parent 57397de commit cdb48c4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- `New` - Tool's `reset` static method added to the API to clean up any data added by Tool on initialization
- `Improvements` - Unuseful log about missed i18n section has been removed [#1269](https://github.com/codex-team/editor.js/issues/1269)
- `Fix` - Fixed issue with enter key in inputs and textareas [#920](https://github.com/codex-team/editor.js/issues/920)
- `Improvements` - Allowed to set `false` as `toolbox` config in order to hide Toolbox button [#1221](https://github.com/codex-team/editor.js/issues/1221)

### 2.18

Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class Renderer extends Module {
const toolToolboxSettings = (Tools.unavailable[tool] as BlockToolConstructable).toolbox;
const userToolboxSettings = Tools.getToolSettings(tool).toolbox;

stubData.title = toolToolboxSettings.title || userToolboxSettings.title || stubData.title;
stubData.title = toolToolboxSettings.title || (userToolboxSettings && userToolboxSettings.title) || stubData.title;
}

const stub = BlockManager.insert({
Expand Down
9 changes: 7 additions & 2 deletions src/components/modules/toolbar/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,15 @@ export default class ConversionToolbar extends Module {
const toolToolboxSettings = toolClass[internalSettings.TOOLBOX];
const conversionConfig = toolClass[internalSettings.CONVERSION_CONFIG];

const userSettings = this.Editor.Tools.USER_SETTINGS;
const userToolboxSettings = this.Editor.Tools.getToolSettings(toolName)[userSettings.TOOLBOX];

const toolboxSettings = userToolboxSettings ?? toolToolboxSettings;

/**
* Skip tools that don't pass 'toolbox' property
*/
if (_.isEmpty(toolToolboxSettings) || !toolToolboxSettings.icon) {
if (_.isEmpty(toolboxSettings) || !toolboxSettings.icon) {
continue;
}

Expand All @@ -278,7 +283,7 @@ export default class ConversionToolbar extends Module {
continue;
}

this.addTool(toolName, toolToolboxSettings.icon, toolToolboxSettings.title);
this.addTool(toolName, toolboxSettings.icon, toolboxSettings.title);
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/components/modules/toolbar/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ export default class Toolbox extends Module {
// return;
// }

const userToolboxSettings = this.Editor.Tools.getToolSettings(toolName)[userSettings.TOOLBOX] || {};
const userToolboxSettings = this.Editor.Tools.getToolSettings(toolName)[userSettings.TOOLBOX];

/**
* Hide Toolbox button if Toolbox settings is false
*/
if ((userToolboxSettings ?? toolToolboxSettings) === false) {
return;
}

const button = $.make('li', [ this.CSS.toolboxButton ]);

button.dataset.tool = toolName;
button.innerHTML = userToolboxSettings.icon || toolToolboxSettings.icon;
button.innerHTML = (userToolboxSettings && userToolboxSettings.icon) || toolToolboxSettings.icon;

$.append(this.nodes.toolbox, button);

Expand Down
3 changes: 2 additions & 1 deletion types/tools/tool-settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface ToolSettings {

/**
* Tool's Toolbox settings
* It will be hidden from Toolbox when false is specified.
*/
toolbox?: ToolboxConfig;
toolbox?: ToolboxConfig | false;
}

0 comments on commit cdb48c4

Please sign in to comment.