Skip to content

Commit

Permalink
Introduce Events feature, bump version to 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisameling committed Sep 16, 2020
1 parent bbf5b1e commit c92672d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
30 changes: 29 additions & 1 deletion README.md
Expand Up @@ -12,7 +12,7 @@ Install the library with the following commands:

`npm install --save muuri muuri-angular`

## Usage
## Basic Usage

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

Expand Down Expand Up @@ -79,6 +79,34 @@ export class AppComponent {
}
```

## Advanced usage

### Events

Muuri exposes many [events](https://github.com/haltu/muuri#grid-events) that you can subscribe to. You can get the `Grid` object as follows:

`app.component.html`

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

`app.component.ts`

```TypeScript
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);
});
}
```

## 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.
Expand Down
2 changes: 1 addition & 1 deletion projects/muuri-angular/package.json
Expand Up @@ -4,7 +4,7 @@
"author": {
"name": "Dennis Ameling"
},
"version": "0.0.6",
"version": "0.1.0",
"peerDependencies": {
"@angular/common": ">=9.0.0",
"@angular/core": ">=9.0.0",
Expand Down
16 changes: 9 additions & 7 deletions projects/muuri-angular/src/lib/muuri-grid.directive.ts
@@ -1,12 +1,13 @@
import { Directive, ElementRef, OnDestroy, OnInit, Input } from '@angular/core';
import { Directive, ElementRef, OnDestroy, OnInit, Input, Output, EventEmitter } from '@angular/core';
import Grid, { GridOptions } from 'muuri';

@Directive({
selector: '[muuriGrid]'
})
export class MuuriGridDirective implements OnInit, OnDestroy {
@Input() config: GridOptions;
layout: Grid;
@Output() gridCreated: EventEmitter<Grid> = new EventEmitter();
gridObject?: Grid;

constructor(private elRef: ElementRef) {}

Expand All @@ -18,23 +19,24 @@ export class MuuriGridDirective implements OnInit, OnDestroy {
* Initialize the grid.
*/
init(grid: ElementRef): void {
this.layout = new Grid(grid.nativeElement, this.config);
this.gridObject = new Grid(grid.nativeElement, this.config);
this.gridCreated.emit(this.gridObject);
}

/**
* Add a new item to the grid.
*/
addItem(item: ElementRef): void {
this.layout.add(item.nativeElement);
this.gridObject.add(item.nativeElement);
}

destroyLayout(): void {
this.layout.destroy();
this.layout = null;
this.gridObject.destroy();
this.gridObject = null;
}

refresh(): void {
this.layout.refreshItems();
this.gridObject.refreshItems();
}

ngOnDestroy(): void {
Expand Down

0 comments on commit c92672d

Please sign in to comment.