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

Commit 6291b9e

Browse files
committed
added JSONDateNode to display Date values
1 parent c6dca23 commit 6291b9e

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-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: 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}"</span>
36+
</li>
37+
);
38+
}
39+
}

src/grab-node.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ export default function(key, value, prevValue, theme, initialExpanded = false) {
2222
return <JSONNumberNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} />;
2323
} else if (nodeType === 'Boolean') {
2424
return <JSONBooleanNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} />;
25-
} else if (nodeType === 'Null') {
25+
} else if (nodeType === 'Date') {
2626
return <JSONNullNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} />;
27-
}
27+
}else if (nodeType === 'Null') {
28+
return <JSONNullNode keyName={key} previousValue={prevValue} theme={theme} value={value} key={key} />;
29+
}
2830
return false;
2931
}

0 commit comments

Comments
 (0)