Skip to content

Commit c76380b

Browse files
bkremJordan Rosenberg
andauthored
feat: provide HierarchyPointNode for renderCustomNodeElement (#355)
Co-authored-by: Jordan Rosenberg <[email protected]>
1 parent 3803c24 commit c76380b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Node/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,17 @@ export default class Node extends React.Component<NodeProps, NodeState> {
118118

119119
// TODO: needs tests
120120
renderNodeElement = () => {
121-
const { data, renderCustomNodeElement } = this.props;
121+
const { data, hierarchyPointNode, renderCustomNodeElement } = this.props;
122122
if (typeof renderCustomNodeElement === 'function') {
123-
return renderCustomNodeElement({ nodeDatum: data, toggleNode: this.handleNodeToggle });
123+
return renderCustomNodeElement({
124+
hierarchyPointNode: hierarchyPointNode,
125+
nodeDatum: data,
126+
toggleNode: this.handleNodeToggle,
127+
});
124128
}
125129

126130
return DefaultNodeElement({
131+
hierarchyPointNode: hierarchyPointNode,
127132
nodeDatum: data,
128133
toggleNode: this.handleNodeToggle,
129134
onNodeClick: this.handleOnClick,

src/types/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export interface CustomNodeElementProps {
4242
* The full datum of the node that is being rendered.
4343
*/
4444
nodeDatum: TreeNodeDatum;
45+
/**
46+
* The D3 `HierarchyPointNode` representation of the node, which wraps `nodeDatum`
47+
* with additional properties.
48+
*/
49+
hierarchyPointNode: HierarchyPointNode<TreeNodeDatum>;
4550
/**
4651
* Toggles the expanded/collapsed state of the node.
4752
*

0 commit comments

Comments
 (0)