Skip to content

Commit

Permalink
Add overloaded style() methods to HasHTMLElement
Browse files Browse the repository at this point in the history
  • Loading branch information
hpehl committed Oct 24, 2023
1 parent 767dbd8 commit a85ee62
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- Add overloaded `style()` methods to `HasHTMLElement`:

- `style(String style)`: Appends the given style to the existing styles of an element.
- `style(String style, boolean append)`: Appends or sets the given style of an element.
- `style(String property, int value)`: Sets the given style property on an element.
- `style(String property, String value)`: Sets the given style property on an element.
- `style(String property, int value, boolean important)`: Sets the given style property on an element.
- `style(String property, String value, boolean important)`: Sets the given style property on an element.

## [1.2.4] - 2023-10-18

### Added
Expand Down
33 changes: 32 additions & 1 deletion core/src/main/java/org/jboss/elemento/HasHTMLElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,38 @@ default B title(String title) {

/** Appends the given style to the existing styles of this element. */
default B style(String style) {
element().style.cssText += style;
return style(style, true);
}

/** Appends or sets the given style to the styles of this element. */
default B style(String style, boolean append) {
if (append) {
element().style.cssText += style;
} else {
element().style.cssText = style;
}
return that();
}

/** Sets the given style on this element. */
default B style(String property, int value) {
return style(property, String.valueOf(value), false);
}

/** Sets the given style on this element. */
default B style(String property, String value) {
return style(property, value, false);
}

/** Sets the given style on this element. */
default B style(String property, int value, boolean important) {
return style(property, String.valueOf(value), important);
}

/** Sets the given style on this element. */
default B style(String property, String value, boolean important) {
String priority = important ? "important" : "";
element().style.setProperty(property, value, property);
return that();
}

Expand Down

0 comments on commit a85ee62

Please sign in to comment.