Skip to content

Commit 61ea0bc

Browse files
added rowHeight prop (to match the original frontend-collective spec)
1 parent a45f490 commit 61ea0bc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/react-sortable-tree.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const mergeTheme = (props) => {
5050
placeholderRenderer: PlaceholderRendererDefault,
5151
scaffoldBlockPxWidth: 44,
5252
slideRegionSize: 100,
53+
rowHeight: 62,
5354
treeNodeRenderer: TreeNode,
5455
}
5556
for (const propKey of Object.keys(overridableDefaults)) {
@@ -563,6 +564,7 @@ class ReactSortableTree extends Component {
563564
scaffoldBlockPxWidth,
564565
searchFocusOffset,
565566
rowDirection,
567+
rowHeight,
566568
} = mergeTheme(this.props)
567569
const TreeNodeRenderer = this.treeNodeRenderer
568570
const NodeContentRenderer = this.nodeContentRenderer
@@ -597,6 +599,7 @@ class ReactSortableTree extends Component {
597599
return (
598600
<TreeNodeRenderer
599601
style={style}
602+
rowHeight={rowHeight}
600603
key={nodeKey}
601604
listIndex={listIndex}
602605
getPrevRow={getPrevRow}
@@ -862,6 +865,10 @@ export type ReactSortableTreeProps = {
862865
placeholderRenderer: any
863866
}
864867

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+
865872
// Determine the unique key used to identify each node and
866873
// generate the `path` array passed in callbacks.
867874
// By default, returns the index in the tree (omitting hidden nodes).

src/tree-node.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface TreeRendererProps {
2222
scaffoldBlockPxWidth: number
2323
lowerSiblingCounts: number[]
2424
rowDirection?: 'ltr' | 'rtl' | string | undefined
25+
rowHeight: number | ((treeIndex: number, node: any, path: any[]) => number)
2526

2627
listIndex: number
2728
children: JSX.Element[]
@@ -63,6 +64,7 @@ const TreeNode: React.FC<TreeRendererProps> = (props) => {
6364
draggedNode,
6465
canDrop,
6566
treeIndex,
67+
rowHeight,
6668
treeId: _treeId, // Delete from otherProps
6769
getPrevRow: _getPrevRow, // Delete from otherProps
6870
node: _node, // Delete from otherProps
@@ -183,9 +185,14 @@ const TreeNode: React.FC<TreeRendererProps> = (props) => {
183185
? { right: scaffoldBlockPxWidth * scaffoldBlockCount }
184186
: { left: scaffoldBlockPxWidth * scaffoldBlockCount }
185187

188+
let calculatedRowHeight = rowHeight
189+
if (typeof rowHeight === 'function') {
190+
calculatedRowHeight = rowHeight(treeIndex, _node, _path)
191+
}
186192
return connectDropTarget(
187193
<div
188194
{...otherProps}
195+
style={{ height: `${calculatedRowHeight}px` }}
189196
className={classnames('rst__node', rowDirectionClass ?? '')}>
190197
{scaffold}
191198

0 commit comments

Comments
 (0)