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

Commit 30e65bb

Browse files
committed
Merge pull request #7 from liamkennedy89/master
added JSONDateNode to display Date values
2 parents c6dca23 + e7cb028 commit 30e65bb

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

examples/src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default class App extends Component {
88
const data = {
99
array: [1, 2, 3],
1010
bool: true,
11+
date: new Date(),
1112
object: {
1213
foo: 'bar'
1314
},
@@ -33,6 +34,7 @@ export default class App extends Component {
3334
base0D: '#66d9ef',
3435
base0E: '#ae81ff',
3536
base0F: '#cc6633'
37+
3638
};
3739

3840
return (

src/JSONDateNode.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
},
13+
label: {
14+
display: 'inline-block',
15+
marginRight: 5
16+
}
17+
};
18+
19+
@reactMixin.decorate(SquashClickEventMixin)
20+
export default class JSONDateNode extends React.Component {
21+
render() {
22+
let backgroundColor = 'transparent';
23+
if (this.props.previousValue !== this.props.value) {
24+
const bgColor = hexToRgb(this.props.theme.base06);
25+
backgroundColor = `rgba(${bgColor.r}, ${bgColor.g}, ${bgColor.b}, 0.1)`;
26+
}
27+
return (
28+
<li style={{ ...styles.base, backgroundColor }} onClick={::this.handleClick}>
29+
<label style={{
30+
...styles.label,
31+
color: this.props.theme.base0D
32+
}}>
33+
{this.props.keyName}:
34+
</label>
35+
<span style={{ color: this.props.theme.base0B }}>{this.props.value.toISOString()}</span>
36+
</li>
37+
);
38+
}
39+
}

src/grab-node.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import JSONStringNode from './JSONStringNode';
77
import JSONNumberNode from './JSONNumberNode';
88
import JSONBooleanNode from './JSONBooleanNode';
99
import JSONNullNode from './JSONNullNode';
10+
import JSONDateNode from './JSONDateNode';
1011

1112
export default function(key, value, prevValue, theme, initialExpanded = false) {
1213
const nodeType = objType(value);
@@ -22,8 +23,10 @@ export default function(key, value, prevValue, theme, initialExpanded = false) {
2223
return <JSONNumberNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} />;
2324
} else if (nodeType === 'Boolean') {
2425
return <JSONBooleanNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} />;
25-
} else if (nodeType === 'Null') {
26+
} else if (nodeType === 'Date') {
27+
return <JSONDateNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} />;
28+
}else if (nodeType === 'Null') {
2629
return <JSONNullNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} />;
27-
}
30+
}
2831
return false;
2932
}

0 commit comments

Comments
 (0)