Skip to content

Commit

Permalink
fix #951 Enhance how we append/remove Prefix/PostFix/primamry addons …
Browse files Browse the repository at this point in the history
…to element and enhance how we append multiple childs
  • Loading branch information
vegegoku committed Aug 5, 2024
1 parent 2ff0bbe commit 9a02140
Show file tree
Hide file tree
Showing 40 changed files with 721 additions and 252 deletions.
16 changes: 13 additions & 3 deletions domino-ui/src/main/java/org/dominokit/domino/ui/cards/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public Card withIcon(ChildHandler<CardHeader, Icon<?>> handler) {
* @return same card instance
*/
public Card appendChild(PostfixAddOn<?> postfix) {
header.get().appendChild(postfix);
getPostfixElement().appendChild(postfix);
return this;
}

Expand All @@ -513,18 +513,28 @@ public Card appendChild(PostfixAddOn<?> postfix) {
* @return same card instance
*/
public Card appendChild(PrefixAddOn<?> prefix) {
header.get().appendChild(prefix);
getPrefixElement().appendChild(prefix);
return this;
}

@Override
public PostfixElement getPostfixElement() {
return PostfixElement.of(header.get().element());
}

@Override
public PrefixElement getPrefixElement() {
return PrefixElement.of(header.get().element());
}

/**
* Appends an element to the right side of the card header.
*
* @param postfix A {@link org.dominokit.domino.ui.utils.PostfixAddOn} wrapped element
* @return same card instance
*/
public Card withUtility(PostfixAddOn<?> postfix) {
header.get().appendChild(postfix);
getPostfixElement().appendChild(postfix);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public CardHeader withIcon(ChildHandler<CardHeader, Icon<?>> handler) {
* @return same CardHeader instance
*/
public CardHeader appendChild(PostfixAddOn<?> postfixAddOn) {
mainHeader.get().appendChild(postfixAddOn);
getPostfixElement().appendChild(postfixAddOn);
return this;
}

Expand All @@ -445,10 +445,20 @@ public CardHeader appendChild(PostfixAddOn<?> postfixAddOn) {
* @return same card instance
*/
public CardHeader appendChild(PrefixAddOn<?> prefixAddOn) {
mainHeader.get().appendChild(prefixAddOn);
getPrefixElement().appendChild(prefixAddOn);
return this;
}

@Override
public PostfixElement getPostfixElement() {
return PostfixElement.of(mainHeader.get().element());
}

@Override
public PrefixElement getPrefixElement() {
return PrefixElement.of(mainHeader.get().element());
}

/** @dominokit-site-ignore {@inheritDoc} */
@Override
public HTMLDivElement element() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import elemental2.dom.HTMLDivElement;
import elemental2.dom.WheelEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import jsinterop.base.Js;
import org.dominokit.domino.ui.config.CarouselConfig;
Expand Down Expand Up @@ -234,6 +235,11 @@ public Carousel appendChild(Slide slide) {
return this;
}

public Carousel appendChild(Slide... slides) {
Arrays.asList(slides).forEach(this::appendChild);
return this;
}

private void nextSlide() {
Slide nextSlide;
if (slides.indexOf(activeSlide) < slides.size() - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public ChipsGroup appendChild(Chip chip) {
return this;
}

public ChipsGroup appendChild(Chip... chips) {
Arrays.asList(chips).forEach(this::appendChild);
return this;
}

/** Enables chips selection */
@Override
public ChipsGroup enable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import elemental2.dom.HTMLDivElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.dominokit.domino.ui.elements.DivElement;
Expand Down Expand Up @@ -79,6 +80,11 @@ public Accordion appendChild(AccordionPanel panel) {
return this;
}

public Accordion appendChild(AccordionPanel... panels) {
Arrays.asList(panels).forEach(this::appendChild);
return this;
}

/**
* Only if the provided AccordionPanel is one of the panels in this accordion toggle the Accordion
* panel open state. if it is open it will be closed and if closed it will open
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.dominokit.domino.ui.utils.Domino.*;

import elemental2.dom.*;
import java.util.Arrays;
import org.dominokit.domino.ui.config.AccordionConfig;
import org.dominokit.domino.ui.config.HasComponentConfig;
import org.dominokit.domino.ui.elements.DivElement;
Expand Down Expand Up @@ -104,10 +105,15 @@ public HTMLElement getAppendTarget() {
* @see NavBar
*/
public AccordionPanel appendChild(PostfixAddOn<?> element) {
headerElement.get().appendChild(element.addCss(dui_panel_utility));
getPostfixElement().appendChild(element.addCss(dui_panel_utility));
return this;
}

@Override
public PostfixElement getPostfixElement() {
return PostfixElement.of(headerElement.get().element());
}

/**
* Appends a component or element to the content body header section This will initialize and
* append the content header section if not yet initialized.
Expand All @@ -121,6 +127,11 @@ public AccordionPanel appendChild(HeaderContent<?> element) {
return this;
}

public AccordionPanel appendChild(HeaderContent<?>... elements) {
Arrays.asList(elements).forEach(this::appendChild);
return this;
}

/**
* Appends a component or element to the content body footer section This will initialize and
* append the content footer section if not yet initialized.
Expand All @@ -134,6 +145,11 @@ public AccordionPanel appendChild(FooterContent<?> element) {
return this;
}

public AccordionPanel appendChild(FooterContent<?>... elements) {
Arrays.asList(elements).forEach(this::appendChild);
return this;
}

/** @dominokit-site-ignore {@inheritDoc} */
@Override
public HTMLElement getCollapsibleElement() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,11 @@ public ColumnConfig<T> appendChild(IsElement<?> element) {
return this;
}

public ColumnConfig<T> appendChild(IsElement<?>... elements) {
Arrays.asList(elements).forEach(this::appendChild);
return this;
}

/**
* Removes the specified child node from the header element of this column if it is a direct
* child.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.dominokit.domino.ui.utils.Domino.*;

import elemental2.dom.HTMLElement;
import java.util.Arrays;
import org.dominokit.domino.ui.datatable.ColumnConfig;
import org.dominokit.domino.ui.datatable.model.Category;
import org.dominokit.domino.ui.datatable.model.Filter;
Expand Down Expand Up @@ -76,6 +77,11 @@ public SelectHeaderFilter<T> appendChild(SelectOption<String> selectOption) {
return this;
}

public SelectHeaderFilter<T> appendChild(SelectOption<String>... options) {
Arrays.asList(options).forEach(this::appendChild);
return this;
}

/**
* Initializes the header filter and adds event listeners.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.dominokit.domino.ui.datatable.plugins.summary;

import static java.util.Objects.nonNull;

import org.dominokit.domino.ui.datatable.DataTable;
import org.dominokit.domino.ui.datatable.events.TableDataUpdatedEvent;
import org.dominokit.domino.ui.datatable.plugins.DataTablePlugin;
Expand Down Expand Up @@ -53,6 +55,7 @@ public class EmptyStatePlugin<T> implements DataTablePlugin<T> {
private TableRowElement rowElement = tr();
private TDElement stateCell = td();
private TFootElement footer;
private DataTable<T> datatable;

/**
* Creates and returns a new instance of {@code EmptyStatePlugin} with the provided icon and
Expand All @@ -79,9 +82,11 @@ public EmptyStatePlugin(Icon<?> emptyStateIcon, String title) {

@Override
public void init(DataTable<T> dataTable) {
this.datatable = dataTable;
rowElement
.addCss(dui_table_row)
.appendChild(stateCell.addCss(dui_table_cell).appendChild(emptyState));
updateColSpan(dataTable);
}

/**
Expand All @@ -101,11 +106,7 @@ public void onAfterAddTable(DataTable<T> dataTable) {
TableDataUpdatedEvent.DATA_UPDATED,
event -> {
TableDataUpdatedEvent tableDataUpdatedEvent = (TableDataUpdatedEvent) event;
long columnsCount =
dataTable.getTableConfig().getLeafColumns().stream()
.filter(c -> !c.isHidden())
.count();
stateCell.setAttribute("colspan", columnsCount);
updateColSpan(dataTable);

if (tableDataUpdatedEvent.getTotalCount() == 0) {
rowElement.show();
Expand All @@ -116,6 +117,14 @@ public void onAfterAddTable(DataTable<T> dataTable) {
this.footer.insertFirst(rowElement);
}

private void updateColSpan(DataTable<T> dataTable) {
if (nonNull(dataTable)) {
long columnsCount =
dataTable.getTableConfig().getLeafColumns().stream().filter(c -> !c.isHidden()).count();
stateCell.setAttribute("colspan", columnsCount);
}
}

/**
* Gets the empty state element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
import static elemental2.dom.DomGlobal.window;
import static java.util.Objects.nonNull;
import static org.dominokit.domino.ui.style.DisplayCss.dui_hidden;
import static org.dominokit.domino.ui.utils.Domino.*;
import static org.dominokit.domino.ui.utils.Domino.div;

import elemental2.dom.*;
import elemental2.dom.Element;
import elemental2.dom.Event;
import elemental2.dom.HTMLDivElement;
import elemental2.dom.HTMLElement;
import elemental2.dom.KeyboardEvent;
import elemental2.dom.NodeList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.dominokit.domino.ui.IsElement;
Expand All @@ -36,7 +41,17 @@
import org.dominokit.domino.ui.i18n.DialogLabels;
import org.dominokit.domino.ui.icons.Icon;
import org.dominokit.domino.ui.style.SwapCssClass;
import org.dominokit.domino.ui.utils.*;
import org.dominokit.domino.ui.utils.BaseDominoElement;
import org.dominokit.domino.ui.utils.ChildHandler;
import org.dominokit.domino.ui.utils.DominoDom;
import org.dominokit.domino.ui.utils.DominoUIConfig;
import org.dominokit.domino.ui.utils.FooterContent;
import org.dominokit.domino.ui.utils.HeaderContent;
import org.dominokit.domino.ui.utils.IsPopup;
import org.dominokit.domino.ui.utils.LazyChild;
import org.dominokit.domino.ui.utils.NullLazyChild;
import org.dominokit.domino.ui.utils.PopupsCloser;
import org.dominokit.domino.ui.utils.Unit;

/**
* The AbstractDialog class is the base class for creating dialog boxes in the Domino-UI framework.
Expand Down Expand Up @@ -503,11 +518,15 @@ public HTMLDivElement element() {
* @return This dialog instance for method chaining.
*/
public T appendChild(HeaderContent<?> element) {

contentHeader.get().appendChild(element);
return (T) this;
}

public T appendChild(HeaderContent<?>... elements) {
Arrays.stream(elements).forEach(this::appendChild);
return (T) this;
}

/**
* Appends a child element to the dialog's footer.
*
Expand All @@ -519,6 +538,11 @@ public T appendChild(FooterContent<?> element) {
return (T) this;
}

public T appendChild(FooterContent<?>... elements) {
Arrays.stream(elements).forEach(this::appendChild);
return (T) this;
}

/**
* Gets the modal element of the dialog, which is the overlay behind the content.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ public T ungroup(FieldsGrouping fieldsGrouping) {
return (T) this;
}

@Override
public PrefixElement getPrefixElement() {
return PrefixElement.of(wrapperElement);
}

@Override
public PostfixElement getPostfixElement() {
return PostfixElement.of(wrapperElement);
}

/**
* Appends a prefix add-on to the form element.
*
Expand All @@ -185,7 +195,7 @@ public T ungroup(FieldsGrouping fieldsGrouping) {
*/
@Override
public T appendChild(PrefixAddOn<?> addon) {
wrapperElement.appendChild(elementOf(addon));
getPrefixElement().appendChild(addon);
return (T) this;
}

Expand All @@ -197,20 +207,13 @@ public T appendChild(PrefixAddOn<?> addon) {
*/
@Override
public T appendChild(PostfixAddOn<?> addon) {
wrapperElement.appendChild(elementOf(addon));
getPostfixElement().appendChild(addon);
return (T) this;
}

/**
* Appends a primary add-on to the form element.
*
* @param addon The primary add-on to append.
* @return This form element instance.
*/
@Override
public T appendChild(PrimaryAddOn<?> addon) {
wrapperElement.appendChild(elementOf(addon).addCss(dui_add_on, dui_add_on_mandatory));
return (T) this;
public PrimaryAddOnElement getPrimaryAddonsElement() {
return PrimaryAddOnElement.of(wrapperElement);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public interface FormsStyles {
/** CSS class for the header of a text area. */
CssClass dui_form_text_area_header = () -> "dui-form-text-area-header";

CssClass dui_form_text_area_header_filler = () -> "dui-form-text-area-header-filler";

/** CSS class for specifying the gap within a text area. */
CssClass dui_form_text_area_gap = () -> "dui-text-area-gap";
}
Loading

0 comments on commit 9a02140

Please sign in to comment.