Skip to content

Commit

Permalink
feat(react-json-tree): Add keyPath to getItemString (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshhunt authored Dec 22, 2020
1 parent a46b432 commit 85b4b0f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react-json-tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ You can pass `getItemString` to customize the way arrays, objects, and iterable
By default, it'll be:

```jsx
<JSONTree getItemString={(type, data, itemType, itemString)
<JSONTree getItemString={(type, data, itemType, itemString, keyPath)
=> <span>{itemType} {itemString}</span>}
```

But if you pass the following:

```jsx
const getItemString = (type, data, itemType, itemString)
const getItemString = (type, data, itemType, itemString, keyPath)
=> (<span> // {type}</span>);
```
Expand Down
3 changes: 2 additions & 1 deletion packages/react-json-tree/src/JSONNestedNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ export default class JSONNestedNode extends React.Component<Props, State> {
nodeType,
data,
itemType,
createItemString(data, collectionLimit)
createItemString(data, collectionLimit),
keyPath
);
const stylingArgs = [keyPath, nodeType, expanded, expandable] as const;

Expand Down
3 changes: 2 additions & 1 deletion packages/react-json-tree/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ interface JSONNestedNodeCircularPropsPassedThroughJSONTree {
nodeType: string,
data: any,
itemType: React.ReactNode,
itemString: string
itemString: string,
keyPath: (string | number)[]
) => React.ReactNode;
postprocessValue: (value: any) => any;
isCustomNode: (value: any) => boolean;
Expand Down

0 comments on commit 85b4b0f

Please sign in to comment.