marcojakob / dart-dnd

Drag and Drop for Dart web apps with mouse and touch support.
https://code.makery.ch/library/dart-drag-and-drop/
MIT License
135 stars 86 forks source link

Add a class to Dropzones on dragStart? #5

Closed mdrx-io closed 10 years ago

mdrx-io commented 10 years ago

Please correct me if you've already built in this feature to the API in some form. But I would like to be able to add a class to acceptable Dropzones for a Draggable on dragStart. The goal being to give the user hints as to where she might be able to drop a Draggable (like a border-color modification around the Dropzone element).

marcojakob commented 10 years ago

It isn't built in because the Dropzone doesn't have a reference to all possible Draggables.

But you can do it by listening to the onDragStart and onDragEnd events:

Draggable draggable = new Draggable(draggableElements, 
    avatarHandler: new AvatarHandler.clone());
Dropzone dropzone = new Dropzone(dropzoneElements);

// Add class when dragging starts and remove it when dragging ends.
draggable.onDragStart.listen((_) {
  dropzoneElements.classes.add('drop-here');
});

draggable.onDragEnd.listen((_) {
  dropzoneElements.classes.remove('drop-here');
});