Skip to content

Commit 9b8b12f

Browse files
freedomlangjuliankrispel
authored andcommitted
refactor(static-toolbar): refactor static-toolbar via render prop
1 parent 98ab509 commit 9b8b12f

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

draft-js-static-toolbar-plugin/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
### 3.0.0
7+
- Swap structure prop in static toolbar for render prop
8+
69
## 2.0.2 - 2.0.3
710
- bumped find-with-regex
811

draft-js-static-toolbar-plugin/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "draft-js-static-toolbar-plugin",
3-
"version": "2.0.3",
3+
"version": "3.0.0",
44
"description": "Static Toolbar Plugin for DraftJS",
55
"author": {
66
"name": "Julian Krispel",

draft-js-static-toolbar-plugin/src/components/Toolbar/index.js

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/* eslint-disable react/no-array-index-key */
22
import React from 'react';
3+
import {
4+
ItalicButton,
5+
BoldButton,
6+
UnderlineButton,
7+
CodeButton,
8+
} from 'draft-js-buttons';
9+
import PropTypes from 'prop-types';
310

4-
export default class Toolbar extends React.Component {
11+
class Toolbar extends React.Component {
512

613
state = {
714
/**
@@ -28,8 +35,17 @@ export default class Toolbar extends React.Component {
2835
*/
2936
onOverrideContent = (overrideContent) => this.setState({ overrideContent });
3037

38+
renderDefaultButtons = (externalProps) => (
39+
<div>
40+
<ItalicButton {...externalProps} />
41+
<BoldButton {...externalProps} />
42+
<UnderlineButton {...externalProps} />
43+
<CodeButton {...externalProps} />
44+
</div>
45+
);
46+
3147
render() {
32-
const { theme, store, structure } = this.props;
48+
const { theme, store } = this.props;
3349
const { overrideContent: OverrideContent } = this.state;
3450
const childrenProps = {
3551
theme: theme.buttonStyles,
@@ -44,9 +60,14 @@ export default class Toolbar extends React.Component {
4460
>
4561
{OverrideContent
4662
? <OverrideContent {...childrenProps} />
47-
: structure.map((Component, index) =>
48-
<Component key={index} {...childrenProps} />)}
63+
: (this.props.children || this.renderDefaultButtons)(childrenProps)}
4964
</div>
5065
);
5166
}
5267
}
68+
69+
Toolbar.propTypes = {
70+
children: PropTypes.func
71+
};
72+
73+
export default Toolbar;

draft-js-static-toolbar-plugin/src/index.js

-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
import decorateComponentWithProps from 'decorate-component-with-props';
2-
import {
3-
ItalicButton,
4-
BoldButton,
5-
UnderlineButton,
6-
CodeButton,
7-
} from 'draft-js-buttons';
82
import createStore from './utils/createStore';
93
import Toolbar from './components/Toolbar';
104
import Separator from './components/Separator';
@@ -18,17 +12,10 @@ export default (config = {}) => {
1812

1913
const {
2014
theme = defaultTheme,
21-
structure = [
22-
BoldButton,
23-
ItalicButton,
24-
UnderlineButton,
25-
CodeButton,
26-
]
2715
} = config;
2816

2917
const toolbarProps = {
3018
store,
31-
structure,
3219
theme,
3320
};
3421

0 commit comments

Comments
 (0)