Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Commit 334ac31

Browse files
committed
Support functions
1 parent d300d30 commit 334ac31

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

examples/src/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export default class App extends Component {
1111
date: new Date(),
1212
object: {
1313
foo: 'bar',
14-
baz: undefined
14+
baz: undefined,
15+
func: (function User() {})
1516
},
1617
immutable: Map({ key: 'value' })
1718
};

src/JSONFunctionNode.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react';
2+
import reactMixin from 'react-mixin';
3+
import { SquashClickEventMixin } from './mixins';
4+
import hexToRgb from './utils/hexToRgb';
5+
6+
const styles = {
7+
base: {
8+
paddingTop: 3,
9+
paddingBottom: 3,
10+
paddingRight: 0,
11+
marginLeft: 14,
12+
WebkitUserSelect: 'text',
13+
MozUserSelect: 'text'
14+
},
15+
label: {
16+
display: 'inline-block',
17+
marginRight: 5
18+
}
19+
};
20+
21+
@reactMixin.decorate(SquashClickEventMixin)
22+
export default class JSONFunctionNode extends React.Component {
23+
render() {
24+
let backgroundColor = 'transparent';
25+
if (this.props.previousValue !== this.props.value) {
26+
const bgColor = hexToRgb(this.props.theme.base06);
27+
backgroundColor = `rgba(${bgColor.r}, ${bgColor.g}, ${bgColor.b}, 0.1)`;
28+
}
29+
return (
30+
<li style={{ ...styles.base, backgroundColor }} onClick={::this.handleClick}>
31+
<label style={{
32+
...styles.label,
33+
color: this.props.theme.base0D,
34+
...this.props.styles.getLabelStyle('Undefined', true)
35+
}}>
36+
{this.props.keyName}:
37+
</label>
38+
<span style={{
39+
color: this.props.theme.base08,
40+
...this.props.styles.getValueStyle('Undefined', true)
41+
}}>{ this.props.value.toString() }</span>
42+
</li>
43+
);
44+
}
45+
}

src/grab-node.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import JSONBooleanNode from './JSONBooleanNode';
99
import JSONNullNode from './JSONNullNode';
1010
import JSONDateNode from './JSONDateNode';
1111
import JSONUndefinedNode from './JSONUndefinedNode';
12+
import JSONFunctionNode from './JSONFunctionNode';
1213

1314
export default function(key, value, prevValue, theme, styles, getItemString, initialExpanded = false) {
1415
const nodeType = objType(value);
@@ -30,6 +31,8 @@ export default function(key, value, prevValue, theme, styles, getItemString, ini
3031
return <JSONNullNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} styles={styles} />;
3132
} else if (nodeType === 'Undefined') {
3233
return <JSONUndefinedNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} styles={styles} />;
34+
} else if (nodeType === 'Function') {
35+
return <JSONFunctionNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} styles={styles} />;
3336
}
3437
return false;
3538
}

0 commit comments

Comments
 (0)