TahaSh / swapy

✨ A framework-agnostic tool that converts any layout into a drag-to-swap one with just a few lines of code https://swapy.tahazsh.com/
MIT License
5.86k stars 114 forks source link

[Feature Request] Add `onBeforeSwap` event #38

Open Tragio opened 1 month ago

Tragio commented 1 month ago

Hi @TahaSh 👋

Thank you for the awesome work. 🚀

Would be awesome to add an onBeforeSwap event. In my use case, I want to move the card only when they click on a specific icon.

The most generic way I thought and that can also help in other implementations of other people's use is to have an onBeforeSwap event. For my use case, I can check in the event if they clicked the icon or not, in that case, I can just return.

Thank you very much 🙏

TahaSh commented 1 month ago

Hi @Tragio, thanks! Does your use case require the cards to be draggable and then check if they can be swapped on drop, or you need to disable dragging completely on some condition?

If it's the latter, you can use swapy.enable(false) to disable it and then swapy.enable(true) to enable it. If it's the former, let me know, and I'll add it 😄

wtfmozart commented 1 month ago

@TahaSh my usecase requires the first scenario you described.