Skip to content

Commit

Permalink
feat(masonry): Create functionality to attach bricks below the top brick
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan-Palan committed Sep 2, 2024
1 parent e222259 commit 2ee22f9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions modules/masonry/playground/pages/workspace/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Brick } from './data';

export function getBelowBricksIds(arr: Brick[], item: string): string[] {
let result: string[] = [];

function recursiveSearch(arr: Brick[], item: string) {
arr.forEach((element, index) => {
if (element.id === item) {
arr.slice(index + 1, arr.length).map((el) => {
result = result.concat(el.childBricks);
result = result.concat(el.id);
});
return;
}
if (Array.isArray(element.children)) {
recursiveSearch(element.children, item);
}
});
}

recursiveSearch(arr, item);
return result;
}

0 comments on commit 2ee22f9

Please sign in to comment.