Git Product home page Git Product logo

muuri-angular's Introduction

muuri-angular

npm version

Angular wrapper around the Muuri JavaScript library. Only supported on Angular 9 and newer versions.

Do you have any requests or improvements? Feel free to create an issue or PR.

Getting started

Install the library with the following commands:

npm install --save muuri muuri-angular

Basic Usage

Add MuuriModule as an import to your app.module.ts:

import { MuuriModule } from 'muuri-angular';

@NgModule({
  declarations: [...],
  imports: [
    ...
    MuuriModule
  ],
  providers: [],
  bootstrap: [...]
})
export class AppModule { }

app.component.html

<button id="add-item-button" (click)="addToGrid()">+ Add new block</button>
<br><br>
<div #grid class="grid" muuriGrid [config]="layoutConfig">
    <div class="grid-item" muuriGridItem *ngFor="let item of blockItems">
        <div class="grid-item-content">
            {{ item }}
        </div>
    </div>
</div>

app.component.ts

import { Component } from '@angular/core';
import { GridOptions } from 'muuri';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
    blockItems: string[] = ['test', 'test2'];

    // Add any options you'd like to set here
    public layoutConfig: GridOptions = {
        items: [],
        layoutOnInit: false,
        dragEnabled: true,
        layout: {
            fillGaps: true,
            horizontal: false,
            alignRight: false,
            alignBottom: false,
            rounding: true
        }
    };

    addToGrid() {
        this.blockItems.push('hello');
    }
}

Advanced usage

Events

Muuri exposes many events that you can subscribe to. You can get the Grid object as follows:

app.component.html

<div muuriGrid (gridCreated)="onGridCreated($event)"></div>

app.component.ts

import Grid from 'muuri';

onGridCreated(grid: Grid) {
  /**
   * Now you can do everything you want with the Grid object,
   * like subcribing to Muuri's events
   */
  grid.on('add', function (items) {
    console.log(items);
  });
}

You can also get a grid item when it is created:

app.component.html

<div muuriGridItem (itemCreated)="onItemCreated($event)"></div>

app.component.ts

import Item from 'muuri';

onItemCreated(item: Item) {
  // Now you can do anything you want with the grid item
}

Contributing

If you want to help developing this library, please do the following to set up your local environment:

  • Set up a project that uses muuri-angular as a dependency.
  • Clone this repo (muuri-angular).
  • Run npm install.
  • Run npm run build:ivy. This will build an Ivy-compatible library that you can use in Angular 9+ projects locally.
    • If you're still using Angular 8 or lower in your project, run npm run build:prod instead. This will use Angular's legacy View Engine to build the library.
  • Run cd dist/muuri-angular.
  • Run npm link.
  • In your project, run npm link muuri-angular. Your project will now use the local muuri-angular code.
  • Run npm run build:ivy -- --watch so that the library gets rebuilt on every code change 😃

muuri-angular's People

Contributors

dennisameling avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

muuri-angular's Issues

Issue with horizontal alignment of items

Hi

I am facing a problem don't know if its an issue or something at my end, let say I have 10 items and showing 5 item in each row, in this case when we have only single item in third row, item is automatically getting aligned to the right but as soon as soon as we add one more item alignment gets corrected and getting aligned to the left.

Layout config is set to default.

Observation:
if I set layout.alignRight = true, then its working correct for the scenario

How can I sort the grid items by an id in Angular ?

I have built a dashboard in Angular, in which I want to use muuri to move the widgets of my dashboard (always the same size rectangles).

My problem now is that I can't get the widgets to appear in a fixed order. After each loading of the page I have a different order.

It would be great if this could be done somehow from the outside (Dashboard Component) to the Murri Grid Element (Widget Component).

Overplapping items

When I use data from a parent component or a photo without a precisely set height, the items overlap. If I change the width of the window, the height will be recalculated and everything will fall into place

image

Feature Request: Unit Test

While Muuri is an upstream project and should be responsible for it's own unit test I believe that integration test would still be very valuable.

Additionally a sample project may be useful for developers to be able to quickly test changes they make in a live environment.

Feature Request: Sort and Filter

Muuri supports sort and filter which provide animations. While it is preferred that Angular handle the order of the DOM elements and what is showing and what not it is unclear that these animations will work with Angular handling this responsibility.

It would be great if this could be tested, updated to work with angular handling the DOM, and demoed.

Additionally it would be great if we could somehow treeshake away any unused methods like .sort() or .filter() in Muuri.
This would likely require PR upstream to Muuri but it would still be great to not ship code that is never used.

Container element must be an existing DOM element.

After copying demo code - getting this error on Angular CLI: 9.0.2, Node: 10.15.0

core.js:5845 ERROR Error: Container element must be an existing DOM element.
    at new Grid (muuri.module.js:7346)
    at MuuriGridDirective.init (muuri-angular.js:16)
    at MuuriGridDirective.ngOnInit (muuri-angular.js:10)
    at callHook (core.js:3909)
    at callHooks (core.js:3873)
    at executeInitAndCheckHooks (core.js:3814)
    at selectIndexInternal (core.js:9530)
    at Module.ɵɵadvance (core.js:9491)
    at DashboardComponent_Template (dashboard.component.html:8)
    at executeTemplate (core.js:11858)
    at refreshView (core.js:11705)
    at refreshComponent (core.js:13145)
    at refreshChildComponents (core.js:11436)
    at refreshView (core.js:11757)
    at refreshDynamicEmbeddedViews (core.js:13070)
    at refreshView (core.js:11728)

Feature Request: Attribute binding to individual properties

As this is currently written an entire GridOptions must be provided.
This doesn't fall in line with other Angular libraries like Angular Material where options are bound on individual attributes.

I would like to see something like this.

<div muuriGrid fillGaps rounding [horizontal]="false">
    <div *ngFor="let item of blockItems" muuriGridItem>
        <div>
            {{ item }}
        </div>
    </div>
</div>

These would also need to support being updated after the grid is created in the event that a property binding is used.

bug dragSort => grid array

If I drag an item to another grid, the ngDestroy of MuuriGridItemDirective will have a wrong MuuriGridDirective:
ngOnDestroy() { this.tileGrid.removeItem(this.elRef); }

Current workaround:

 @ViewChildren(MuuriGridDirective) directives?: QueryList< MuuriGridDirective >;
  @ViewChildren(MuuriGridItemDirective) contentChildren?: QueryList< MuuriGridItemDirective >;
  private lastDragTargetGrid: Grid;
  private lastDragElementItem: HTMLElement | undefined;

grid.on('beforeSend',` ({ item, toGrid }) => {
      this.lastDragElementItem = item.getElement();
      this.lastDragTargetGrid = toGrid;
    });

grid.on('dragEnd', (item, event) => {
        const targetDirective = this.directives?.find(d => d.gridObject === this.lastDragTargetGrid);
        if (targetDirective) {
          const targetItemDirective = this.contentChildren?.find(child => child['elRef'].nativeElement === this.lastDragElementItem);
          if (targetItemDirective) {
            targetItemDirective['tileGrid'] = targetDirective;
          }
        }
    });

I change the internal tileGrid of MuuriGridItemDirective with the new target MuuriGridDirective.

The error occurs only when you leave oder change the page-routing. Only then is ngOnDestroy () called.

Dynamically remove an element

When i try add an element it works great. Unfortunately, when i try to remove an element. it's didn't dynamically removed. it's leave a space over there.
Screen Shot 2020-09-16 at 12 44 09 PM

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.