Skip to content

Commit 7f4d585

Browse files
committed
Add theme support
1 parent a87896d commit 7f4d585

File tree

4 files changed

+71
-30
lines changed

4 files changed

+71
-30
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Then, just write an JSON action in the field, click on Dispatch, and that's all!
5050

5151
Name | Description
5252
------------- | -------------
53+
`theme` | _Same as in LogMonitor's package_ Either a string referring to one of the themes provided by [redux-devtools-themes](https://github.com/gaearon/redux-devtools-themes) (feel free to contribute!) or a custom object of the same format. Optional. By default, set to [`'nicinabox'`](https://github.com/gaearon/redux-devtools-themes/blob/master/src/nicinabox.js).
5354
`initEmpty` | When `true`, the dispatcher is empty. By default, set to `false`, the dispatcher contains : `{ "type": "" }`.
5455

5556
### Contributing

examples/counter/src/containers/DevTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default createDevTools(
1010
changePositionKey='ctrl-q'>
1111
<MultipleMonitors>
1212
<LogMonitor />
13-
<Dispatcher initEmpty="" />
13+
<Dispatcher initEmpty />
1414
</MultipleMonitors>
1515
</DockMonitor>
1616
);

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-devtools-dispatch",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Dispatch your actions manually to test if your app reacts well",
55
"main": "lib/index.js",
66
"scripts": {
@@ -39,5 +39,7 @@
3939
"react": "^0.14.0",
4040
"redux-devtools": "^3.0.0"
4141
},
42-
"dependencies": {}
42+
"dependencies": {
43+
"redux-devtools-themes": "^1.0.0"
44+
}
4345
}

src/Dispatcher.js

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,58 @@
11
import React, { Component, PropTypes } from 'react';
2+
import * as themes from 'redux-devtools-themes';
23

3-
const buttonStyles = {
4-
cursor: 'pointer',
5-
fontWeight: 'bold',
6-
borderRadius: '3px',
7-
padding: '4px',
8-
margin: '5px 3px',
9-
fontSize: '0.8em',
10-
color: 'white',
11-
textDecoration: 'none',
12-
backgroundColor: '#4F5A65',
13-
border: 'none',
14-
position: 'absolute',
15-
bottom: '3px',
16-
right: '5px'
17-
};
18-
19-
const contentStyles = {
20-
background: '#2A2F3A',
21-
margin: '5px',
22-
padding: '5px',
23-
borderRadius: '3px',
24-
outline: 'none',
25-
color: 'white',
26-
overflow: 'auto'
4+
const styles = {
5+
button: {
6+
cursor: 'pointer',
7+
fontWeight: 'bold',
8+
borderRadius: '3px',
9+
padding: '3px',
10+
margin: '5px 3px',
11+
fontSize: '0.8em',
12+
textDecoration: 'none',
13+
border: 'none',
14+
position: 'absolute',
15+
bottom: '3px',
16+
right: '5px'
17+
},
18+
content: {
19+
margin: '5px',
20+
padding: '5px',
21+
borderRadius: '3px',
22+
outline: 'none',
23+
overflow: 'auto'
24+
},
2725
};
2826

2927
export default class Dispatcher extends Component {
3028
static contextTypes = {
3129
store: PropTypes.object
3230
};
3331

32+
static propTypes = {
33+
dispatch: PropTypes.func,
34+
computedStates: PropTypes.array,
35+
actionsById: PropTypes.object,
36+
stagedActionIds: PropTypes.array,
37+
skippedActionIds: PropTypes.array,
38+
monitorState: PropTypes.shape({
39+
initialScrollTop: PropTypes.number
40+
}),
41+
42+
initEmpty: PropTypes.bool,
43+
theme: PropTypes.oneOfType([
44+
PropTypes.object,
45+
PropTypes.string,
46+
]),
47+
};
48+
49+
static defaultProps = {
50+
select: (state) => state,
51+
theme: 'nicinabox',
52+
preserveScrollTop: true,
53+
initEmpty: false,
54+
};
55+
3456
static update = () => {};
3557

3658
constructor(props, context) {
@@ -45,11 +67,27 @@ export default class Dispatcher extends Component {
4567
this.refs.action.innerHTML = this.props.initEmpty ? '<br/>' : '{<br/>"type": ""<br/>}';
4668
}
4769

70+
getTheme() {
71+
let { theme } = this.props;
72+
if (typeof theme !== 'string') {
73+
return theme;
74+
}
75+
76+
if (typeof themes[theme] !== 'undefined') {
77+
return themes[theme];
78+
}
79+
80+
console.warn('DevTools theme ' + theme + ' not found, defaulting to nicinabox');
81+
return themes.nicinabox;
82+
}
83+
4884
render() {
85+
const theme = this.getTheme();
86+
4987
return (
50-
<div style={{background: '#4F5A65', fontFamily: 'monaco,Consolas,Lucida Console,monospace'}}>
51-
<div contentEditable='true' style={contentStyles} ref='action'></div>
52-
<button style={buttonStyles} onClick={this.launchAction.bind(this)}>Dispatch</button>
88+
<div style={{background: theme.base02, fontFamily: 'monaco,Consolas,Lucida Console,monospace'}}>
89+
<div contentEditable='true' style={{...styles.content, color: theme.base06, backgroundColor: theme.base00}} ref='action'></div>
90+
<button style={{...styles.button, color: theme.base06, backgroundColor: theme.base02}} onClick={this.launchAction.bind(this)}>Dispatch</button>
5391
</div>
5492
);
5593
}

0 commit comments

Comments
 (0)