File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ const mergeTheme = (props) => {
50
50
placeholderRenderer : PlaceholderRendererDefault ,
51
51
scaffoldBlockPxWidth : 44 ,
52
52
slideRegionSize : 100 ,
53
+ rowHeight : 62 ,
53
54
treeNodeRenderer : TreeNode ,
54
55
}
55
56
for ( const propKey of Object . keys ( overridableDefaults ) ) {
@@ -563,6 +564,7 @@ class ReactSortableTree extends Component {
563
564
scaffoldBlockPxWidth,
564
565
searchFocusOffset,
565
566
rowDirection,
567
+ rowHeight,
566
568
} = mergeTheme ( this . props )
567
569
const TreeNodeRenderer = this . treeNodeRenderer
568
570
const NodeContentRenderer = this . nodeContentRenderer
@@ -597,6 +599,7 @@ class ReactSortableTree extends Component {
597
599
return (
598
600
< TreeNodeRenderer
599
601
style = { style }
602
+ rowHeight = { rowHeight }
600
603
key = { nodeKey }
601
604
listIndex = { listIndex }
602
605
getPrevRow = { getPrevRow }
@@ -862,6 +865,10 @@ export type ReactSortableTreeProps = {
862
865
placeholderRenderer : any
863
866
}
864
867
868
+ // Sets the height of a given tree row item in pixels. Can either be a number
869
+ // or a function to calculate dynamically
870
+ rowHeight ?: number | ( ( treeIndex : number , node : any , path : any [ ] ) => number )
871
+
865
872
// Determine the unique key used to identify each node and
866
873
// generate the `path` array passed in callbacks.
867
874
// By default, returns the index in the tree (omitting hidden nodes).
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export interface TreeRendererProps {
22
22
scaffoldBlockPxWidth : number
23
23
lowerSiblingCounts : number [ ]
24
24
rowDirection ?: 'ltr' | 'rtl' | string | undefined
25
+ rowHeight : number | ( ( treeIndex : number , node : any , path : any [ ] ) => number )
25
26
26
27
listIndex : number
27
28
children : JSX . Element [ ]
@@ -63,6 +64,7 @@ const TreeNode: React.FC<TreeRendererProps> = (props) => {
63
64
draggedNode,
64
65
canDrop,
65
66
treeIndex,
67
+ rowHeight,
66
68
treeId : _treeId , // Delete from otherProps
67
69
getPrevRow : _getPrevRow , // Delete from otherProps
68
70
node : _node , // Delete from otherProps
@@ -183,9 +185,14 @@ const TreeNode: React.FC<TreeRendererProps> = (props) => {
183
185
? { right : scaffoldBlockPxWidth * scaffoldBlockCount }
184
186
: { left : scaffoldBlockPxWidth * scaffoldBlockCount }
185
187
188
+ let calculatedRowHeight = rowHeight
189
+ if ( typeof rowHeight === 'function' ) {
190
+ calculatedRowHeight = rowHeight ( treeIndex , _node , _path )
191
+ }
186
192
return connectDropTarget (
187
193
< div
188
194
{ ...otherProps }
195
+ style = { { height : `${ calculatedRowHeight } px` } }
189
196
className = { classnames ( 'rst__node' , rowDirectionClass ?? '' ) } >
190
197
{ scaffold }
191
198
You can’t perform that action at this time.
0 commit comments