Skip to content

Commit

Permalink
refactor: separate spacing into gap and padding (#6853)
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur-vaadin authored Dec 4, 2024
1 parent af1bf6e commit b0698f2
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public DashboardItemResizePage() {
dashboard.setMinimumRowHeight("200px");
dashboard.setMinimumColumnWidth("250px");
dashboard.setMaximumColumnWidth("250px");
// Use setSpacing when it is made public
getStyle().set("--vaadin-dashboard-spacing", "0px");
dashboard.setGap("0px");
dashboard.setPadding("0px");

DashboardWidget widget = new DashboardWidget();
widget.setTitle("Widget");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,26 +313,47 @@ public void setMinimumRowHeight(String minRowHeight) {
}

/**
* Returns the spacing of the dashboard. This value adjusts the spacing
* between elements within the component and the space around its outer
* edges.
* Returns the gap of the dashboard. This value adjusts the gap between
* elements within the dashboard.
*
* @return the spacing of the dashboard
* @return the gap of the dashboard
*/
String getSpacing() {
return getStyle().get("--vaadin-dashboard-spacing");
public String getGap() {
return getStyle().get("--vaadin-dashboard-gap");
}

/**
* Sets the spacing of the dashboard. This value adjusts the spacing between
* elements within the component and the space around its outer edges.
* Sets the gap of the dashboard. This value adjusts the gap between
* elements within the dashboard.
*
* @param spacing
* the new spacing. Pass in {@code null} to set the spacing back
* @param gap
* the new gap. Pass in {@code null} to set the gap back to the
* default value.
*/
public void setGap(String gap) {
getStyle().set("--vaadin-dashboard-gap", gap);
}

/**
* Returns the padding of the dashboard. This value adjusts the space around
* the outer edges of the dashboard.
*
* @return the padding of the dashboard
*/
public String getPadding() {
return getStyle().get("--vaadin-dashboard-padding");
}

/**
* Sets the padding of the dashboard. This value adjusts the space around
* the outer edges of the dashboard.
*
* @param padding
* the new padding. Pass in {@code null} to set the padding back
* to the default value.
*/
void setSpacing(String spacing) {
getStyle().set("--vaadin-dashboard-spacing", spacing);
public void setPadding(String padding) {
getStyle().set("--vaadin-dashboard-padding", padding);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,41 +794,78 @@ public void setMinimumRowHeightNull_valueIsCorrectlyRetrieved() {
}

@Test
public void setSpacing_valueIsCorrectlySet() {
String propertyName = "--vaadin-dashboard-spacing";
public void setGap_valueIsCorrectlySet() {
String propertyName = "--vaadin-dashboard-gap";
String valueToSet = "10px";
Assert.assertNull(dashboard.getStyle().get(propertyName));
dashboard.setSpacing(valueToSet);
dashboard.setGap(valueToSet);
Assert.assertEquals(valueToSet, dashboard.getStyle().get(propertyName));
dashboard.setSpacing(null);
dashboard.setGap(null);
Assert.assertNull(dashboard.getStyle().get(propertyName));
}

@Test
public void setSpacingNull_propertyIsRemoved() {
dashboard.setSpacing("10px");
dashboard.setSpacing(null);
public void setGapNull_propertyIsRemoved() {
dashboard.setGap("10px");
dashboard.setGap(null);
Assert.assertNull(dashboard.getStyle().get("--vaadin-dashboard-gap"));
}

@Test
public void defaultGapValueIsCorrectlyRetrieved() {
Assert.assertNull(dashboard.getGap());
}

@Test
public void setGap_valueIsCorrectlyRetrieved() {
String valueToSet = "10px";
dashboard.setGap(valueToSet);
Assert.assertEquals(valueToSet, dashboard.getGap());
}

@Test
public void setGapNull_valueIsCorrectlyRetrieved() {
dashboard.setGap("10px");
dashboard.setGap(null);
Assert.assertNull(dashboard.getGap());
}

@Test
public void setPadding_valueIsCorrectlySet() {
String propertyName = "--vaadin-dashboard-padding";
String valueToSet = "10px";
Assert.assertNull(dashboard.getStyle().get(propertyName));
dashboard.setPadding(valueToSet);
Assert.assertEquals(valueToSet, dashboard.getStyle().get(propertyName));
dashboard.setPadding(null);
Assert.assertNull(dashboard.getStyle().get(propertyName));
}

@Test
public void setPaddingNull_propertyIsRemoved() {
dashboard.setPadding("10px");
dashboard.setPadding(null);
Assert.assertNull(
dashboard.getStyle().get("--vaadin-dashboard-spacing"));
dashboard.getStyle().get("--vaadin-dashboard-padding"));
}

@Test
public void defaultSpacingValueIsCorrectlyRetrieved() {
Assert.assertNull(dashboard.getSpacing());
public void defaultPaddingValueIsCorrectlyRetrieved() {
Assert.assertNull(dashboard.getPadding());
}

@Test
public void setSpacing_valueIsCorrectlyRetrieved() {
public void setPadding_valueIsCorrectlyRetrieved() {
String valueToSet = "10px";
dashboard.setSpacing(valueToSet);
Assert.assertEquals(valueToSet, dashboard.getSpacing());
dashboard.setPadding(valueToSet);
Assert.assertEquals(valueToSet, dashboard.getPadding());
}

@Test
public void setSpacingNull_valueIsCorrectlyRetrieved() {
dashboard.setSpacing("10px");
dashboard.setSpacing(null);
Assert.assertNull(dashboard.getSpacing());
public void setPaddingNull_valueIsCorrectlyRetrieved() {
dashboard.setPadding("10px");
dashboard.setPadding(null);
Assert.assertNull(dashboard.getPadding());
}

@Test
Expand Down

0 comments on commit b0698f2

Please sign in to comment.