@@ -426,7 +426,7 @@ let defaultExpandedKeys = new Set(['projects', 'project-2', 'project-5', 'report
426
426
427
427
const TreeExampleDynamicRender = < T extends object > ( args : TreeProps < T > ) : JSX . Element => {
428
428
let treeData = useTreeData < any > ( {
429
- initialItems : rows ,
429
+ initialItems : args . items as any ?? rows ,
430
430
getKey : item => item . id ,
431
431
getChildren : item => item . childItems
432
432
} ) ;
@@ -1196,3 +1196,80 @@ export const TreeWithDragAndDropVirtualized = {
1196
1196
render : TreeDragAndDropVirtualizedRender ,
1197
1197
name : 'Tree with drag and drop (virtualized)'
1198
1198
} ;
1199
+
1200
+
1201
+ interface ITreeItem {
1202
+ id : string ,
1203
+ name : string ,
1204
+ childItems ?: Iterable < ITreeItem >
1205
+ }
1206
+
1207
+ let totalItems = 0 ;
1208
+ let itemKeys = new Set < any > ( ) ;
1209
+ /**
1210
+ * Generates a tree data structure with 10 items per level and 6 levels deep.
1211
+ * @returns Array of tree items with the specified structure.
1212
+ */
1213
+ function generateTreeData ( ) : Array < ITreeItem > {
1214
+ /**
1215
+ * Recursively generates tree items for a given level.
1216
+ * @param level - Current depth level (1-6).
1217
+ * @param parentId - Parent item ID for generating unique child IDs.
1218
+ * @returns Array of tree items for this level.
1219
+ */
1220
+ function generateLevel ( level : number , parentId : string = '' ) : Array < ITreeItem > {
1221
+ const items : ITreeItem [ ] = [ ] ;
1222
+ const itemsPerLevel = 7 ;
1223
+
1224
+ for ( let i = 1 ; i < itemsPerLevel ; i ++ ) {
1225
+ const itemId = parentId ? `${ parentId } -${ i } ` : `level-${ level } -item-${ i } ` ;
1226
+ const itemName = `Level ${ level } Item ${ i } ` ;
1227
+
1228
+ const item : ITreeItem = {
1229
+ id : itemId ,
1230
+ name : itemName
1231
+ } ;
1232
+
1233
+ // Add child items if not at the deepest level (level 6)
1234
+ if ( level < 6 ) {
1235
+ item . childItems = generateLevel ( level + 1 , itemId ) ;
1236
+ }
1237
+
1238
+ totalItems ++ ;
1239
+ items . push ( item ) ;
1240
+ itemKeys . add ( itemId ) ;
1241
+ }
1242
+
1243
+ return items ;
1244
+ }
1245
+
1246
+ return generateLevel ( 1 ) ;
1247
+ }
1248
+
1249
+ const treeData = generateTreeData ( ) ;
1250
+ console . log ( `Total items: ${ totalItems } ` ) ;
1251
+
1252
+ function HugeVirtualizedTreeRender < T extends object > ( args : TreeProps < T > ) : JSX . Element {
1253
+ let [ expandedKeys , setExpandedKeys ] = useState ( new Set < Key > ( ) ) ;
1254
+ let expandAll = ( ) => {
1255
+ setExpandedKeys ( itemKeys ) ;
1256
+ } ;
1257
+
1258
+ return (
1259
+ < >
1260
+ < button onClick = { expandAll } > Expand All { totalItems } </ button >
1261
+ < Virtualizer layout = { ListLayout } layoutOptions = { { rowHeight : 30 } } >
1262
+ < TreeExampleDynamicRender { ...args } expandedKeys = { expandedKeys } onExpandedChange = { setExpandedKeys } />
1263
+ </ Virtualizer >
1264
+ </ >
1265
+ ) ;
1266
+ }
1267
+
1268
+ export const HugeVirtualizedTree : StoryObj < typeof VirtualizedTreeRender > = {
1269
+ ...TreeExampleDynamic ,
1270
+ args : {
1271
+ ...TreeExampleDynamic . args ,
1272
+ items : treeData
1273
+ } ,
1274
+ render : ( args ) => < HugeVirtualizedTreeRender { ...args } />
1275
+ } ;
0 commit comments