Skip to content

Commit

Permalink
add Layout.width
Browse files Browse the repository at this point in the history
resolves #18
  • Loading branch information
BrunnerLivio committed Jan 21, 2023
1 parent bebd202 commit cc2fd7a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/simple-masonry-layout/src/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Col<T> {
interface ColGroup<T> {
readonly shortest: Col<T> | null;
readonly longest: Col<T> | null;
readonly widest: Col<T> | null;
readonly cols: Col<T>[];
readonly items: GridItem<T>[];

Expand Down Expand Up @@ -41,6 +42,7 @@ export type GridItem<T> = {
export type Layout<T> = {
items: GridItem<T>[];
height: number;
width: number;
};

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

get widest(): Col<T> | 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;
}
Expand Down Expand Up @@ -225,6 +235,7 @@ export function getLayout<T>(
return {
items: group.items,
height: group.longest?.height ?? 0,
width: group.widest?.width ?? 0,
};
} else {
let y = 0;
Expand All @@ -249,6 +260,7 @@ export function getLayout<T>(
return {
items: gridItems,
height: group.longest?.height ?? 0,
width: group.widest?.width ?? 0,
};
}
}
Expand Down

0 comments on commit cc2fd7a

Please sign in to comment.