feat(gallery): add new gallery component#31101
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
I updated this because this rule prevented the images in my assets/ directory from being served on Vercel.
| // -------------------------------------------------- | ||
|
|
||
| :host(.gallery-layout-uniform) { | ||
| gap: var(--ion-gallery-gap, 16px); |
There was a problem hiding this comment.
Gap currently can only be changed by CSS. Should this be a property that can be updated based on breakpoint, like columns?
There was a problem hiding this comment.
Yes, I lean towards it especially seeing that Chakra does that. I do wonder if we should split it into row-gap and column-gap but we can cross that bridge if we get a request for it so gap works for me.
|
|
||
| await page.setContent( | ||
| ` | ||
| <ion-gallery style="--internal-gallery-columns: 2;"> |
There was a problem hiding this comment.
Overriding the internal CSS variable for columns should have no effect since the columns property takes priority.
| // This should match the default columns defined by the gallery component. | ||
| // It is hardcoded here instead of grabbing the value from the gallery so | ||
| // that changing it there without updating it here will break the tests. | ||
| const DEFAULT_COLUMNS_BY_BREAKPOINT = { |
There was a problem hiding this comment.
I chose to define these here to catch any changes in the component but I can pull them from there if we want.
There was a problem hiding this comment.
I would prefer getting them from gallery for a true source of truth.
| warningSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('should properly set columns for the md breakpoint but fallback to the default columns for all others when the columns property is set to an object with one valid breakpoint and the rest invalid', () => { |
There was a problem hiding this comment.
I decided to accept the valid breakpoint value and fallback for all the invalid ones, but I can change this behavior if something else is expected.
| // Reset the default margin for slotted elements so wrapper elements | ||
| // (such as <figure>) align properly with other gallery items. | ||
| ::slotted(*) { | ||
| @include margin(0); |
There was a problem hiding this comment.
This is required to be here because if the user wraps the img in something with default margin (like figure) it will not properly align the element, even if they override the margin on their side. I will have to document that the top-level item in a gallery should not have margin to avoid issues with this.
| * Normalize a columns value to a positive integer. | ||
| * Returns undefined when the input cannot be interpreted as a finite number. |
There was a problem hiding this comment.
| * Normalize a columns value to a positive integer. | |
| * Returns undefined when the input cannot be interpreted as a finite number. | |
| * Normalize columns value to a positive integer. | |
| * Returns `undefined` when the input cannot be interpreted as a finite number. |
| printIonWarning( | ||
| `[ion-gallery] - Invalid "columns" value (${JSON.stringify( | ||
| columns | ||
| )}). Expected a positive integer or breakpoint map object (e.g. { xs: 2, md: 4 }). Falling back to default responsive columns.`, |
There was a problem hiding this comment.
I wonder if it would be beneficial to display what the default responsive columns are so the dev can see it.
| const columnsStr = styles.getPropertyValue('--internal-gallery-columns'); | ||
| // Fallback to 2 columns for masonry calculations when the resolved | ||
| // --internal-gallery-columns CSS value is missing or unparsable. | ||
| const columns = parseInt(columnsStr, 10) || 2; |
There was a problem hiding this comment.
Do you think themes would want to define the fallback value instead of using 2?
| * placed in the DOM. When `best-fit`, items are positioned under the column | ||
| * with the most available space. | ||
| */ | ||
| @Prop({ reflect: true }) order: 'sequential' | 'best-fit' = 'sequential'; |
There was a problem hiding this comment.
Let's give a warning if dev uses layout="uniform with order.
| @@ -0,0 +1,64 @@ | |||
| @import "../../themes/native/native.globals"; | |||
There was a problem hiding this comment.
Since this is a new component, let's use @use and only import the needed mixins since @import is deprecated and it would lessen the work for Modular Ionic.
There was a problem hiding this comment.
The background is turning transparent because the content is too long. You'll need to adjust the viewport. I would recommend doing what I did with the badges in ionic-modular.
There was a problem hiding this comment.
The background is turning transparent because the content is too long. You'll need to adjust the viewport. I would recommend doing what I did with the badges in ionic-modular.
There was a problem hiding this comment.
The background is turning transparent because the content is too long. You'll need to adjust the viewport. I would recommend doing what I did with the badges in ionic-modular.
There was a problem hiding this comment.
The background is turning transparent because the content is too long. You'll need to adjust the viewport. I would recommend doing what I did with the badges in ionic-modular. There seems to be quite a lot of screenshots like this so my comment goes to those as well.
There was a problem hiding this comment.
The background is turning transparent because the content is too long. You'll need to adjust the viewport. I would recommend doing what I did with the badges in ionic-modular.
Issue number: internal
What is the current behavior?
Developers who want to use a masonry layout must rely on third-party solutions or implement their own.
What is the new behavior?
Adds a new
ion-gallerycomponent.Features
layoutproperty:uniform- evenly sized grid rowsmasonry- stacked masonry layoutorderproperty (masonryonly):sequential- preserves DOM orderbest-fit- places items in the shortest columncolumnsproperty:xs,sm,md,lg,xl,xxl)Test Coverage
columnsfallback and normalization caseslayoutwatcher, masonry scheduling, and load-event behaviororderplacement logic (sequentialandbest-fit)Does this introduce a breaking change?
Other information
Basic Preview
Layout Preview
Dev build:
8.8.6-dev.11777668103.132817bd