Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: DropZones support horizontal direction #520

Open
abird opened this issue Jun 25, 2024 · 3 comments
Open

Feature request: DropZones support horizontal direction #520

abird opened this issue Jun 25, 2024 · 3 comments

Comments

@abird
Copy link

abird commented Jun 25, 2024

I'm developing a Layout component that positions subcomponents horizontally and supports flex "justify-content" and "align-items." The rendering portion works great, but editing only supports adding and displaying components vertically. The underlying "dnd" library supports a horizontal direction.
It would be great if DropZone allowed specifying a horizontal direction. Support for flex positioning would be icing on the cake.

@chrisvxd
Copy link
Member

Hi @abird - I suspect this will be resolve as part of #123 or #455. I'll leave it open for tracking purposes.

@abird
Copy link
Author

abird commented Jul 30, 2024

I found a solution that works great for me. I've found that if you pass a "style" prop (undocumented) to DropZone, it's passed on to the container for all of the draggable children. So I do this:

<DropZone zone="layout" style={{ display: 'flex', justifyContent: justify }} />

This lays out the children horizontally within the drop zone. I can specify any justify-content value, such as 'space-between'.

However, when dropping onto the drop zone, it still does it vertically, so I patched Puck to fix this. The file is: node_modules/@measured/puck/dist/index.js. For my version, the line number is 31374 where I replaced direction: "vertical" with direction: style?.display === "flex" ? "horizontal" : "vertical". So when flex display is specified, it uses a horizontal drag and drop.

Patching an NPM module can be tricky, so I use "patch-package" to manage my patch. (See https://scottspence.com/posts/patching-packages or https://www.npmjs.com/package/patch-package)

The patch works for editing, but not when rendering. The solution that works for me is to wrap the <DropZone .../> in a div with { display: 'flex', justifyContent: justify }.

@chrisvxd
Copy link
Member

chrisvxd commented Aug 6, 2024

Nice solution @abird!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants