Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 62e1809

Browse files
zackifysstur
authored andcommitted
Add option to hide link and block type dropdown (sstur#108)
* Add ability to hide block type dropdown and link buttons * Update readme with toolbar config options * Toolbar config: display groups
1 parent 3a5869b commit 62e1809

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ render() {
6969
// Supported inline styles: https://github.com/facebook/draft-js/blob/master/docs/Advanced-Topics-Inline-Styles.md
7070
// Supported block types: https://github.com/facebook/draft-js/blob/master/docs/Advanced-Topics-Custom-Block-Render.md#draft-default-block-render-map
7171
const toolbarConfig = {
72+
// Optionally specify the groups to display (displayed in the order listed).
73+
display: ['INLINE_STYLE_BUTTONS', 'BLOCK_TYPE_DROPDOWN', 'LINK_BUTTONS', 'BLOCK_TYPE_BUTTONS', 'HISTORY_BUTTONS'],
7274
INLINE_STYLE_BUTTONS: [
7375
{label: 'Bold', style: 'BOLD', className: 'custom-css-class'},
7476
{label: 'Italic', style: 'ITALIC'},

‎src/lib/EditorToolbar.js‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,33 @@ export default class EditorToolbar extends Component {
5959
}
6060

6161
render() {
62-
const {className, toolbarConfig} = this.props;
62+
let {className, toolbarConfig} = this.props;
63+
if (toolbarConfig == null) {
64+
toolbarConfig = DefaultToolbarConfig;
65+
}
66+
let display = toolbarConfig.display || DefaultToolbarConfig.display;
67+
let buttonsGroups = display.map((groupName) => {
68+
switch (groupName) {
69+
case 'INLINE_STYLE_BUTTONS': {
70+
return this._renderInlineStyleButtons(toolbarConfig);
71+
}
72+
case 'BLOCK_TYPE_DROPDOWN': {
73+
return this._renderBlockTypeButtons(toolbarConfig);
74+
}
75+
case 'LINK_BUTTONS': {
76+
return this._renderLinkButtons();
77+
}
78+
case 'BLOCK_TYPE_BUTTONS': {
79+
return this._renderBlockTypeDropdown(toolbarConfig);
80+
}
81+
case 'HISTORY_BUTTONS': {
82+
return this._renderUndoRedo();
83+
}
84+
}
85+
});
6386
return (
6487
<div className={cx(styles.root, className)}>
65-
{this._renderInlineStyleButtons(toolbarConfig || DefaultToolbarConfig)}
66-
{this._renderBlockTypeButtons(toolbarConfig || DefaultToolbarConfig)}
67-
{this._renderLinkButtons()}
68-
{this._renderBlockTypeDropdown(toolbarConfig || DefaultToolbarConfig)}
69-
{this._renderUndoRedo()}
88+
{buttonsGroups}
7089
</div>
7190
);
7291
}

‎src/lib/EditorToolbarConfig.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export type StyleConfig = {
88

99
export type StyleConfigList = Array<StyleConfig>;
1010

11+
export type GroupName = 'INLINE_STYLE_BUTTONS' | 'BLOCK_TYPE_DROPDOWN' | 'LINK_BUTTONS' | 'BLOCK_TYPE_BUTTONS' | 'HISTORY_BUTTONS';
12+
1113
export type ToolbarConfig = {
14+
display: Array<GroupName>;
1215
INLINE_STYLE_BUTTONS: StyleConfigList;
1316
BLOCK_TYPE_DROPDOWN: StyleConfigList;
1417
BLOCK_TYPE_BUTTONS: StyleConfigList;
@@ -36,6 +39,7 @@ export const BLOCK_TYPE_BUTTONS: StyleConfigList = [
3639
];
3740

3841
let EditorToolbarConfig: ToolbarConfig = {
42+
display: ['INLINE_STYLE_BUTTONS', 'BLOCK_TYPE_DROPDOWN', 'LINK_BUTTONS', 'BLOCK_TYPE_BUTTONS', 'HISTORY_BUTTONS'],
3943
INLINE_STYLE_BUTTONS,
4044
BLOCK_TYPE_DROPDOWN,
4145
BLOCK_TYPE_BUTTONS,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /