Skip to content

added key value click recognizing #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/leaf.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,29 @@ var Leaf = React.createClass({
DTPath: p.DTPath,
};

var onLabelClick = this._onClick.bind(this, d);
var onLabelClick = this._onClick.bind(this, d, true);
var onValueClick = this._onClick.bind(this, d, false);
var dataType = type(this.data());
var isLeaf = dataType !== 'Array' && dataType !== 'Object';

return D.div({ className: this.getClassName(), id: 'leaf-' + this._rootPath() },
D.input({ className: 'json-inspector__radio', type: 'radio', name: p.id, id: id, tabIndex: -1 }),
D.label({ className: 'json-inspector__line', htmlFor: id, onClick: onLabelClick },
D.label({ className: 'json-inspector__line', htmlFor: id, onClick: this.toggle },
D.div({ className: 'json-inspector__flatpath' },
d.path),
isLeaf ?
null :
this.state.expanded ? D.i({ className: 'icon caret down' }) : D.i({ className: 'icon caret right' }),
D.span({ className: isLeaf ? 'json-inspector__leafKey' : 'json-inspector__key' },
D.span({ className: isLeaf ? 'json-inspector__leafKey' : 'json-inspector__key',
onClick: isLeaf ? onLabelClick : undefined },
this.format(d.key),
':',
this.renderInteractiveLabel(d.key, true)),
this.renderTitle(),
this.renderTitle(onValueClick),
this.renderShowOriginalButton()),
this.renderChildren());
},
renderTitle: function() {
renderTitle: function(onValueClick) {
var data = this.data();
var t = type(data);

Expand All @@ -67,7 +69,7 @@ var Leaf = React.createClass({
return D.span({ className: 'json-inspector__value json-inspector__value_helper' },
'{} ' + items(Object.keys(data).length));
default:
return D.span({ className: 'json-inspector__value json-inspector__value_' + t.toLowerCase() },
return D.span({ className: 'json-inspector__value json-inspector__value_' + t.toLowerCase(), onClick: onValueClick },
this.format(String(data)),
this.renderInteractiveLabel(data, false));
}
Expand Down Expand Up @@ -194,9 +196,9 @@ var Leaf = React.createClass({
expanded: !this.state.expanded
});
},
_onClick: function(data, e) {
_onClick: function(data, isLabel, e) {
this.toggle();
this.props.onClick(data);
this.props.onClick(data, isLabel);

e.stopPropagation();
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generic-react-json-inspector",
"version": "6.1.8",
"version": "6.1.9",
"description": "React JSON inspector component",
"main": "json-inspector.js",
"author": {
Expand Down