Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-masonry

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-masonry

Angular Module for displaying a feed of items in a masonry layout using https://github.com/desandro/masonry

  • 9.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-6.02%
Maintainers
1
Weekly downloads
 
Created
Source

Angular Module for displaying a feed of items in a masonry layout using https://github.com/desandro/masonry

This package was originally a fork from https://github.com/jelgblad/angular2-masonry to allow it to work with newer versions of Angular.

This updated version is also compatible with Angular Universal server side rendering (SSR)

npm version

V9 beta

  • update the version number to match angular version
  • masonry-layout is now a peerDependency, not a dependency
  • expose reloadItems() function
  • remove imagesLoaded and support images loading by default

Installation

npm install ngx-masonry masonry-layout --save

If you're using SystemJS add ngx-masonry and masonry-layout to your configuration:

packages: {
  "ngx-masonry": { "defaultExtension": "js", "main": "index" }
},
map: {
  "ngx-masonry": "node_modules/ngx-masonry",
  "masonry-layout": "node_modules/masonry-layout/dist/masonry.pkgd.js"
}

Usage

Import NgxMasonryModule into your app's modules:

import { NgxMasonryModule } from 'ngx-masonry';

@NgModule({
  imports: [
    NgxMasonryModule
  ]
})
@Component({
  selector: 'my-component',
  template: `
     <ngx-masonry>
       <div ngxMasonryItem class="masonry-item" *ngFor="let item of masonryItems">
        {{item.title}}
      </div>
     </ngx-masonry>
     `,
  styles: [
    `
       .masonry-item { width: 200px; }
     `
  ]
})
class MyComponent {
  masonryItems = [
    { title: 'item 1' },
    { title: 'item 2' },
    { title: 'item 3' },
    { title: 'item 4' },
    { title: 'item 5' },
    { title: 'item 6' }
  ];
}

Configuration

Options

Read about Masonry options here: Masonry Options

The options-attribute takes an object with the following properties:

  • itemSelector: string;
  • columnWidth: number | string;
  • gutter: number;
  • percentPosition: boolean;
  • stamp: string;
  • fitWidth: boolean;
  • originLeft: boolean;
  • originTop: boolean;
  • containerStyle: string;
  • transitionDuration: string;
  • resize: boolean;
  • initLayout: boolean;
  • horizontalOrder: boolean;
Examples

Inline object:

<ngx-masonry [options]="{ transitionDuration: '0.8s' }"></ngx-masonry>

From parent component:

import { NgxMasonryOptions } from 'ngx-masonry';

public myOptions: MasonryOptions = {
  transitionDuration: '0.8s'
};
<ngx-masonry [options]="myOptions"></ngx-masonry>

imagesLoaded

imagesLoaded is removed in V9. masonry item will support image by default

updateLayout

ngx-masonry has an input property, updateLayout, which accepts a boolean and will call masonry's layout() method on a change. It ignores the first change when the component loads.

<ngx-masonry [updateLayout]="updateMasonryLayout"></ngx-masonry>

When updateMasonryLayout is updated, the layout() method will be called.

Events

layoutComplete: EventEmitter<any[]>

Triggered after a layout and all positioning transitions have completed.

http://masonry.desandro.com/events.html#layoutcomplete

removeComplete: EventEmitter<any[]>

Triggered after an item element has been removed.

http://masonry.desandro.com/events.html#removecomplete

FAQ

  • Why does masonry have wrong order?

The new item is always appended to the list because there is no "insert" function supported in masonry-layout. If the order changed and you want to update the order of items, use reloadItems()

// get reference
@ViewChild(NgxMasonryComponent, {static: false}) masonry: NgxMasonryComponent;

// after the order of items has changed
this.masonry.reloadItems();
this.masonry.layout();
  • Why is it rendering the tiles twice in prod?

This could be the case because of angular build optimizer. A currently working "workaround" is disabling the build-optimizer in the angular.json file.

{
  "projects": {
    "my-project": {
      "architect": {
        "build": {
            "production": {
              "buildOptimizer": false
            }
          }
        }
    }
  }
}

For more information refer to this issue:
https://github.com/wynfred/ngx-masonry/issues/8

Examples

<ngx-masonry (layoutComplete)="doStuff($event)" (removeComplete)="doOtherStuff($event)"></ngx-masonry>

Demo

This repository contains a working app using ngx-masonry as a child module, not as an npm package. You can go to the demo respository to view an app that uses it as an npm package.

View a live demo here

Keywords

FAQs

Package last updated on 13 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc