Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Commit

Permalink
Pass more information to InteractiveLabel component
Browse files Browse the repository at this point in the history
  • Loading branch information
Aziz Yuldoshev committed Jun 6, 2015
1 parent ce2b029 commit 682c7ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ to built-in search bar. Pass `false` to disable search.

#### props.interactiveLabel

Pass component factory that would accept `value` property. Can be used to create
custom input fields for JSON property names and primitive values, see
[#3](https://github.com/Lapple/react-json-inspector/issues/3) for more information.
Pass component factory that would receive the following properties:

- `value`, either stringified property value or key value that is being interacted with,
- `originalValue`, either the original property value or key value,
- `isKey`, boolean flag to differentiate between interacting with keys or properties,
- `keypath`, keypath of the node being interacted with, will be the same for keys and properties

Can be used to create custom input fields for JSON property names and primitive
values, see [#3](https://github.com/Lapple/react-json-inspector/issues/3)
for more information.

#### props.onClick

Expand Down
13 changes: 9 additions & 4 deletions lib/leaf.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var Leaf = React.createClass({
D.span({ className: 'json-inspector__key' },
this.format(d.key),
':',
this.renderInteractiveLabel(d.key)),
this.renderInteractiveLabel(d.key, true)),
this.renderTitle(),
this.renderShowOriginalButton()),
this.renderChildren());
Expand All @@ -60,7 +60,7 @@ var Leaf = React.createClass({
default:
return D.span({ className: 'json-inspector__value json-inspector__value_' + t.toLowerCase() },
this.format(String(data)),
this.renderInteractiveLabel(String(data)));
this.renderInteractiveLabel(data, false));
}
},
renderChildren: function() {
Expand Down Expand Up @@ -99,10 +99,15 @@ var Leaf = React.createClass({
onClick: this._onShowOriginalClick
});
},
renderInteractiveLabel: function(value) {
renderInteractiveLabel: function(originalValue, isKey) {
if (typeof this.props.interactiveLabel === 'function') {
return this.props.interactiveLabel({
value: value
// The distinction between `value` and `originalValue` is
// provided to have backwards compatibility.
value: String(originalValue),
originalValue: originalValue,
isKey: isKey,
keypath: this.keypath()
});
}

Expand Down

0 comments on commit 682c7ed

Please sign in to comment.