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

feat: add API to set spacing in HL/VL with custom values #7129

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

DiegoCardoso
Copy link
Contributor

Description

This change adds:

  • setSpacing(String) - method to set spacing passing a CSS length value (e.g. 10px, 1em)
  • setSpacing(float, Unit) - method to set spacing passing a float value and a Unit
  • getSpacing() - method to return the value set to the gap CSS property of the layout

It also changes isSpacing() to return whether the spacing has been set by the theme API or by setting the gap property.

Part of #6999 - the enum API is not part of this PR and should be added later

Type of change

  • Feature

This changes adds:
- `setSpacing(String)` - method to set spacing passing a CSS lenght
value (e.g. `10px`, `1em`)
- `setSpacing(float, Unit)` - method to set spacing passing a float
value and a `Unit`
- `getSpacing()` - method to return the value set to the `gap` CSS
property of the layout

It also changes `isSpacing()` to return whether the spacing has been set
by the theme API or by setting the `gap` property.
*
* @return the spacing between the components
*/
default String getSpacing() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this wouldn't return a value when:

  • Using setSpacing(boolean)
  • Using setSpacing(SpacingEnum) once that is added

Which could be somewhat confusing? I wonder if we need this, or if we should clarify this in the JavaDoc at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed the setSpacing(boolean) wouldn't return a value, but setSpacing(SpacingEnum) depends on the implementation. For instance, each enum entrance could hold the name of the CSS variable it maps to, then the setSpacint(SpacingEnum) would call setSpacing(enum.getValue()). For the boolean API, the isSpacing() would be the preferable way to check whether spacing is set or not, then we could mention it on the JavaDoc.

@@ -93,16 +94,58 @@ default boolean isPadding() {
* it if {@code false}
*/
default void setSpacing(boolean spacing) {
if (!spacing) {
getElement().getStyle().remove("gap");
Copy link
Contributor

Choose a reason for hiding this comment

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

Could add a test case for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

public void checkSpacingStringSetter() {
layout.setSpacing("20px");
assertTrue("Expected spacing to be applied after setting it",
layout.isSpacing());
Copy link
Contributor

Choose a reason for hiding this comment

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

isSpacing checks for both, the theme variant or the gap. It looks like the new overloads should also always set the theme variant, so maybe it would be good to cover that explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it's not needed to set the theme in the new overloads. It was a leftover from another approach that would be require a few changes in the web component. Removed.

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