Interface IsElement<E extends Element>

All Known Subinterfaces:
Container<E,B>, Finder<E>, HasElement<E,B>, HasHTMLElement<E,B>, HasInputElement<E,B>
All Known Implementing Classes:
HTMLContainerBuilder, HTMLElementBuilder, InputElementBuilder, LazyElement

public interface IsElement<E extends Element>
Interface for custom components returning a single element.

public class TodoElement implements IsElement<HTMLElement>, Attachable {

    private final HTMLElement root;
    private final HTMLInputElement toggle;
    private final HTMLElement label;
    private final HTMLButtonElement destroy;
    private final HTMLInputElement summary;
    private HandlerRegistration handlerRegistration;

    TodoElement(Todo todo) {
        root = li().data("item", todo.id)
                .add(div().css("view")
                        .add(toggle = input(checkbox).css("toggle")
                                .checked(todo.completed)
                                .element())
                        .add(label = label().textContent(todo.text).element())
                        .add(destroy = button().css("destroy").element()))
                .add(summary = input(text).css("edit").element())
                .element();
        root.classList.toggle("completed", todo.completed);
        toggle.checked = todo.completed;
        Attachable.register(root, this);
    }

    @Override
    public HTMLElement element() {
        return root;
    }

    @Override
    public void attach(MutationRecord mutationRecord) {
        handlerRegistration = HandlerRegistrations.compose(
                bind(toggle, change, ev -> element()),
                bind(label, dblclick, ev -> ...),
                bind(destroy, click, ev -> ...),
                bind(summary, keydown, ev -> ...),
                bind(summary, blur, ev -> ...));
    }

    @Override
    public void detach(MutationRecord mutationRecord) {
        if (handlerRegistration != null) {
            handlerRegistration.removeHandler();
        }
    }
}
  • Method Summary

    Modifier and Type
    Method
    Description
     
  • Method Details

    • element

      E element()
      Returns:
      the element of the custom component