neodrag
neodrag copied to clipboard
Angular support
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);
}
}
}
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
I've added Angular integration via #129 and I'm happy to maintain the Angular side of things.