Skip to content

Commit

Permalink
#186: Update types and README for the onToggleCollapse callback. Remo…
Browse files Browse the repository at this point in the history
…ved rjvId as it appears to be more of an internal id that isn't exposed to consumers.
  • Loading branch information
AtlHermanChow committed Jan 20, 2020
1 parent d053cb5 commit 1710bd9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -49,6 +49,7 @@ Name|Type|Default|Description
`collapsed`|`boolean` or `integer`|`false`|When set to `true`, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth.
`collapseStringsAfterLength`|`integer`|`false`|When an integer value is assigned, strings will be cut off at that length. Collapsed strings are followed by an ellipsis. String content can be expanded and collapsed by clicking on the string value.
`shouldCollapse`|`(field)=>{}`|`false`|Callback function to provide control over what objects and arrays should be collapsed by default. An object is passed to the callback containing `name`, `src`, `type` ("array" or "object") and `namespace`.
`onToggleCollapse`|`(collapse)=>{}`|`false`|Callback function to hook into when an object or array has been expanded or collapsed. An object is passed to the callback containing `expanded`, `name`, and `namespace`.
`groupArraysAfterLength`|`integer`|`100`|When an integer value is assigned, arrays will be displayed in groups by count of the value. Groups are displayed with brakcet notation and can be expanded and collapsed by clickong on the brackets.
`enableClipboard`|`boolean` or `(copy)=>{}`|`true`|When prop is not `false`, the user can copy objects and arrays to clipboard by clicking on the clipboard icon. Copy callbacks are supported.
`displayObjectSize`|`boolean`|`true`|When set to `true`, objects and arrays are labeled with size
Expand Down
22 changes: 22 additions & 0 deletions index.d.ts
Expand Up @@ -117,6 +117,12 @@ export interface ReactJsonViewProps {
* Default: false
*/
onSelect?: ((select: OnSelectProps) => void) | false;
/**
* When a function is passed in, toggling an expand/collapse object triggers the onToggleCollapse method to be called.
*
* Default: false
*/
onToggleCollapse?: ((collapse: onToggleCollapseProps) => void) | false;
/**
* Custom message for validation failures to onEdit, onAdd, or onDelete callbacks.
*
Expand Down Expand Up @@ -219,6 +225,22 @@ export interface OnSelectProps {

}

export interface onToggleCollapseProps {
/**
* The name of the currently selected entry.
*/
name: string | null;
/**
* The new expanded state of the expandable/collapsable object.
*/
expanded: boolean;
/**
* List of keys representing the scopes above the selected entry.
*/
namespace: Array<string | null>;

}

export type TypeDefaultValue = string | number | boolean | object;

export interface ThemeObject {
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/DataTypes/Object.js
Expand Up @@ -92,7 +92,7 @@ class RjvObject extends React.PureComponent {
this.state.expanded
);
if (typeof onToggleCollapse === 'function') {
onToggleCollapse({ expanded: this.state.expanded, name, namespace, rjvId });
onToggleCollapse({ expanded: this.state.expanded, name, namespace });
}
});
}
Expand Down

0 comments on commit 1710bd9

Please sign in to comment.