Skip to content

Commit cc2fd7a

Browse files
committed
add Layout.width
resolves #18
1 parent bebd202 commit cc2fd7a

File tree

1 file changed

+12
-0
lines changed
  • packages/simple-masonry-layout/src

1 file changed

+12
-0
lines changed

packages/simple-masonry-layout/src/grid.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Col<T> {
1111
interface ColGroup<T> {
1212
readonly shortest: Col<T> | null;
1313
readonly longest: Col<T> | null;
14+
readonly widest: Col<T> | null;
1415
readonly cols: Col<T>[];
1516
readonly items: GridItem<T>[];
1617

@@ -41,6 +42,7 @@ export type GridItem<T> = {
4142
export type Layout<T> = {
4243
items: GridItem<T>[];
4344
height: number;
45+
width: number;
4446
};
4547

4648
/**
@@ -83,6 +85,14 @@ class MasonryColumnGroup<T> implements ColGroup<T> {
8385
return this._cols.slice().sort((a, b) => b.height - a.height)[0];
8486
}
8587

88+
get widest(): Col<T> | null {
89+
if (this._cols.length === 0) {
90+
return null;
91+
}
92+
93+
return this._cols.slice().sort((a, b) => b.width - a.width)[0];
94+
}
95+
8696
get cols() {
8797
return this._cols;
8898
}
@@ -225,6 +235,7 @@ export function getLayout<T>(
225235
return {
226236
items: group.items,
227237
height: group.longest?.height ?? 0,
238+
width: group.widest?.width ?? 0,
228239
};
229240
} else {
230241
let y = 0;
@@ -249,6 +260,7 @@ export function getLayout<T>(
249260
return {
250261
items: gridItems,
251262
height: group.longest?.height ?? 0,
263+
width: group.widest?.width ?? 0,
252264
};
253265
}
254266
}

0 commit comments

Comments
 (0)