r/reactjs • u/Alngaawy • Oct 09 '21
How to control the elements with react.js like this video ?
171
u/Lil_Jiggly47 Oct 09 '21
To complex drag and drop like in the video i use "react-beautiful-dnd", it's incredible usefull
46
u/straightouttaireland Oct 09 '21
Until you want nested scrolling 😭
30
u/Kyle772 Oct 09 '21
Are you me?
18
u/straightouttaireland Oct 09 '21
And hundreds of others unfortunately!
6
u/iJubag Oct 09 '21
Are there any specific advantages to nested scrolling over just having expandable containers? I’ve always found it to be kind of annoying from a users perspective
13
u/straightouttaireland Oct 09 '21
Having a sticky header per column. Think of the trello app... imagine if that didn't allowed nested scrolling where you can scrolling vertically in a column and also drag a card horizontally.
4
5
3
3
u/kylemh Oct 10 '21
Doesn't nested scrolling work fine? I thought `react-beautiful-dnd` is used for both Trello and Jira.
3
u/straightouttaireland Oct 10 '21
It may be used, but they must have added this feature privately as the repo hasn't been maintained for years.
1
49
u/maddy_0120 Oct 09 '21 edited Oct 10 '21
I blame Dribble for this. All these new UX designers add a lot of unnecessary animations thinking it will look cool on their portfolio.
Then, the clients be like I want that!. It's a coding nightmare.
9
u/amarbuga Oct 09 '21
But the biggest pain is the performance we used framer motion and the performance hit was crazy .
5
u/The5thElephant Oct 10 '21
For in/out animations like this (these are overkill) it’s quite easy to implement in React/Vue with a CSS tool my brother and I built: AnimXYZ.com and the performance is generally quite good thanks to hardware acceleration and not relying on JS request animation frame complexity.
We automatically turn them off if a user has reduced-motion preferences turned on in their OS or browser settings, and we generally suggest using animations subtly to inform the user although there are times it’s nice to have some flashy eye catching motion.
5
u/kecupochren Oct 10 '21
But that's what Dribbble is about. Showcase. For real world, UX optimized solutions there is Behance
-3
Oct 09 '21
Bruh did you try to code drag and drop and fail? What kind of kanban board from 100 years ago doesn't have DnD?
2
u/maddy_0120 Oct 10 '21
That's not what I'm talking about. I just said that some designers like to add unnecessary animations to their designs.
I did say it's a coding nightmare, but that's just my opinion, cause I'm terrible at CCS.
-1
Oct 10 '21
Ok but what does those unnecessary animations have to do with this video of a fairly average drag and drop kanban board?
3
u/maddy_0120 Oct 10 '21
It's not the drag and drop that's the problem. Its everything else in the video.
0
12
u/guyariely Oct 09 '21
for the elements entering the screen - you can use the css animation property and keyframes (animate the transform and opacity).
for reordering the items in the list - react-beautiful-dnd is your best bet
16
u/nahtnam Oct 09 '21
https://dndkit.com/ this is an alternative to react-beautiful-dnd
3
1
1
u/plastix3000 Oct 10 '21
Too many people trying to use the abbreviation 'dnd' and I can't keep up.
Do not disturb (original dictionary definition)
Dungeons and dragons (the only true dnd)
Dan and Dave (how Reddit send to refer to the hack showrunners from game of thrones)
This is the first time I've seen drag and drop
15
u/AcidNoX Oct 09 '21
Most of this can be fairly easily achieved with framer-motion.
There are several different types of animation here so no one is going to be able to answer you question in a single comment.
9
Oct 09 '21
Framer motion is a beast of a library for animations.
How to take care of the drag and reposition though? Framer does allow dragging. But repositioning perfectly into a grid?
4
u/AcidNoX Oct 09 '21
AnimateSharedLayout should handle the dnd
1
Oct 09 '21
Yeah but what about perfectly fitting into the place on its own (snapping)? Can Animate shared layout handle that too? Maybe (for this design), all I would need a flexbox container, and then allow dragging of the boxes.
Am I right?
5
u/AcidNoX Oct 09 '21
Essentially the cards would be represented in state as a 2D array. On drop, you calculate the new position in that 2D array and, as long as the element has the same “layoutId” framer handles the animation
2
Oct 09 '21
Thanks man. Will try this one out.
How do you suggest recalculating the new position? Mouse events? Framer motion drag event?
2
u/AcidNoX Oct 09 '21
Yeah I’d use onDragEnd from framer
2
Oct 09 '21
Got it.
2
u/AcidNoX Oct 10 '21
I spent a couple of hours putting a demo together. It turned out to be not quite as easy as I hoped as apparently framer does not yet support "onDragOver" events (https://github.com/framer/motion/issues/538 ).
This meant I had to add some extra code to determine which column the card is intersecting, etc.
Anywho, here's the link: https://codesandbox.io/s/silly-hawking-7jx8w
This is purely a PoC - the code is nowhere near production-ready and I certainly wasn't adhering to best practices etc so please excuse the mess.
Should give you an idea of how you might achieve it though :)
1
Oct 28 '21
Hey man, good news!
Framer Motion 5 comes with reordering!!
Check this out: https://www.framer.com/docs/reorder/
1
4
3
3
2
u/bleedeleventh Oct 10 '21
I use interact.js for drag and drop events. it has tons of interactive events and might help you
3
2
1
u/kiesoma Oct 10 '21
For the animations, I normally use react-reveal.
Not sure about the drag and drop though :(
1
1
1
u/Curtis017 Oct 10 '21
Lots of people recommending ui frameworks or libraries. Not sure of your entire use case, but I’ll throw out that this is “technically“ a built in functionality within most browsers. Just use the “draggable” attribute on the element:
199
u/Snapstromegon Oct 09 '21
This animation is great for a trailer video, but in my opinion should never under any circumstances should happen on a real page.
Animation should always serve a purpose to either give direction, feedback or pull focus. And you can't focus on everything. And it's not even like it's giving you one direction to tell you "start looking here", but is jumping all around and has seven different movement directions/types, often multiple in the same container.
I often go by the rule of "if it's hard to animate, you shouldn't do it in the first place" (this refers to the complexity of the constuct to animate, not the code).