Skip to content

Commit

Permalink
Enable removing items, bump version to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisameling committed Sep 30, 2020
1 parent e5d1ee1 commit 56162d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion projects/muuri-angular/package.json
Expand Up @@ -4,7 +4,7 @@
"author": {
"name": "Dennis Ameling"
},
"version": "0.1.1",
"version": "0.2.0",
"peerDependencies": {
"@angular/common": ">=9.0.0",
"@angular/core": ">=9.0.0",
Expand Down
8 changes: 6 additions & 2 deletions projects/muuri-angular/src/lib/muuri-grid-item.directive.ts
@@ -1,15 +1,19 @@
import { Directive, ElementRef, Host, OnInit } from '@angular/core';
import { Directive, ElementRef, Host, OnDestroy, OnInit } from '@angular/core';
import { MuuriGridDirective } from './muuri-grid.directive';

@Directive({
selector: '[muuriGridItem]'
})
export class MuuriGridItemDirective implements OnInit {
export class MuuriGridItemDirective implements OnInit, OnDestroy {
constructor(@Host() private tileGrid: MuuriGridDirective, private elRef: ElementRef) {}

ngOnInit(): void {
this.tileGrid.addItem(this.elRef);
// Force refresh the grid to prevent overlapping items
this.tileGrid.refresh();
}

ngOnDestroy(): void {
this.tileGrid.removeItem(this.elRef);
}
}
10 changes: 10 additions & 0 deletions projects/muuri-angular/src/lib/muuri-grid.directive.ts
Expand Up @@ -42,4 +42,14 @@ export class MuuriGridDirective implements OnInit, OnDestroy {
ngOnDestroy(): void {
this.destroyLayout();
}

/**
* Remove an item from the grid.
*/
removeItem(item: ElementRef): void {
const gridItem = this.gridObject.getItem(item.nativeElement);
this.gridObject.remove([gridItem], {
layout: true
});
}
}

0 comments on commit 56162d9

Please sign in to comment.