Masonry: Flexible width items #3993
Open
+540
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR builds on Masonry's multi-column to add support for flexible width items.
This change introduces a new Masonry's experimental prop to support such feature:
_getResponsiveModuleConfigForSecondItem
Current state
At a high level, the current multi-column items work using the
_getColumnSpanConfig
prop. This sets a static width column span, based on the grid size. For more details, please see #3636Flexible Width Items
By introducing flexible width items, the idea is that the second item in the Masonry grid can span to fill empty columns in the first row of the grid, within the limits configured by using
_getResponsiveModuleConfigForSecondItem
._getResponsiveModuleConfigForSecondItem
_getResponsiveModuleConfigForSecondItem
is a function which takes the item data (T) as an input and returns one of the following:number
: Fixed column span (same behavior as today){ min: number, max: number }
: An object which defines the minimum and maximum limits the flexible width item could span.undefined
: This is an indicator to know the functionality should fallback to current behavior.We've identified the following edge cases and defined fallback logic:
_getResponsiveModuleConfigForSecondItem
logic will be ignored, and fallback to the current logic._getResponsiveModuleConfigForSecondItem
is undefined but_getColumnSpanConfig
is defined for the second item, it should still behave as the existing multi-column items, whose width depends on the grid size._getResponsiveModuleConfigForSecondItem
and_getColumnSpanConfig
are set for the second item, the flexible width_getResponsiveModuleConfigForSecondItem
behavior will have preference.Test
Added Unit Test for new functionality
Tested locally:
Using _getColumnSpanConfig for item1:
and using _getResponsiveModuleConfigForSecondItem for item2
5cols example: Multicol item (red) 3 cols. Flexible Width item (black) 2 cols.
![image](https://private-user-images.githubusercontent.com/43483573/412600966-5453296c-3ccc-4c8d-ade5-5c90dc319e92.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjI5MzUsIm5iZiI6MTczOTQ2MjYzNSwicGF0aCI6Ii80MzQ4MzU3My80MTI2MDA5NjYtNTQ1MzI5NmMtM2NjYy00YzhkLWFkZTUtNWM5MGRjMzE5ZTkyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE2MDM1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgyMzdkMTgxZmQyYjFmYzg4ZGI5YzNmMzNjMDFjYzFmYmNkYzk3ZWI3ZTQ4N2VlMDk2ZjZhMDFlYjAwZTRiNjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.EDBcIG_RgF0lANalfX2RqC2cFF3lJkgSsJw4PoJ1IuM)
6cols example: Multicol item (red) 3 cols. Flexible Width item (black) 3 cols.
![image](https://private-user-images.githubusercontent.com/43483573/412601060-d7b09e01-faa0-420c-804b-c51fdecaf390.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjI5MzUsIm5iZiI6MTczOTQ2MjYzNSwicGF0aCI6Ii80MzQ4MzU3My80MTI2MDEwNjAtZDdiMDllMDEtZmFhMC00MjBjLTgwNGItYzUxZmRlY2FmMzkwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE2MDM1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU5MzA3NmQ5NTBhY2Q3ODI5NDczNGNjZmU5NjZkYmFiMDY1YTNkOGY4NzA3MDU3OTNiNGFmYWZlZmVlNWEwZDUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.w3baZE8X0o3voBUwQnpB_6Nold70JN2IjnDN3MtIClk)
Testing max limit: Multicol item (red) 4 cols. Flexible Width item (black) 6 cols.
![image](https://private-user-images.githubusercontent.com/43483573/412602210-94e33b31-4289-44ef-8bd0-d7ae31fc3f0a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjI5MzUsIm5iZiI6MTczOTQ2MjYzNSwicGF0aCI6Ii80MzQ4MzU3My80MTI2MDIyMTAtOTRlMzNiMzEtNDI4OS00NGVmLThiZDAtZDdhZTMxZmMzZjBhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE2MDM1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNjOGM4NGVkZWY0MDg3NTdhYTQzM2I4N2EzMzkxODA4OWNjNGEzZTA4MDBhY2M5NWEyZjliMjNkOTEwZWQwZjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.I-ub4VIQ1-9GbUJiGSt-uoImIf-gXm3IqL9KtJy7ORM)
Testing min limit: Flex width item (black) doesn't fit first row, so it gets pushed to second row using min limit width
![image](https://private-user-images.githubusercontent.com/43483573/412602719-777435e8-d4e5-444a-a929-b5a4c93c4bdd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjI5MzUsIm5iZiI6MTczOTQ2MjYzNSwicGF0aCI6Ii80MzQ4MzU3My80MTI2MDI3MTktNzc3NDM1ZTgtZDRlNS00NDRhLWE5MjktYjVhNGM5M2M0YmRkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE2MDM1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg4NTdkNzU5ZmE1MTQ1MTI1N2RkN2NkYTQ2NDU1MjkyOGUwOGVlZGVmZjM5MDRmYTUwOWI5N2NmYzNmYjBlMWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.pkZFQubNcJiSkuR1SQ-47NYCElyfBPhWDG3qc0VZH_k)