auto-animate icon indicating copy to clipboard operation
auto-animate copied to clipboard

Angular Docs

Open danielehrhardt opened this issue 3 years ago • 5 comments

Can this lib work in Angular? Maybe i will add a Pull Request for Docs for Angular or a Wrapper what do you think?

danielehrhardt avatar May 30 '22 09:05 danielehrhardt

That would be great. We don't plan to touch angular ourselves so it needs to be a submission from someone like yourself anyway :)

justin-schroeder avatar May 30 '22 12:05 justin-schroeder

I also came looking for Angular support :)

To be fair, the docs do say this:

You can use it with React, Vue, Svelte, or any other JavaScript application

That claim needs an asterisk ;).

But it shouldn't be impossible to create an auto-animate Angular directive @danielehrhardt

Waterstraal avatar Jun 06 '22 17:06 Waterstraal

I created a quick POC:

import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';
import autoAnimate, { AutoAnimateOptions, AutoAnimationPlugin } from '@formkit/auto-animate';

@Directive({
  selector: '[auto-animate]'
})
export class AutoAnimateDirective implements AfterViewInit {
  @Input() options: Partial<AutoAnimateOptions> | AutoAnimationPlugin = {}

  constructor(private el: ElementRef) {}

  ngAfterViewInit(): void {
    autoAnimate(this.el.nativeElement, this.options);
  }
}

Works like a charm:

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

@Component({
  selector: 'app-root',
  template: `
    <ul auto-animate [options]="{duration: 500}">
      <li *ngFor="let item of items">{{item}}</li>
    </ul>
    <button (click)="this.items.push('🍒 Cherry')">Add fruit</button>
  `
})
export class AppComponent {
  items: string[] = ['🍎 Apple', '🍌 Banana', '🍓 Strawberry'];
}

Waterstraal avatar Jun 06 '22 18:06 Waterstraal

I created a quick POC:

import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';
import autoAnimate, { AutoAnimateOptions, AutoAnimationPlugin } from '@formkit/auto-animate';

@Directive({
  selector: '[auto-animate]'
})
export class AutoAnimateDirective implements AfterViewInit {
  @Input() options: Partial<AutoAnimateOptions> | AutoAnimationPlugin = {}

  constructor(private el: ElementRef) {}

  ngAfterViewInit(): void {
    autoAnimate(this.el.nativeElement, this.options);
  }
}

Works like a charm:

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

@Component({
  selector: 'app-root',
  template: `
    <ul auto-animate [options]="{duration: 500}">
      <li *ngFor="let item of items">{{item}}</li>
    </ul>
    <button (click)="this.items.push('🍒 Cherry')">Add fruit</button>
  `
})
export class AppComponent {
  items: string[] = ['🍎 Apple', '🍌 Banana', '🍓 Strawberry'];
}

Wow Nice! Maybe you can create a Pull Request?

danielehrhardt avatar Jun 06 '22 19:06 danielehrhardt

Sorry for the delay, I just got around for it. I created a PR that add Angular support.

Waterstraal avatar Jun 14 '22 13:06 Waterstraal