Skip to content

Commit

Permalink
Add fullscreen option, fix adding/removing classes (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrozkovec authored Dec 8, 2023
1 parent a0c58cf commit 12cd947
Showing 1 changed file with 60 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,7 +42,7 @@ public class Modal<T> extends GenericPanel<T> {
public static final String BUTTON_MARKUP_ID = "button";

/**
* @see <a href="https://getbootstrap.com/docs/4.3/components/modal/#optional-sizes">Modal Sizes</a>
* @see <a href="https://getbootstrap.com/docs/5.3/components/modal/#optional-sizes">Optional sizes</a>
*/
public enum Size implements ICssClassNameProvider {
Small("sm"),
Expand Down Expand Up @@ -67,6 +70,39 @@ public String cssClassName() {
}
}

/**
* @see <a href="https://getbootstrap.com/docs/5.3/components/modal/#fullscreen-modal">Fullscreen Modal</a>
*/
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
}
Expand All @@ -92,6 +128,7 @@ public enum Backdrop {
private AjaxEventBehavior closeBehavior;

private Size size = Size.Default;
private Fullscreen fullscreen = Fullscreen.None;

/**
* Constructor.
Expand Down Expand Up @@ -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<Size> 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<Fullscreen> 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);
}
};
}
Expand All @@ -234,6 +267,17 @@ public Modal<T> 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<T> fullscreen(Fullscreen fullscreen) {
this.fullscreen = fullscreen;
return this;
}

@Override
protected void onComponentTag(ComponentTag tag) {
Expand Down

0 comments on commit 12cd947

Please sign in to comment.