Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fullscreen option, fix adding/removing classes #1013

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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