1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/app-desktop/gui/ResizableLayout/utils/findItemByKey.ts
2021-01-02 13:32:15 +00:00

20 lines
462 B
TypeScript

import { LayoutItem } from './types';
export default function findItemByKey(layout: LayoutItem, key: string): LayoutItem {
if (!layout) throw new Error('Layout cannot be null');
function recurseFind(item: LayoutItem): LayoutItem {
if (item.key === key) return item;
if (item.children) {
for (const child of item.children) {
const found = recurseFind(child);
if (found) return found;
}
}
return null;
}
return recurseFind(layout);
}