Giter Site home page Giter Site logo

bartholomej / ngx-masonry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wynfred/ngx-masonry

0.0 2.0 0.0 9 KB

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

JavaScript 12.51% TypeScript 87.49%

ngx-masonry's Introduction

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)

If I have the time I will look into further improvements, but please do not expect support as I don't have the time for that.

npm version

Installation

npm install ngx-masonry --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

NOTE: Will throw error if global imagesLoaded not available.

Delay adding brick until all images in brick are loaded. To activate imagesLoaded set useImagesLoaded to true.

<ngx-masonry [useImagesLoaded]="true"></ngx-masonry>

index.html:

<script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.min.js"></script>

check the ImagesLoaded website for the latest version.

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 is it rendering the tiles twice in prod? This could be the case because of angulars 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/gethinoakes/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

ngx-masonry's People

Contributors

erikhofer avatar

Watchers

James Cloos avatar BART! avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.