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

Automatically wrap non-layout components in box containers #804

Merged
merged 11 commits into from
Aug 22, 2022

Conversation

apedroferreira
Copy link
Member

@apedroferreira apedroferreira commented Aug 16, 2022

Issue #712

Screen Shot 2022-08-16 at 20 20 18

Not 100% convinced about this UI for the box alignment (which might just be a temporary thing until we improve resizing anyway), but just looking for feedback on where to place it, or this might be okay after all.

@render
Copy link

render bot commented Aug 16, 2022

@oliviertassinari oliviertassinari requested a deployment to default-component-boxes - toolpad-db PR #804 August 16, 2022 19:18 — with Render Abandoned
@apedroferreira apedroferreira marked this pull request as ready for review August 17, 2022 09:37
@apedroferreira apedroferreira self-assigned this Aug 17, 2022
* the component it will forward it to this property.
* Enables controlling the aligment of the component container box.
*/
hasLayoutBoxAlign?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Which components don't we want this for?

Copy link
Member Author

Choose a reason for hiding this comment

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

DataGrid, for example, as it takes up the whole box?
(btw i noticed bindings are still broken and fixing it now, sorry about that)

Copy link
Member

Choose a reason for hiding this comment

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

This is public API, I'm not sure about the interface

hasLayoutBoxAlign
hasLayoutBoxJustify
  • It's a bit verbose for the current use-case. e.g. might as well get away with something like a layout: 'static' | 'flex' to mark whether a component that sizes with its box, or has a static size.
  • Would it make sense to be more explicit about direction? i.e. use vertical/horizontal or something instead of "align" and "justify". layout: { vertical: 'flex', horizontal: 'static' }
  • It's not powerful enough to build upon. e.g. it might depend on component state. like a TextField that is in mode fullWidth may want to have its justification disabled.
resizableHeightProp

I'm not sure we should rely on a custom component correctly implementing the height prop. Can't we remove this resizableHeightProp and instead allow changing the height of the box container of every component?

Copy link
Member Author

Choose a reason for hiding this comment

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

just fixed the bindings, i hadn't messed with bindings before but seems good now

Copy link
Member

Choose a reason for hiding this comment

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

🤔 I'm not sure whether we should make these bindable, at least the height prop shouldn't be I think, it would create too much layout shift.

Copy link
Member Author

Choose a reason for hiding this comment

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

great points, i agree with all of them

  • something simpler like the layout prop you mentioned should cover all our current use cases, no point yet even in align/justify being separate things, i'll change it to something like that
  • justify/align naming is being confusing even to me so i'll change them to something more explicit
  • about making the resizable height be the height of the container box, now that i abstracted the box container and am creating more "layout" props this should be easier to do and makes complete sense - this i probably will do in a separate PR though

Copy link
Member Author

@apedroferreira apedroferreira Aug 17, 2022

Choose a reason for hiding this comment

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

🤔 I'm not sure whether we should make these bindable, at least the height prop shouldn't be I think, it would create too much layout shift.

I ended up doing it because i noticed bindings were setting the default values in the controls. I don't see any cons to doing it for the alignment/justify even if it's not super useful (even though these might just be temporary controls until we allow for controlling margins a bit better).
I can make the height not be bindable though - as elements in the same row always take up the same height anyway i guess it shouldn't be too useful...

Copy link
Member

Choose a reason for hiding this comment

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

Some other options

{
  flex: 'vertical' | 'horizontal' | 'both',
  flex: 'row' | 'column' | 'all',
  flex: 'x' | 'y' | 'xy'
}

Letting the imagination free, we could in the future expand that to (props) => 'vertical' | 'horizontal' | 'both'. e.g.

{
  flex: ({ fullWidth }) => fullWidth ? 'vertical' : 'both'
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Some other options

{
  flex: 'vertical' | 'horizontal' | 'both',
  flex: 'row' | 'column' | 'all',
  flex: 'x' | 'y' | 'xy'
}

Letting the imagination free, we could in the future expand that to (props) => 'vertical' | 'horizontal' | 'both'. e.g.

{
  flex: ({ fullWidth }) => fullWidth ? 'vertical' : 'both'
}

we can make it a function that takes the props, just not sure how useful it would really be to make this behavior change according to stateful values.
i wouldn't mind that a "horizontal alignment" control was enabled even if a component was taking up the full-width - wouldn't be wrong, it just wouldn't be doing anything in that particular case.
but there's probably in no harm in making this more powerful in case we see the need for it down the line.

@apedroferreira
Copy link
Member Author

@Janpot how about this?

elm.layout?.[propName as keyof typeof layoutBoxArgTypes] ||
appDom.createConst(argType?.defaultValue ?? undefined);
const bindingId = `${elm.id}.layout.${propName}`;
const scopePath = `${elm.name}.@layout.${propName}`;
Copy link
Member Author

Choose a reason for hiding this comment

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

i want to make sure this scope path can't collide with any normal prop name. any other suggestions?

Copy link
Member

@Janpot Janpot Aug 23, 2022

Choose a reason for hiding this comment

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

It shouldn't be in the scope, you can remove the scope path. In fact, should we even have these bindable?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok let's make these not be bindable for now - i'll just have to set the default value in a different way if i remember correctly

@apedroferreira
Copy link
Member Author

merging, if there are any more suggestions i can add later.

@apedroferreira apedroferreira merged commit fffed02 into master Aug 22, 2022
@apedroferreira apedroferreira deleted the default-component-boxes branch August 22, 2022 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants