day8 / re-com

A ClojureScript library of reusable components for Reagent
https://re-com.day8.com.au
MIT License
797 stars 146 forks source link

Sortable or Draggable Components #114

Open Conaws opened 7 years ago

Conaws commented 7 years ago

Hey there, It took me a while to figure out how to make a sortable list with reagent, but having done so, I felt like it might be useful to other folks as a higher-order component.

I love this library, so figured I'd ask -- if I clean this up a bit, would you be at all interested in a pull request to add this.

drag

code is here

https://gist.github.com/0e8f6860c57be50f5edf7c0c636d478d

mike-thompson-day8 commented 7 years ago

Are you suggesting that we add n example page to the re-com demo, showing the technique. (I'm not seeing a general component ... but checking, in case I missed something)

Conaws commented 7 years ago

The example I wrote isn't general, but if you're interested in a general one I can re-write it. I wanted to check in before though so I could A) make sure you were interested and B) hear your preferred API.

What I'm thinking is that a "sortable list" component would have the following

list (atom vector)

on-reorder (fn vector -> nil) The function to fire with the new ordered items

note -- the drag/drop api seems a little wonky, and sometimes dropping with this component doesn't seem to fire -- so might be worth asking for a spec, or at least a predicate for testing that all items in the new vector are the items -- that way this doesn't fire when you still have the placeholder item in the list.

placeholder (opt component) or placeholder-class (opt string)

item-class (opt string)

list-class (opt string)

during-drag-class (opt string)

Does that make sense? JQuery sortable is a thing, so figure we should have some kind of equivalent

On Fri, Oct 28, 2016 at 5:09 PM, Mike Thompson notifications@github.com wrote:

Are you suggesting that we add n example page to the re-com demo, showing the technique. (I'm not seeing a general component ... but checking, in case I missed something)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Day8/re-com/issues/114#issuecomment-256899440, or mute the thread https://github.com/notifications/unsubscribe-auth/ACljr1o2J5CF9sQfNPXcMhduScHbRWWVks5q4d7ugaJpZM4KiMb- .

Conor White-Sullivan 347-216-0173 @Conaw http://twitter.com/conaw

Good tests kill flawed theories, we remain alive to guess again. ~ Karl Popper

danielcompton commented 7 years ago

I'll leave the decision on whether to include this to others, but I've got a few notes on the current implementation:

I'd recommend waiting to see whether this will make it into re-com before going too much further as I wouldn't want you to do extra work. Thanks! This looks nice 👍.

CaptainLexington commented 7 years ago

Is there any word on whether the maintainers would like to incorporate functionality like this if it were available? I need my app to do this anyway so I have to do it one way or another. I'd be happy to contribute work to this PR if it would be helpful to anyone.