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

"Grid" drag and drop interactive layouts #14321

Closed
wants to merge 64 commits into from
Closed

Conversation

aptkingston
Copy link
Member

@aptkingston aptkingston commented Aug 5, 2024

Description

This PR adds a new way to lay out your components - a drag and drop grid system. This makes it easier, faster and more intuitive to design your screens.

I'd really appreciate it if you could give this a try on the feature branch - all feedback is welcome.
Some of these videos are now outdated - please use the feature branch for the most up to date code.

image

How to use grid layout

Grid layout can be used in 2 ways: either on your screen as a whole, or in any container.

To change your screen or container to grid layout, use the new action button setting setting:
image

Grid layout basics

Any components put inside a grid container or screen can be resized using anchors on all corners and sides:

Screen.Recording.2024-08-05.at.19.03.57.mov

They can be moved around by dragging:

Screen.Recording.2024-08-05.at.19.04.31.mov

Some components take up the full size that you specify, like the table in the videos above, but this doesn't make sense for all components. Take a button for example - you wouldn't want your button to ever be that size. Components like this instead are positioned inside the bounds you define, and can be aligned whatever way you want:

Screen.Recording.2024-08-05.at.19.06.28.mov

Designing for mobile

The biggest limitation of drag and drop layout systems (especially compared to Budibase's normal layout system) is the lack of responsiveness - i.e. they don't automatically work on mobile.

To solve this, the new grid layout system "remembers" the position and size of your components for both large (desktop/tablet) and small (mobile) previews. So to design a screen for mobile, just swap to the mobile preview and move your components around to design the screen as you want on mobile.

Here's a quick example of building a very basic screen:

Screen.Recording.2024-08-05.at.19.13.59.mov

A few other clarifications about how this feature works:

  • Grids have 12 columns, which are dynamically sized depending on the width of your component.
  • Grids have rows that are 24px tall - so the taller your grid is, the more rows you have.
  • Grid lines are only shown when resizing or dragging a component inside your grid.
  • There is a fixed 5px margin and 5px padding around all components to provide natural spacing and allow anchors to render properly.
  • You can overlap things without restrictions. Components rendered lower down your tree go on top.
  • You can nest grids inside grids as many times as you want. But should you?
  • Nothing can ever overflow outside the bounds you define. So yes you can make a form block that is 10px tall. Overflow will cause scrolling within the bounds of your component.
  • All components should appear with a sensible amount of rows and columns predetermined for you.
  • When used at a screen level, the screen width setting is still respected. If you want a full screen grid (ignoring the width of your nav) then use the "Max" width setting.

Addresses

For plugin authors

When adding a component inside grids, we use metadata defined in the manifest to determine how big a component should initially be, and what way it should be laid out.

The size key is used to define what size (in pixels) an instance of your component should be by default. Please use a reasonably small size here. If this is undefined, we will use 200x200. For our table component for example, we use:

"size": {
  "width": 600,
  "height": 400
},

The grid key defines how your component should be aligned when used inside a grid. There are 2 properties - hAlign for horizontal alignment and vAlign for vertical alignment. Each of these can be either start, center, end or stretch and behaves exactly like their CSS flexbox equivalents. The defaults are stretch horizontally and start vertically. These can be controlled by the end user in the settings bar rendered in the preview. The one exception to this is if you specify stretch for both. In that case, the user will not see the settings in the bar and the component will always fill the space, like for our table component.
Here's an example of how this metadata looks for our form block:

"grid": {
  "hAlign": "stretch",
  "vAlign": "start"
},

Other stuff

  • Fixed the Tag component which was completely broken and didn't have styles at all
  • Improve alignment of indicators when in the builder, and improve app preview styles and alignment which could be offset slightly

Launchcontrol

Added a new way to lay out your components - a drag and drop grid system. This makes it easier, faster and more intuitive to design your screens.

Feature branch env

Feature Branch Link

--grid-mobile-row-end,
round(up, calc(var(--default-height) / var(--row-size) + 1))
)
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm actually using CSS here to calculate default sizes and then round it to get a valid integer to use later for CSS grid column/row positions.

@@ -650,6 +664,7 @@
data-name={name}
data-icon={icon}
data-parent={$component.id}
use:gridLayout={gridMetadata}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the new metadata required to use this feature is handled by this new svelte action. This keeps it all nicely scoped inside one file and means we don't need to make this core Component file any more complicated than it already is.

@aptkingston aptkingston marked this pull request as draft August 6, 2024 06:59
@aptkingston aptkingston marked this pull request as ready for review August 6, 2024 10:49
@poirazis
Copy link
Contributor

poirazis commented Aug 6, 2024

this looks really neat !
cant wait !

@aptkingston aptkingston added feature-branch Release this PR code into a feature branch and removed feature-branch Release this PR code into a feature branch labels Aug 8, 2024
@aptkingston
Copy link
Member Author

Closing in favour of #14360.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2024
@adrinr adrinr deleted the grid-layout-improved branch November 6, 2024 08:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-branch Release this PR code into a feature branch size/xl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants