Skip to content

Commit 5c19ff3

Browse files
committed
docs(types): adds docs for renderCustomNodeElement
1 parent 150f21c commit 5c19ff3

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/Tree/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
5151
rootNodeClassName: '',
5252
branchNodeClassName: '',
5353
leafNodeClassName: '',
54+
renderCustomNodeElement: undefined,
5455
enableLegacyTransitions: false,
5556
};
5657

src/Tree/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ export interface TreeProps {
3434
*/
3535
data: RawNodeDatum[] | RawNodeDatum;
3636

37+
/**
38+
* Custom render function that will be used for every node in the tree.
39+
*
40+
* The function is passed `CustomNodeElementProps` as its first argument.
41+
* `react-d3-tree` expects the function to return a `ReactElement`.
42+
*
43+
* See the `RenderCustomNodeElementFn` type for more details.
44+
*
45+
* {@link Tree.defaultProps.renderCustomNodeElement | Default value}
46+
*/
3747
renderCustomNodeElement?: RenderCustomNodeElementFn;
3848

3949
/**

src/types/common.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,21 @@ export type PathClassFunction = PathFunction;
3333

3434
export type SyntheticEventHandler = (evt: React.SyntheticEvent) => void;
3535

36+
/**
37+
* The properties that are passed to the user-defined `renderCustomNodeElement` render function.
38+
*/
3639
export interface CustomNodeElementProps {
40+
/**
41+
* The full datum of the node that is being rendered.
42+
*/
3743
nodeDatum: TreeNodeDatum;
44+
/**
45+
* Toggles the expanded/collapsed state of the node.
46+
*
47+
* Provided for customized control flow; e.g. if we want to toggle the node when its
48+
* label is clicked instead of the node itself.
49+
*/
3850
toggleNode: () => void;
3951
}
4052

41-
/**
42-
* Function to render a custom node element. Should return a `ReactElement`.
43-
*/
4453
export type RenderCustomNodeElementFn = (rd3tProps: CustomNodeElementProps) => JSX.Element;

0 commit comments

Comments
 (0)