Skip to content

Commit a1566f4

Browse files
committed
tweaks and enhancements
1 parent 98fad5d commit a1566f4

File tree

16 files changed

+353
-41
lines changed

16 files changed

+353
-41
lines changed

domino-ui/src/main/java/org/dominokit/domino/ui/dialogs/AbstractDialog.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,17 @@ public T setDefaultFocusElement(IsElement<?> defaultFocusElement) {
697697
return (T) this;
698698
}
699699

700+
/**
701+
* Use to apply changes to the actual root element of this dialog
702+
*
703+
* @param handler
704+
* @return same dialog instance
705+
*/
706+
public T withMainElement(ChildHandler<T, DivElement> handler) {
707+
handler.apply((T) this, element);
708+
return (T) this;
709+
}
710+
700711
@Override
701712
public void resetZIndexLayer() {
702713
// Dialogs should never rest their base layer.;

domino-ui/src/main/java/org/dominokit/domino/ui/forms/TextAreaBox.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,7 @@
2323
import elemental2.dom.HTMLTextAreaElement;
2424
import org.dominokit.domino.ui.elements.DivElement;
2525
import org.dominokit.domino.ui.elements.SpanElement;
26-
import org.dominokit.domino.ui.utils.DominoElement;
27-
import org.dominokit.domino.ui.utils.FillerElement;
28-
import org.dominokit.domino.ui.utils.IntersectionObserver;
29-
import org.dominokit.domino.ui.utils.IntersectionObserverEntry;
30-
import org.dominokit.domino.ui.utils.IntersectionObserverOptions;
31-
import org.dominokit.domino.ui.utils.LazyChild;
32-
import org.dominokit.domino.ui.utils.PostfixElement;
33-
import org.dominokit.domino.ui.utils.PrefixElement;
34-
import org.dominokit.domino.ui.utils.PrimaryAddOnElement;
26+
import org.dominokit.domino.ui.utils.*;
3527

3628
/**
3729
* The TextAreaBox class is a form field component for text areas, providing features such as prefix
@@ -182,10 +174,7 @@ public String getStringValue() {
182174

183175
@Override
184176
protected DominoElement<HTMLTextAreaElement> createInputElement(String type) {
185-
return textarea()
186-
.addCss(dui_field_input)
187-
.setCssProperty("line-height", "26px")
188-
.toDominoElement();
177+
return textarea().addCss(dui_field_input).toDominoElement();
189178
}
190179

191180
/**
@@ -237,7 +226,11 @@ private void adjustHeight() {
237226
if (autoSize) {
238227
getInputElement().style().setHeight("auto");
239228
int scrollHeight = getInputElement().element().scrollHeight;
240-
getInputElement().style().setHeight(Math.max(scrollHeight, 28) + "px");
229+
String value =
230+
DominoDom.window.getComputedStyle(getInputElement().element()).get("line-height");
231+
getInputElement()
232+
.style()
233+
.setHeight(Math.max(scrollHeight, CssParser.parseCssNumber(value) + 2) + "px");
241234
}
242235
}
243236

domino-ui/src/main/java/org/dominokit/domino/ui/menu/AbstractMenuItem.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ public AbstractMenuItem<V> addDeselectionHandler(DeselectionHandler deselectionH
342342
return this;
343343
}
344344

345+
@Override
346+
public AbstractMenuItem<V> removeDeselectionHandler(DeselectionHandler deselectionHandler) {
347+
if (nonNull(deselectionHandler)) {
348+
deselectionHandlers.remove(deselectionHandler);
349+
}
350+
return this;
351+
}
352+
345353
/**
346354
* Sets focus on the clickable element of the menu item.
347355
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.utils;
17+
18+
public abstract class Attribute<T> implements IsAttribute<T> {
19+
20+
private final String name;
21+
22+
public Attribute(String name) {
23+
this.name = name;
24+
}
25+
26+
@Override
27+
public String getName() {
28+
return name;
29+
}
30+
}

domino-ui/src/main/java/org/dominokit/domino/ui/utils/BaseDominoElement.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,30 @@ public T setAttribute(String name, double value) {
18061806
return element;
18071807
}
18081808

1809+
/**
1810+
* Sets the specified attribute to the given double value on this element.
1811+
*
1812+
* @param attribute {@link IsAttribute}.
1813+
* @return The modified DOM element.
1814+
*/
1815+
@Editor.Ignore
1816+
public T setAttribute(IsAttribute<?> attribute) {
1817+
element().setAttribute(attribute.getName(), String.valueOf(attribute.getValue()));
1818+
return element;
1819+
}
1820+
1821+
/**
1822+
* Sets the specified attribute to the given double value on this element.
1823+
*
1824+
* @param attributes array of {@link IsAttribute}.
1825+
* @return The modified DOM element.
1826+
*/
1827+
@Editor.Ignore
1828+
public T setAttribute(IsAttribute<?>... attributes) {
1829+
Arrays.asList(attributes).forEach(this::setAttribute);
1830+
return element;
1831+
}
1832+
18091833
/**
18101834
* Gets the value of the specified attribute on this element.
18111835
*
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.utils;
17+
18+
public class BooleanAttribute extends Attribute<Boolean> {
19+
20+
private final Boolean value;
21+
22+
public static BooleanAttribute of(String name, Boolean value) {
23+
return new BooleanAttribute(name, value);
24+
}
25+
26+
public BooleanAttribute(String name, Boolean value) {
27+
super(name);
28+
this.value = value;
29+
}
30+
31+
@Override
32+
public Boolean getValue() {
33+
return value;
34+
}
35+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.utils;
17+
18+
import elemental2.core.JsRegExp;
19+
import elemental2.core.RegExpResult;
20+
21+
public class CssParser {
22+
23+
/**
24+
* Extracts the numeric part from a CSS unit string (e.g., "26px" -> 26.0). Compatible with GWT /
25+
* Elemental2 (no use of String.replaceFirst).
26+
*
27+
* @param cssValue the CSS unit string
28+
* @return the numeric part as a double, or NaN if parsing fails
29+
*/
30+
public static double parseCssNumber(String cssValue) {
31+
final int DEFAULT_LINE_HEIGHT = 26;
32+
if (cssValue == null || cssValue.isEmpty()) {
33+
return DEFAULT_LINE_HEIGHT;
34+
}
35+
36+
// Use JavaScript-style RegExp via Elemental2
37+
JsRegExp regex = new JsRegExp("^[0-9]*\\.?[0-9]+");
38+
RegExpResult result = regex.exec(cssValue.trim());
39+
40+
if (result != null && result.length > 0) {
41+
try {
42+
return Double.parseDouble(result.getAt(0));
43+
} catch (NumberFormatException e) {
44+
return DEFAULT_LINE_HEIGHT;
45+
}
46+
}
47+
48+
return DEFAULT_LINE_HEIGHT;
49+
}
50+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.utils;
17+
18+
public class DoubleAttribute extends Attribute<Double> {
19+
20+
private final Double value;
21+
22+
public static DoubleAttribute of(String name, Double value) {
23+
return new DoubleAttribute(name, value);
24+
}
25+
26+
public DoubleAttribute(String name, Double value) {
27+
super(name);
28+
this.value = value;
29+
}
30+
31+
@Override
32+
public Double getValue() {
33+
return value;
34+
}
35+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.utils;
17+
18+
import java.util.Map;
19+
import java.util.Optional;
20+
21+
public interface HasComponentMeta<T> {
22+
Map<String, ComponentMeta> getMetaObjects();
23+
24+
default T setMetaObject(ComponentMeta componentMeta) {
25+
getMetaObjects().put(componentMeta.getKey(), componentMeta);
26+
onMetaObjectUpdated(componentMeta);
27+
return (T) this;
28+
}
29+
30+
default T onMetaObjectUpdated(ComponentMeta componentMeta) {
31+
return (T) this;
32+
}
33+
34+
default <C> Optional<C> getMetaObject(String key) {
35+
if (getMetaObjects().containsKey(key)) {
36+
return Optional.of((C) getMetaObjects().get(key));
37+
}
38+
return Optional.empty();
39+
}
40+
}

domino-ui/src/main/java/org/dominokit/domino/ui/utils/HasDeselectionHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public interface HasDeselectionHandler<T> {
3232
*/
3333
T addDeselectionHandler(DeselectionHandler deselectionHandler);
3434

35+
T removeDeselectionHandler(DeselectionHandler deselectionHandler);
36+
3537
/** The {@code DeselectionHandler} interface defines a method to handle deselection events. */
3638
interface DeselectionHandler {
3739

0 commit comments

Comments
 (0)