From cc2fd7a42a8c18461ba07a0c19c0de9bfab7bdfd Mon Sep 17 00:00:00 2001 From: Livio Date: Sat, 21 Jan 2023 17:26:48 +0100 Subject: [PATCH] add Layout.width resolves #18 --- packages/simple-masonry-layout/src/grid.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/simple-masonry-layout/src/grid.ts b/packages/simple-masonry-layout/src/grid.ts index 61b1387..525c222 100644 --- a/packages/simple-masonry-layout/src/grid.ts +++ b/packages/simple-masonry-layout/src/grid.ts @@ -11,6 +11,7 @@ interface Col { interface ColGroup { readonly shortest: Col | null; readonly longest: Col | null; + readonly widest: Col | null; readonly cols: Col[]; readonly items: GridItem[]; @@ -41,6 +42,7 @@ export type GridItem = { export type Layout = { items: GridItem[]; height: number; + width: number; }; /** @@ -83,6 +85,14 @@ class MasonryColumnGroup implements ColGroup { return this._cols.slice().sort((a, b) => b.height - a.height)[0]; } + get widest(): Col | null { + if (this._cols.length === 0) { + return null; + } + + return this._cols.slice().sort((a, b) => b.width - a.width)[0]; + } + get cols() { return this._cols; } @@ -225,6 +235,7 @@ export function getLayout( return { items: group.items, height: group.longest?.height ?? 0, + width: group.widest?.width ?? 0, }; } else { let y = 0; @@ -249,6 +260,7 @@ export function getLayout( return { items: gridItems, height: group.longest?.height ?? 0, + width: group.widest?.width ?? 0, }; } }