diff --git a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/dialog/Modal.java b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/dialog/Modal.java index c1a6b174f..1d49da0a1 100644 --- a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/dialog/Modal.java +++ b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/dialog/Modal.java @@ -1,7 +1,10 @@ package de.agilecoders.wicket.core.markup.html.bootstrap.dialog; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.wicket.AttributeModifier; import org.apache.wicket.Component; @@ -39,7 +42,7 @@ public class Modal extends GenericPanel { public static final String BUTTON_MARKUP_ID = "button"; /** - * @see Modal Sizes + * @see Optional sizes */ public enum Size implements ICssClassNameProvider { Small("sm"), @@ -67,6 +70,39 @@ public String cssClassName() { } } + /** + * @see Fullscreen Modal + */ + public enum Fullscreen implements ICssClassNameProvider { + None(""), + Always("fullscreen"), + Sm_down("fullscreen-sm-down"), + Md_down("fullscreen-md-down"), + Lg_down("fullscreen-lg-down"), + Xl_down("fullscreen-xl-down"), + Xxl_down("fullscreen-xxl-down"); + + + private final String cssClassName; + + /** + * Construct. + * + * @param cssClassName the css class name of button type + */ + Fullscreen(final String cssClassName) { + this.cssClassName = cssClassName; + } + + /** + * @return css class name of button type + */ + @Override + public String cssClassName() { + return "modal-" + cssClassName; + } + } + public enum Backdrop { TRUE, FALSE, STATIC } @@ -92,6 +128,7 @@ public enum Backdrop { private AjaxEventBehavior closeBehavior; private Size size = Size.Default; + private Fullscreen fullscreen = Fullscreen.None; /** * Constructor. @@ -205,21 +242,17 @@ protected WebMarkupContainer createDialog(String id) { protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); - Attributes.removeClass(tag, Size.Large.cssClassName(), Size.Small.cssClassName()); - - switch (size) { - case Large: - Attributes.addClass(tag, Size.Large.cssClassName()); - break; - case Small: - Attributes.addClass(tag, Size.Small.cssClassName()); - break; - case Extra_large: - Attributes.addClass(tag, Size.Extra_large.cssClassName()); - break; - default: - // do nothing. the CSS classes are removed before the switch - } + Set sizes = Arrays.stream(Size.values()).collect(Collectors.toSet()); + sizes.remove(Size.Default); + sizes.forEach(s -> Attributes.removeClass(tag, s)); + if(sizes.contains(size)) + Attributes.addClass(tag, size); + + Set fulscreens = Arrays.stream(Fullscreen.values()).collect(Collectors.toSet()); + fulscreens.remove(Fullscreen.None); + fulscreens.forEach(s -> Attributes.removeClass(tag, s)); + if(fulscreens.contains(fullscreen)) + Attributes.addClass(tag, fullscreen); } }; } @@ -234,6 +267,17 @@ public Modal size(Size size) { this.size = size; return this; } + + /** + * Sets fullscreen modal. + * + * @param size The size of the modal dialog. + * @return {@code this}, for method chaining + */ + public Modal fullscreen(Fullscreen fullscreen) { + this.fullscreen = fullscreen; + return this; + } @Override protected void onComponentTag(ComponentTag tag) {