Skip to content

Commit f62e5f0

Browse files
committed
tweaks and minor fixes
1 parent a1566f4 commit f62e5f0

File tree

16 files changed

+478
-140
lines changed

16 files changed

+478
-140
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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.style;
17+
18+
import elemental2.dom.Element;
19+
import java.util.*;
20+
21+
/**
22+
* A class for managing a set of prefixed CSS classes and ensuring that only one of them is active
23+
* at a time on a DOM element.
24+
*/
25+
public class LimitOneOfPrefixedCssClass implements CssClass {
26+
27+
private final Set<String> prefixes;
28+
29+
private final CssClass cssClass;
30+
31+
/**
32+
* Creates a new instance of {@link LimitOneOfPrefixedCssClass} with the specified prefix CSS
33+
* class name and a string postfix.
34+
*
35+
* @param prefixes The base CSS classes names to be replaced.
36+
* @param cssClass css class to replace all prefixed css classes.
37+
* @return A new {@link LimitOneOfPrefixedCssClass} instance with the specified css class.
38+
*/
39+
public static LimitOneOfPrefixedCssClass of(Set<String> prefixes, String cssClass) {
40+
return new LimitOneOfPrefixedCssClass(prefixes, () -> cssClass);
41+
}
42+
43+
/**
44+
* Creates a new instance of {@link LimitOneOfPrefixedCssClass} with the specified prefix CSS
45+
* class name and a string postfix.
46+
*
47+
* @param prefixes The base CSS classes names to be replaced.
48+
* @param cssClass css class to replace all prefixed css classes.
49+
* @return A new {@link LimitOneOfPrefixedCssClass} instance with the specified css class.
50+
*/
51+
public static LimitOneOfPrefixedCssClass of(Set<String> prefixes, CssClass cssClass) {
52+
return new LimitOneOfPrefixedCssClass(prefixes, cssClass);
53+
}
54+
55+
/**
56+
* Creates a new instance of {@link LimitOneOfPrefixedCssClass} with the specified prefix CSS
57+
* class name and a string postfix.
58+
*
59+
* @param prefix The base CSS classes names to be replaced.
60+
* @param cssClass css class to replace all prefixed css classes.
61+
* @return A new {@link LimitOneOfPrefixedCssClass} instance with the specified css class.
62+
*/
63+
public static LimitOneOfPrefixedCssClass of(String prefix, String cssClass) {
64+
return of(
65+
new HashSet<>() {
66+
{
67+
add(prefix);
68+
}
69+
},
70+
cssClass);
71+
}
72+
73+
/**
74+
* Creates a new instance of {@link LimitOneOfPrefixedCssClass} with the specified prefix CSS
75+
* class name and a string postfix.
76+
*
77+
* @param prefix The base CSS classes names to be replaced.
78+
* @param cssClass css class to replace all prefixed css classes.
79+
* @return A new {@link LimitOneOfPrefixedCssClass} instance with the specified css class.
80+
*/
81+
public static LimitOneOfPrefixedCssClass of(String prefix, CssClass cssClass) {
82+
return of(
83+
new HashSet<>() {
84+
{
85+
add(prefix);
86+
}
87+
},
88+
cssClass);
89+
}
90+
91+
/**
92+
* Creates a new instance of {@link LimitOneOfPrefixedCssClass} with the specified prefix CSS
93+
* class name and a string postfix.
94+
*
95+
* @param cssClass css class to replace all prefixed css classes.
96+
* @param prefixes The base CSS classes names to be replaced.
97+
* @return A new {@link LimitOneOfPrefixedCssClass} instance with the specified css class.
98+
*/
99+
public static LimitOneOfPrefixedCssClass of(CssClass cssClass, String... prefixes) {
100+
return of(new HashSet<>(Arrays.asList(prefixes)), cssClass);
101+
}
102+
103+
/**
104+
* Creates a new instance of {@link LimitOneOfPrefixedCssClass} with the specified prefix CSS
105+
* class name and a string postfix.
106+
*
107+
* @param cssClass css class to replace all prefixed css classes.
108+
* @param prefixes The base CSS classes names to be replaced.
109+
* @return A new {@link LimitOneOfPrefixedCssClass} instance with the specified css class.
110+
*/
111+
public static LimitOneOfPrefixedCssClass of(String cssClass, String... prefixes) {
112+
return of(new HashSet<>(Arrays.asList(prefixes)), cssClass);
113+
}
114+
115+
/**
116+
* Creates a PostfixCssClass with the specified base CSS class name and string postfix.
117+
*
118+
* @param prefixes The base CSS class name without any postfix.
119+
* @param cssClass The class to replace prefixed css classes.
120+
*/
121+
public LimitOneOfPrefixedCssClass(Set<String> prefixes, CssClass cssClass) {
122+
this.prefixes = prefixes;
123+
this.cssClass = cssClass;
124+
}
125+
126+
/**
127+
* Removes all css classes that has the same prefix as the baseCssName.
128+
*
129+
* @param element The DOM element from which to remove the prefixed CSS classes.
130+
*/
131+
@Override
132+
public void remove(Element element) {
133+
CompositeCssClass.of(element).getCssClasses().stream()
134+
.filter(
135+
className ->
136+
prefixes.stream().anyMatch(prefix -> className.getCssClass().startsWith(prefix)))
137+
.forEach(css -> css.remove(element));
138+
}
139+
140+
/**
141+
* Applies the active CSS class to the given DOM element if it is in the list of allowed classes.
142+
*
143+
* @param element The DOM element to which to apply the active CSS class.
144+
*/
145+
@Override
146+
public void apply(Element element) {
147+
remove(element);
148+
this.cssClass.apply(element);
149+
}
150+
151+
@Override
152+
public String getCssClass() {
153+
return this.cssClass.getCssClass();
154+
}
155+
}

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/selection/SelectionPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class SelectionPlugin<T> implements DataTablePlugin<T> {
5454
private Supplier<Element> singleSelectIndicator = () -> Icons.check().element();
5555
private SelectionCondition<T> selectionCondition = (table, row) -> true;
5656
private TableRow<T> lastSelected;
57-
private CheckBoxCreator<T> checkBoxCreator = tableRow -> CheckBox.create();
57+
private CheckBoxCreator<T> checkBoxCreator = tableRow -> CheckBox.create().addCss(dui_minified);
5858
private DataTable<T> datatable;
5959
private List<T> oldSelection = new ArrayList<>();
6060
private boolean retainSelectionOnDataChange = false;

domino-ui/src/main/java/org/dominokit/domino/ui/notifications/Notification.java

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.dominokit.domino.ui.button.RemoveButton;
2727
import org.dominokit.domino.ui.elements.DivElement;
2828
import org.dominokit.domino.ui.elements.SpanElement;
29+
import org.dominokit.domino.ui.events.CustomEvents;
2930
import org.dominokit.domino.ui.events.EventType;
3031
import org.dominokit.domino.ui.style.*;
3132
import org.dominokit.domino.ui.utils.BaseDominoElement;
@@ -49,6 +50,7 @@
4950
public class Notification extends BaseDominoElement<HTMLDivElement, Notification>
5051
implements NotificationStyles {
5152

53+
public static final String DUI_NOTIFICATION_CLOSE = "dui-notification-close";
5254
private final DivElement element;
5355
private final DivElement root;
5456
private final DivElement content;
@@ -62,7 +64,8 @@ public class Notification extends BaseDominoElement<HTMLDivElement, Notification
6264
private boolean dismissible = true;
6365
private boolean infinite = false;
6466
private boolean closed = true;
65-
private final List<CloseHandler> closeHandlers = new ArrayList<>();
67+
private final List<NotificationHandler> closeHandlers = new ArrayList<>();
68+
private final List<NotificationHandler> showHandlers = new ArrayList<>();
6669

6770
/** Constructs a default notification instance. */
6871
public Notification() {
@@ -82,6 +85,9 @@ public Notification() {
8285
element.insertBefore(span().addCss("dui-notification-filler"), closeButton.element());
8386
});
8487
init(this);
88+
onAttached((target, mutationRecord) -> showHandlers.forEach(handler -> handler.apply(this)));
89+
onDetached((target, mutationRecord) -> closeHandlers.forEach(handler -> handler.apply(this)));
90+
addEventListener(DUI_NOTIFICATION_CLOSE, evt -> close());
8591
}
8692

8793
/**
@@ -105,6 +111,19 @@ public static Notification create() {
105111
return new Notification();
106112
}
107113

114+
/** Close all currently opened notifications */
115+
public static void dismissAll() {
116+
NodeList<Element> notifications =
117+
DomGlobal.document.querySelectorAll("." + dui_notification_wrapper.getCssClass());
118+
notifications
119+
.asList()
120+
.forEach(
121+
notification -> {
122+
CustomEvent<Void> closeEvent = CustomEvents.create(DUI_NOTIFICATION_CLOSE);
123+
notification.dispatchEvent(closeEvent);
124+
});
125+
}
126+
108127
/**
109128
* {@inheritDoc}
110129
*
@@ -305,7 +324,6 @@ public final void close(int after) {
305324
animateClose(
306325
after,
307326
() -> {
308-
closeHandlers.forEach(CloseHandler::onClose);
309327
this.closed = true;
310328
});
311329
}
@@ -335,32 +353,67 @@ private void animateClose(int after, Runnable onComplete) {
335353
*
336354
* @return a list of close handlers
337355
*/
338-
public List<CloseHandler> getCloseHandlers() {
356+
public List<NotificationHandler> getCloseHandlers() {
339357
return closeHandlers;
340358
}
341359

360+
/**
361+
* Retrieves the list of show handlers associated with the notification.
362+
*
363+
* @return a list of show handlers
364+
*/
365+
public List<NotificationHandler> getShowHandlers() {
366+
return showHandlers;
367+
}
368+
342369
/**
343370
* Adds a close handler to the notification.
344371
*
345-
* @param closeHandler the close handler to be added
372+
* @param notificationHandler the close handler to be added
346373
* @return this notification for chaining
347374
*/
348-
public Notification addCloseHandler(CloseHandler closeHandler) {
349-
if (nonNull(closeHandler)) {
350-
closeHandlers.add(closeHandler);
375+
public Notification addCloseHandler(NotificationHandler notificationHandler) {
376+
if (nonNull(notificationHandler)) {
377+
closeHandlers.add(notificationHandler);
378+
}
379+
return this;
380+
}
381+
382+
/**
383+
* Adds a show handler to the notification.
384+
*
385+
* @param showHandler the show handler to be added
386+
* @return this notification for chaining
387+
*/
388+
public Notification addShowHandler(NotificationHandler showHandler) {
389+
if (nonNull(showHandler)) {
390+
showHandlers.add(showHandler);
351391
}
352392
return this;
353393
}
354394

355395
/**
356396
* Removes a specified close handler from the notification.
357397
*
358-
* @param closeHandler the close handler to be removed
398+
* @param notificationHandler the close handler to be removed
399+
* @return this notification for chaining
400+
*/
401+
public Notification removeCloseHandler(NotificationHandler notificationHandler) {
402+
if (nonNull(notificationHandler)) {
403+
closeHandlers.remove(notificationHandler);
404+
}
405+
return this;
406+
}
407+
408+
/**
409+
* Removes a specified show handler from the notification.
410+
*
411+
* @param showHandler the show handler to be removed
359412
* @return this notification for chaining
360413
*/
361-
public Notification removeCloseHandler(CloseHandler closeHandler) {
362-
if (nonNull(closeHandler)) {
363-
closeHandlers.remove(closeHandler);
414+
public Notification removeShowHandler(NotificationHandler showHandler) {
415+
if (nonNull(showHandler)) {
416+
showHandlers.remove(showHandler);
364417
}
365418
return this;
366419
}
@@ -387,12 +440,13 @@ public HTMLDivElement element() {
387440
}
388441

389442
/**
390-
* A functional interface representing handlers that are triggered when a notification is closed.
443+
* A functional interface representing handlers that are triggered when a notification is
444+
* shown/closed.
391445
*/
392446
@FunctionalInterface
393-
public interface CloseHandler {
394-
/** Triggered when the notification is closed. */
395-
void onClose();
447+
public interface NotificationHandler {
448+
/** Triggered when the notification is shown/closed. */
449+
void apply(Notification notification);
396450
}
397451

398452
/**

domino-ui/src/main/java/org/dominokit/domino/ui/stepper/CompletedStep.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
*/
1616
package org.dominokit.domino.ui.stepper;
1717

18-
import static org.dominokit.domino.ui.style.GenericCss.dui_success;
18+
import static org.dominokit.domino.ui.stepper.StepStateCss.dui_step_state_completed;
1919

2020
import org.dominokit.domino.ui.icons.lib.Icons;
21-
import org.dominokit.domino.ui.style.ColorsCss;
22-
import org.dominokit.domino.ui.style.SpacingCss;
2321

2422
/**
2523
* A concrete implementation of the {@link StepState} interface representing a completed step in a
@@ -37,12 +35,9 @@ public class CompletedStep implements StepState {
3735
@Override
3836
public void apply(StepTracker tracker) {
3937
tracker
40-
.addCss(ColorsCss.dui_accent_success)
38+
.addCss(dui_step_state_completed)
4139
.withTrackerNode(
42-
(parent1, node) ->
43-
node.appendChild(
44-
Icons.check().addCss(SpacingCss.dui_font_size_4, dui_tracker_node_icon))
45-
.addCss(dui_success));
40+
(parent1, node) -> node.appendChild(Icons.check().addCss(dui_tracker_node_icon)));
4641
}
4742

4843
/**
@@ -54,8 +49,8 @@ public void apply(StepTracker tracker) {
5449
@Override
5550
public void cleanUp(StepTracker tracker) {
5651
tracker
57-
.removeCss(ColorsCss.dui_accent_success)
58-
.withTrackerNode((parent1, node) -> node.clearElement().removeCss(dui_success));
52+
.removeCss(dui_step_state_completed)
53+
.withTrackerNode((parent1, node) -> node.clearElement());
5954
}
6055

6156
/**

0 commit comments

Comments
 (0)