Skip to content

Commit 3a306a6

Browse files
committed
Support proper theme prop for DividerButton
1 parent eff2ee3 commit 3a306a6

File tree

5 files changed

+22
-46
lines changed

5 files changed

+22
-46
lines changed

draft-js-divider-plugin/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "draft-js-divider-plugin",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Divider Plugin for DraftJS",
55
"author": {
66
"name": "Ilkwon Sim",
@@ -35,7 +35,8 @@
3535
"license": "MIT",
3636
"dependencies": {
3737
"decorate-component-with-props": "^1.0.2",
38-
"prop-types": "^15.5.8"
38+
"prop-types": "^15.5.8",
39+
"union-class-names": "^1.0.0"
3940
},
4041
"peerDependencies": {
4142
"draft-js": "^0.10.1",

draft-js-divider-plugin/src/buttonStyles.css

Lines changed: 0 additions & 40 deletions
This file was deleted.

draft-js-divider-plugin/src/components/DividerButton.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33

4+
import unionClassNames from 'union-class-names';
5+
46
import { insertCustomBlock } from '../utils';
57

68
class DividerButton extends Component {
@@ -17,9 +19,20 @@ class DividerButton extends Component {
1719
event.preventDefault();
1820
};
1921

22+
blockTypeIsActive = () => {
23+
const editorState = this.props.getEditorState();
24+
const type = editorState
25+
.getCurrentContent()
26+
.getBlockForKey(editorState.getSelection().getStartKey())
27+
.getType();
28+
return type === this.props.blockType;
29+
};
30+
2031
render() {
2132
const { theme } = this.props;
22-
const className = theme.button;
33+
const className = this.blockTypeIsActive()
34+
? unionClassNames(theme.button, theme.active)
35+
: theme.button;
2336

2437
return (
2538
<div className={theme.buttonWrapper} onMouseDown={this.preventBubblingUp}>

draft-js-divider-plugin/src/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import React from 'react';
33
import DefaultDivider from './components/DefaultDivider';
44
import DividerButton from './components/DividerButton';
55

6-
import buttonStyles from './buttonStyles.css';
7-
86
import addDivider from './modifiers/addDivider';
97

108
const createDividerPlugin = (
@@ -21,8 +19,8 @@ const createDividerPlugin = (
2119
DividerButton: props => (
2220
<DividerButton
2321
{...props}
22+
blockType={blockType}
2423
addDivider={addDivider(blockType)}
25-
theme={buttonStyles}
2624
/>
2725
),
2826
addDivider: addDivider(blockType),

draft-js-divider-plugin/yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ ua-parser-js@^0.7.9:
103103
version "0.7.14"
104104
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.14.tgz#110d53fa4c3f326c121292bbeac904d2e03387ca"
105105

106+
union-class-names@^1.0.0:
107+
version "1.0.0"
108+
resolved "https://registry.yarnpkg.com/union-class-names/-/union-class-names-1.0.0.tgz#9259608adacc39094a2b0cfe16c78e6200617847"
109+
106110
watch@^1.0.2:
107111
version "1.0.2"
108112
resolved "https://registry.yarnpkg.com/watch/-/watch-1.0.2.tgz#340a717bde765726fa0aa07d721e0147a551df0c"

0 commit comments

Comments
 (0)