Skip to content

Commit

Permalink
minor enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Jun 26, 2024
1 parent af70269 commit c8aefa1
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ public static ImageElement of(HTMLImageElement e) {
public ImageElement(HTMLImageElement element) {
super(element);
}

/**
* Sets the src for the image element
*
* @param src String image source
* @return same component
*/
public ImageElement src(String src) {
setAttribute("src", src);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public Radio(T value, String label) {
inputElement.addEventListener(
"change",
evt -> {
DomGlobal.console.info("CHANGEEEEEEEED.!");
if (isEnabled() && !isReadOnly()) {
setChecked(isChecked(), isChangeListenersPaused());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import elemental2.dom.HTMLElement;
import org.dominokit.domino.ui.elements.SpanElement;
import org.dominokit.domino.ui.style.WavesElement;
import org.dominokit.domino.ui.utils.ChildHandler;

/**
* A component that combines an icon and a text label, allowing you to create labeled icons with
Expand All @@ -30,6 +31,8 @@
public class LabeledIcon extends WavesElement<HTMLElement, LabeledIcon> {

private final SpanElement element;
private final SpanElement textElement;
private final Icon<?> icon;

/**
* Creates a labeled icon with the provided icon and text, positioned to the left.
Expand All @@ -52,8 +55,9 @@ public LabeledIcon(Icon<?> icon, String text, IconPosition position) {
element =
span()
.addCss(dui_labeled_icon)
.appendChild(icon)
.appendChild(span().addCss(dui_icon_text, dui_text_ellipsis).textContent(text));
.appendChild(this.icon = icon)
.appendChild(
textElement = span().addCss(dui_icon_text, dui_text_ellipsis).textContent(text));
init(this);
position.apply(this);
}
Expand Down Expand Up @@ -82,6 +86,50 @@ public static LabeledIcon create(Icon<?> icon, String text, IconPosition positio
return new LabeledIcon(icon, text, position);
}

/**
* Changes the text of the labeled icon
*
* @param text the new text.
* @return same component
*/
public LabeledIcon setText(String text) {
this.textElement.setTextContent(text);
return this;
}

/**
* Apply a handler to the labeledIcon text element.
*
* @param handler the handler to be applied
* @return same component
*/
public LabeledIcon withTextElement(ChildHandler<LabeledIcon, SpanElement> handler) {
handler.apply(this, textElement);
return this;
}

/**
* Apply a handler to the labeledIcon icon element.
*
* @param handler the handler to be applied
* @return same component
*/
public LabeledIcon withIcon(ChildHandler<LabeledIcon, Icon<?>> handler) {
handler.apply(this, icon);
return this;
}

/**
* Applies a new position for the labeledIcon text.
*
* @param position The new position to be applied
* @return same component.
*/
public LabeledIcon setIconPosition(IconPosition position) {
position.apply(this);
return this;
}

/** @dominokit-site-ignore {@inheritDoc} */
@Override
public HTMLElement element() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import elemental2.core.JsArray;
import elemental2.dom.CustomEvent;
import elemental2.dom.CustomEventInit;
import elemental2.dom.Element;
import elemental2.dom.Event;
import elemental2.dom.HTMLElement;
import elemental2.dom.MutationObserver;
import elemental2.dom.MutationObserverInit;
import elemental2.dom.MutationRecord;
import elemental2.dom.Node;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import jsinterop.base.Js;

/**
Expand Down Expand Up @@ -96,52 +99,64 @@ private static void observe() {

private static void onElementsAppended(MutationRecord record) {
List<Node> nodes = record.addedNodes.asList();
Set<String> processed = new HashSet<>();
for (int i = 0; i < nodes.size(); i++) {
Node elementNode = Js.uncheckedCast(nodes.get(i));
if (Node.ELEMENT_NODE == elementNode.nodeType) {
HTMLElement element = Js.uncheckedCast(elementNode);
List<DominoElement<Element>> childElements =
elements.elementOf(element).querySelectorAll("[" + ATTACH_UID_KEY + "]");
if (element.hasAttribute(ATTACH_UID_KEY)) {
element.dispatchEvent(
new CustomEvent<>(AttachDetachEventType.attachedType(elements.elementOf(element))));
String type = AttachDetachEventType.attachedType(elements.elementOf(element));
if (!processed.contains(type)) {
processed.add(type);
element.dispatchEvent(new CustomEvent<>(type));
}
}
elements
.elementOf(element)
.querySelectorAll("[" + ATTACH_UID_KEY + "]")
.forEach(
child -> {
CustomEventInit<MutationRecord> ceinit = CustomEventInit.create();
ceinit.setDetail(record);
CustomEvent<MutationRecord> event =
new CustomEvent<>(
AttachDetachEventType.attachedType(elements.elementOf(child)), ceinit);
child.element().dispatchEvent(event);
});

childElements.forEach(
child -> {
CustomEventInit<MutationRecord> ceinit = CustomEventInit.create();
ceinit.setDetail(record);
String type = AttachDetachEventType.attachedType(elements.elementOf(child));
if (!processed.contains(type)) {
processed.add(type);
CustomEvent<MutationRecord> event = new CustomEvent<>(type, ceinit);
child.element().dispatchEvent(event);
}
});
}
}
}

private static void onElementsRemoved(MutationRecord record) {
List<Node> nodes = record.removedNodes.asList();
Set<String> processed = new HashSet<>();
for (int i = 0; i < nodes.size(); i++) {
Node elementNode = Js.uncheckedCast(nodes.get(i));
if (Node.ELEMENT_NODE == elementNode.nodeType) {
HTMLElement element = Js.uncheckedCast(elementNode);
List<DominoElement<Element>> childElements =
elements.elementOf(element).querySelectorAll("[" + DETACH_UID_KEY + "]");
if (element.hasAttribute(DETACH_UID_KEY)) {
element.dispatchEvent(
new Event(AttachDetachEventType.detachedType(elements.elementOf(element))));
String type = AttachDetachEventType.detachedType(elements.elementOf(element));
if (!processed.contains(type)) {
processed.add(type);
element.dispatchEvent(new Event(type));
}
}
elements
.elementOf(element)
.querySelectorAll("[" + DETACH_UID_KEY + "]")
.forEach(
child -> {
CustomEventInit<MutationRecord> ceinit = CustomEventInit.create();
ceinit.setDetail(record);
CustomEvent<MutationRecord> event =
new CustomEvent<>(
AttachDetachEventType.detachedType(elements.elementOf(child)), ceinit);
child.element().dispatchEvent(event);
});

childElements.forEach(
child -> {
String type = AttachDetachEventType.detachedType(elements.elementOf(child));
if (!processed.contains(type)) {
processed.add(type);
CustomEventInit<MutationRecord> ceinit = CustomEventInit.create();
ceinit.setDetail(record);
CustomEvent<MutationRecord> event = new CustomEvent<>(type, ceinit);
child.element().dispatchEvent(event);
}
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
package org.dominokit.domino.ui.utils;

import elemental2.core.JsArray;
import elemental2.dom.DomGlobal;
import elemental2.promise.Promise;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
import jsinterop.base.Any;
import jsinterop.base.Js;

/**
* A class for interacting with the clipboard to read and write data.
Expand Down Expand Up @@ -59,4 +62,24 @@ public class Clipboard {
* @return A promise that resolves when the text data is successfully written to the clipboard.
*/
public native Promise<Any> writeText(String text);

@JsOverlay
public static Promise<JsArray<ClipboardItem>> get() {
return Js.<DominoNavigator>uncheckedCast(DomGlobal.window.navigator).clipboard.read();
}

@JsOverlay
public static Promise<String> getText() {
return Js.<DominoNavigator>uncheckedCast(DomGlobal.window.navigator).clipboard.readText();
}

@JsOverlay
public static Promise<Any> put(ClipboardItem item) {
return Js.<DominoNavigator>uncheckedCast(DomGlobal.window.navigator).clipboard.write(item);
}

@JsOverlay
public static Promise<Any> put(String text) {
return Js.<DominoNavigator>uncheckedCast(DomGlobal.window.navigator).clipboard.writeText(text);
}
}

0 comments on commit c8aefa1

Please sign in to comment.