Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular support #106

Open
eneajaho opened this issue Jan 13, 2023 · 2 comments · May be fixed by #129
Open

Angular support #106

eneajaho opened this issue Jan 13, 2023 · 2 comments · May be fixed by #129

Comments

@eneajaho
Copy link

Angular support is very easy to integrate using a directive:

import { Directive, ElementRef, inject, Input } from "@angular/core";
import { Draggable, DragOptions } from '@neodrag/vanilla';

@Directive({
    standalone: true,
    selector: "[draggable]"
})
export class DraggableDirective {
    #elementRef = inject(ElementRef);
    #dragInstance: Draggable | null = null;

    @Input('draggable') set dragOptions(dragOptions: DragOptions | undefined | null | "") {
        let options = dragOptions || {};
        
        if (this.#dragInstance) {
            this.#dragInstance.updateOptions(options);
        } else { // create new instance
            this.#dragInstance = new Draggable(this.#elementRef.nativeElement, options);
        }
    }
    
    ngOnDestroy() {
        this.#dragInstance?.destroy();
        this.#dragInstance = null;
    }
}

Usage:

@Component({
  selector: 'app-root',
  template: `
    <div draggable style="width: 100px">
      Drag me!
    </div>

    <!-- With options -->
    <div [draggable]="dragOptions" style="width: 100px">
      Drag me!
    </div>
  `
})
export class AppComponent {
  dragOptions: DragOptions = {
    axis: 'y',
    onDrag: (event) => {
      console.log(event);
    }
  }
}
@PuruVJ
Copy link
Owner

PuruVJ commented Jan 14, 2023

Adding a library itself isn't hard, it's adding the docs, and answering any angular integration questions. I'm not knowledgeable in angular and am not ready to undertake such a big task

If i get volunteers to maintain the angular side, I'm ready to add a @neodrag/angular

@nartc
Copy link

nartc commented Jun 28, 2023

I've added Angular integration via #129 and I'm happy to maintain the Angular side of things.

@nartc nartc linked a pull request Jun 28, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants