Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Masonry: Enable whitespaceThreshold prop #3825

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/gestalt/src/Masonry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ type Props<T> = {
* Experimental flag to enable dynamic heights on items. This only works if multi column items are enabled.
*/
_dynamicHeights?: boolean;
/**
* Experimental prop to define how much whitespace is good enough to position multicolumn modules
*
* This is an experimental prop and may be removed or changed in the future
*/
_whitespaceThreshold?: number;
};

type State<T> = {
Expand Down Expand Up @@ -585,6 +591,7 @@ export default class Masonry<T> extends ReactComponent<Props<T>, State<T>> {
_getColumnSpanConfig,
_loadingStateItems = [],
_renderLoadingStateItems,
_whitespaceThreshold,
} = this.props;
const { hasPendingMeasurements, measurementStore, width } = this.state;
const { positionStore } = this;
Expand All @@ -607,6 +614,7 @@ export default class Masonry<T> extends ReactComponent<Props<T>, State<T>> {
logWhitespace: _logTwoColWhitespace,
_getColumnSpanConfig,
renderLoadingState,
whitespaceThreshold: _whitespaceThreshold,
});
} else if (layout === 'uniformRow') {
getPositions = uniformRowLayout({
Expand All @@ -631,6 +639,7 @@ export default class Masonry<T> extends ReactComponent<Props<T>, State<T>> {
logWhitespace: _logTwoColWhitespace,
_getColumnSpanConfig,
renderLoadingState,
whitespaceThreshold: _whitespaceThreshold,
});
}

Expand Down
4 changes: 4 additions & 0 deletions packages/gestalt/src/Masonry/getLayoutAlgorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function getLayoutAlgorithm<T>({
_logTwoColWhitespace,
_loadingStateItems = [],
renderLoadingState,
_whitespaceThreshold,
}: {
align: Align;
columnWidth: number;
Expand All @@ -37,6 +38,7 @@ export default function getLayoutAlgorithm<T>({
) => void;
_loadingStateItems?: ReadonlyArray<LoadingStateItem>;
renderLoadingState?: boolean;
_whitespaceThreshold?: number;
}): (items: ReadonlyArray<T> | ReadonlyArray<LoadingStateItem>) => ReadonlyArray<Position> {
if ((layout === 'flexible' || layout === 'serverRenderedFlexible') && width !== null) {
return fullWidthLayout({
Expand All @@ -49,6 +51,7 @@ export default function getLayoutAlgorithm<T>({
logWhitespace: _logTwoColWhitespace,
_getColumnSpanConfig,
renderLoadingState,
whitespaceThreshold: _whitespaceThreshold,
});
}
if (layout === 'uniformRow') {
Expand All @@ -74,5 +77,6 @@ export default function getLayoutAlgorithm<T>({
width,
_getColumnSpanConfig,
renderLoadingState,
whitespaceThreshold: _whitespaceThreshold,
});
}
11 changes: 11 additions & 0 deletions packages/gestalt/src/MasonryV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ type Props<T> = {
* Experimental flag to enable dynamic heights on items. This only works if multi column items are enabled.
*/
_dynamicHeights?: boolean;
/**
* Experimental prop to define how much whitespace is good enough to position multicolumn modules
*
* This is an experimental prop and may be removed or changed in the future
*/
_whitespaceThreshold?: number;
};

type MasonryRef = {
Expand Down Expand Up @@ -370,6 +376,7 @@ function useLayout<T>({
_getColumnSpanConfig,
_loadingStateItems = [],
_renderLoadingStateItems,
_whitespaceThreshold,
}: {
align: Align;
columnWidth: number;
Expand All @@ -391,6 +398,7 @@ function useLayout<T>({
_getColumnSpanConfig?: (item: T) => ColumnSpanConfig;
_loadingStateItems?: ReadonlyArray<LoadingStateItem>;
_renderLoadingStateItems?: Props<T>['_renderLoadingStateItems'];
_whitespaceThreshold?: number;
}): {
height: number;
hasPendingMeasurements: boolean;
Expand All @@ -416,6 +424,7 @@ function useLayout<T>({
_logTwoColWhitespace,
_loadingStateItems,
renderLoadingState,
_whitespaceThreshold,
});

const hasMultiColumnItems =
Expand Down Expand Up @@ -692,6 +701,7 @@ function Masonry<T>(
_dynamicHeights,
_loadingStateItems = [],
_renderLoadingStateItems,
_whitespaceThreshold,
}: Props<T>,
ref:
| {
Expand Down Expand Up @@ -815,6 +825,7 @@ function Masonry<T>(
_getColumnSpanConfig,
_loadingStateItems,
_renderLoadingStateItems,
_whitespaceThreshold,
});

useFetchOnScroll({
Expand Down
Loading