Gallery Grid For Angular And IonicGallery Grid For Angular And Ionic
Responsive gallery for Angular v2/v4 and Ionic v2/v3Gallery Grid For Angular And Ionic
Responsive gallery for Angular v2/v4 and Ionic v2/v3
Overview
Gallery Grid for Angular v2/v4 and Ionic v2/v3Â is the component for integrating responsive gallery into you app (demo)
Features
- Define rules by which images will be broken to rows inside the galleryÂ
- Define spacing between imagesÂ
- Implement custom adapter class that would adapt your custom component within gallery
Instructions
Installation:
- Download the zip file and unzip it;
- Copy files fromÂ
mama-gallery-grid/src and paste them intoÂsrc folder within your project; - Import component inÂ
app.module.ts:Â
import { MamaGalleryGrid } from 'path/to/mama-gallery-grid';
...
@NgModule({
declarations: [
...,
MamaGalleryGrid
],
...
})
export class AppModule {}
Usage:
In your view, add:
<!-- Other content -->
<mama-gallery-grid>
<img *ngFor="let image of images"
[src]="image.url"
[attr.data-image-width]="image.width"
[attr.data-image-height]="image.height">
</mama-gallery-grid>
<!-- Other content -->
Options:
[breakingRules] (optional array in formatÂ{ maxWidth: number, maxColumns: number }[]) - rules by which images will be broken to rows inside the gallery;maxWidth - Width of the gallery component;maxColumns - Number of columns in the gallery when gallery width is lower than maxWidth;
Default value:
[
{
maxWidth: 480,
maxColumns: 1
},
{
maxWidth: 1024,
maxColumns: 2
},
{
maxWidth: Number.MAX_VALUE,
maxColumns: 3
}
]
[spacing]Â (optional number, default is 0) - spacing between images;- Content elements/images need to haveÂ
data-image-width andÂdata-image-height attributes with values set to original dimensions of an image.
Currently gallery works same with any HTML element (works with any element that controls sizing through css properties). If you want to implement custom HTML element inside the gallery, do following steps:
- ImportÂ
ItemAdapter,ÂItemStylingOptions andÂregisterItemAdapter fromÂmama-gallery-grid; - Create classÂ
MyItemAdapter that implementsÂItemAdapter; - Add instance ofÂ
MyItemAdapter toÂregisterItemAdapter;
Sample:
import {
ItemAdapter,
ItemStylingOptions,
registerItemAdapter
} from 'path/to/mama-gallery-grid';
class MyItemAdapter implements ItemAdapter {
styleElement(element:any, options:ItemStylingOptions) {
element.widthProperty = `${options.width}px`;
element.heightProperty = `${options.height}px`;
element.marginTopProperty = `${options.marginTop}px`;
element.marginLeftProperty = `${options.marginLeft}px`;
element.style.display = 'block';
element.style.float = 'left';
}
}
registerItemAdapter('my-custom-element', new MyItemAdapter());








