diff --git a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/helpers/ColorAndBackgroundBehavior.java b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/helpers/ColorAndBackgroundBehavior.java new file mode 100644 index 000000000..608333612 --- /dev/null +++ b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/helpers/ColorAndBackgroundBehavior.java @@ -0,0 +1,181 @@ +package de.agilecoders.wicket.core.markup.html.bootstrap.helpers; + +import org.apache.wicket.Component; +import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; + +import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.BootstrapBaseBehavior; +import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.ICssClassNameProvider; +import de.agilecoders.wicket.core.markup.html.bootstrap.utilities.BackgroundColorBehavior; +import de.agilecoders.wicket.core.markup.html.bootstrap.utilities.BackgroundColorBehavior.Color; +import de.agilecoders.wicket.core.util.Attributes; + +/** + * Color and background helpers combine the power of our .text-* utilities and .bg-* utilities in one class. + */ +public class ColorAndBackgroundBehavior extends BootstrapBaseBehavior { + + /** + * Enumeration of all possible background colors. + */ + public enum Color implements ICssClassNameProvider { + Primary("primary"), + Secondary("secondary"), + Success("success"), + Danger("danger"), + Warning("warning"), + Info("info"), + Light("light"), + Dark("dark"); + + private final String cssClassName; + + Color(String value) { + this.cssClassName = "text-bg-" + value; + } + + /** + * Css class associated with this background color. + * @return Css class associated with this background color. + */ + public String cssClassName() { + return cssClassName; + } + } + + /** + * Color that should be added to component. + */ + private IModel colorModel; + + /** + * Constructs new instance for given color. + * @param color the color that should be added to component. + */ + public ColorAndBackgroundBehavior(Color color) { + this(Model.of(color)); + } + + /** + * @param colorModel + */ + public ColorAndBackgroundBehavior(IModel colorModel) + { + this.colorModel = colorModel; + } + + @Override + public void onComponentTag(Component component, ComponentTag tag) { + super.onComponentTag(component, tag); + + Attributes.addClass(tag, colorModel.getObject()); + } + + /** + * Sets color. + * @param color + * @return this for chaining + */ + public ColorAndBackgroundBehavior color(Color color) { + colorModel.setObject(color); + return this; + } + + /** + * Sets color model. + * @param colorModel + * @return this for chaining + */ + public ColorAndBackgroundBehavior color(IModel colorModel) { + this.colorModel = colorModel; + return this; + } + + /** + * @return color + */ + public Color getColor() { + return colorModel.getObject(); + } + + /** + * @return color model + */ + public IModel getColorModel() { + return colorModel; + } + + + /** + * Constructs new behavior that adds {@link ColorAndBackgroundBehavior.Color#Primary} to component + * + * @return behavior that adds primary background color to component + */ + public static ColorAndBackgroundBehavior primary() { + return new ColorAndBackgroundBehavior(Color.Primary); + } + + /** + * Constructs new behavior that adds {@link ColorAndBackgroundBehavior.Color#Secondary} to component + * + * @return behavior that adds secondary background color to component + */ + public static ColorAndBackgroundBehavior secondary() { + return new ColorAndBackgroundBehavior(Color.Secondary); + } + + /** + * Constructs new behavior that adds {@link ColorAndBackgroundBehavior.Color#Success} to component + * + * @return behavior that adds success background color to component + */ + public static ColorAndBackgroundBehavior success() { + return new ColorAndBackgroundBehavior(Color.Success); + } + + /** + * Constructs new behavior that adds {@link ColorAndBackgroundBehavior.Color#Danger} to component + * + * @return behavior that adds danger background color to component + */ + public static ColorAndBackgroundBehavior danger() { + return new ColorAndBackgroundBehavior(Color.Danger); + } + + /** + * Constructs new behavior that adds {@link ColorAndBackgroundBehavior.Color#Warning} to component + * + * @return behavior that adds warning background color to component + */ + public static ColorAndBackgroundBehavior warning() { + return new ColorAndBackgroundBehavior(Color.Warning); + } + + /** + * Constructs new behavior that adds {@link ColorAndBackgroundBehavior.Color#Info} to component + * + * @return behavior that adds info background color to component + */ + public static ColorAndBackgroundBehavior info() { + return new ColorAndBackgroundBehavior(Color.Info); + } + + /** + * Constructs new behavior that adds {@link ColorAndBackgroundBehavior.Color#Light} to component + * + * @return behavior that adds light background color to component + */ + public static ColorAndBackgroundBehavior light() { + return new ColorAndBackgroundBehavior(Color.Light); + } + + /** + * Constructs new behavior that adds {@link ColorAndBackgroundBehavior.Color#Dark} to component + * + * @return behavior that adds dark background color to component + */ + public static ColorAndBackgroundBehavior dark() { + return new ColorAndBackgroundBehavior(Color.Dark); + } +} diff --git a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/panel/BootstrapGenericPanel.java b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/panel/BootstrapGenericPanel.java index 2990b3d5d..bb6ed391a 100644 --- a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/panel/BootstrapGenericPanel.java +++ b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/panel/BootstrapGenericPanel.java @@ -13,17 +13,14 @@ import de.agilecoders.wicket.core.util.Components; /** - * A convenient implementation of the Bootstrap styles Panel of a Wicket {@link GenericPanel}. + * A convenient implementation of the Bootstrap-styled Card of a Wicket {@link GenericPanel}. * - * documentation: http://getbootstrap.com/components/#panels + * documentation: https://getbootstrap.com/docs/5.3/components/card/ * * Implement as you would a standard Wicket {@link GenericPanel}. * - * Adding components to this panel will insert them below the markup for the body and aove the markup for the - * footer, per the Bootstrap documentation. This is useful for: - * - * panels with tables - http://getbootstrap.com/components/#panels-tables - * panel with list groups - http://getbootstrap.com/components/#panels-list-group + * Adding components to this panel will insert them below the markup for the body and above the markup for the + * footer, per the Bootstrap documentation. * * @author Eric Hamel * diff --git a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/BackgroundColorBehavior.java b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/BackgroundColorBehavior.java index cc02a1cb7..3c3fb33f9 100644 --- a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/BackgroundColorBehavior.java +++ b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/BackgroundColorBehavior.java @@ -2,8 +2,11 @@ import org.apache.wicket.Component; import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.BootstrapBaseBehavior; +import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.ICssClassNameProvider; import de.agilecoders.wicket.core.util.Attributes; /** @@ -16,7 +19,7 @@ public class BackgroundColorBehavior extends BootstrapBaseBehavior { /** * Enumeration of all possible background colors. */ - public enum Color { + public enum Color implements ICssClassNameProvider { Primary("primary"), Secondary("secondary"), Danger("danger"), @@ -28,10 +31,10 @@ public enum Color { White("white"), Transparent("transparent"); - private final String value; + private final String cssClassName; Color(String value) { - this.value = value; + this.cssClassName = "bg-" + value; } /** @@ -39,14 +42,14 @@ public enum Color { * @return Css class associated with this background color. */ public String cssClassName() { - return String.format("bg-%s", value); + return cssClassName; } } /** * Background color that should be added to component. */ - private Color color; + private IModel colorModel; /** @@ -54,22 +57,58 @@ public String cssClassName() { * @param color the background color that should be added to component. */ public BackgroundColorBehavior(Color color) { - this.color = color; + this(Model.of(color)); } - @Override + + /** + * @param colorModel + */ + public BackgroundColorBehavior(IModel colorModel) + { + this.colorModel = colorModel; + } + + + @Override public void onComponentTag(Component component, ComponentTag tag) { super.onComponentTag(component, tag); - Attributes.addClass(tag, color.cssClassName()); + Attributes.addClass(tag, colorModel.getObject()); } - public void color(Color color) { - this.color = color; + /** + * Sets color. + * @param color + * @return this for chaining + */ + public BackgroundColorBehavior color(Color color) { + colorModel.setObject(color); + return this; + } + + /** + * Sets color model. + * @param colorModel + * @return this for chaining + */ + public BackgroundColorBehavior color(IModel colorModel) { + this.colorModel = colorModel; + return this; } + /** + * @return color + */ public Color getColor() { - return this.color; + return colorModel.getObject(); + } + + /** + * @return color model + */ + public IModel getColorModel() { + return colorModel; } /** diff --git a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/BorderBehavior.java b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/BorderBehavior.java index 511ac021f..f20a4977c 100644 --- a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/BorderBehavior.java +++ b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/BorderBehavior.java @@ -2,13 +2,16 @@ import org.apache.wicket.Component; import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.BootstrapBaseBehavior; +import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.ICssClassNameProvider; import de.agilecoders.wicket.core.util.Attributes; /** * Behavior that adds different border utility classes to components. - * https://getbootstrap.com/docs/4.1/utilities/borders/ + * https://getbootstrap.com/docs/5.3/utilities/borders/ * * @author Jan Ferko */ @@ -17,41 +20,51 @@ public class BorderBehavior extends BootstrapBaseBehavior { /** * Border colors built on our theme colors. */ - public enum Color { + public enum Color implements ICssClassNameProvider { Primary("primary"), + Primary_subtle("primary-subtle"), Secondary("secondary"), + Secondary_subtle("secondary-subtle"), Success("success"), + Success_subtle("success-subtle"), Danger("danger"), + Danger_subtle("danger-subtle"), Warning("warning"), + Warning_subtle("warning-subtle"), Info("info"), + Info_subtle("info-subtle"), Light("light"), + Light_subtle("light-subtle"), Dark("dark"), + Dark_subtle("dark-subtle"), + Black("black"), White("white"); - private final String value; + private final String cssClassName; Color(String value) { - this.value = value; + cssClassName = "border-" + value; } /** * Returns css class name of given border color */ public String cssClassName() { - return String.format("border-%s", value); + return cssClassName; } } /** * Classes to easily round its corners. */ - public enum Radius { + public enum Radius implements ICssClassNameProvider { All("rounded"), Top("rounded-top"), - Right("rounded-right"), + Right("rounded-end"), Bottom("rounded-bottom"), - Left("rounded-left"), + Left("rounded-start"), Circle("rounded-circle"), + Pill("rounded-pill"), None("rounded-0"); private final String value; @@ -71,16 +84,16 @@ public String cssClassName() { /** * Enum of available border types. */ - public enum Type { + public enum Type implements ICssClassNameProvider { All("border"), Top("border-top"), - Right("border-right"), + Right("border-end"), Bottom("border-bottom"), - Left("border-left"), + Left("border-start"), ExceptTop("border-top-0"), - ExceptRight("border-right-0"), + ExceptRight("border-end-0"), ExceptBottom("border-bottom-0"), - ExceptLeft("border-left-0"), + ExceptLeft("border-start-0"), None("border-0"); private final String value; @@ -96,46 +109,89 @@ public String cssClassName() { return value; } } + + /** + * Enum of available border types. + */ + public enum Width implements ICssClassNameProvider { + Width_1(1), + Width_2(2), + Width_3(3), + Width_4(4), + Width_5(5) + ; + + private final String cssClassName; + + Width(int width) { + this.cssClassName = "border-" + width; + } + + /** + * Returns css class of given border type. + */ + public String cssClassName() { + return cssClassName; + } + } /** * Border color that should be added to component. */ - private BorderBehavior.Color color; + private IModel colorModel; /** * Border rounding type. */ - private BorderBehavior.Radius radius; + private IModel radiusModel; /** * Type of border. */ - private BorderBehavior.Type type; + private IModel typeModel; + + /** + * Width of border. + */ + private IModel widthModel; /** * Constructs new instance of default border. */ public BorderBehavior() { - this.color = Color.Secondary; - this.radius = Radius.None; - this.type = Type.None; + this.colorModel = Model.of(Color.Secondary); + this.radiusModel = Model.of(Radius.None); + this.typeModel = Model.of(Type.None); + this.widthModel = Model.of(); } @Override public void onComponentTag(Component component, ComponentTag tag) { super.onComponentTag(component, tag); - Attributes.addClass(tag, type.cssClassName(), color.cssClassName(), radius.cssClassName()); + Attributes.addClass(tag, colorModel.getObject()); + Attributes.addClass(tag, radiusModel.getObject()); + Attributes.addClass(tag, typeModel.getObject()); + Attributes.addClass(tag, widthModel.getObject()); } - + /** * Sets new border color. * * @param color the new border color */ public BorderBehavior color(Color color) { - this.color = color; - + colorModel.setObject(color); + return this; + } + + /** + * Sets new border color. + * + * @param colorModel the new border color + */ + public BorderBehavior color(IModel colorModel) { + this.colorModel = colorModel; return this; } @@ -145,8 +201,17 @@ public BorderBehavior color(Color color) { * @param radius the new rounding border corners type. */ public BorderBehavior radius(Radius radius) { - this.radius = radius; + radiusModel.setObject(radius); + return this; + } + /** + * Sets new type of rounding border corners. + * + * @param radiusModel the model for the rounding border corners type + */ + public BorderBehavior radius(IModel radiusModel) { + this.radiusModel = radiusModel; return this; } @@ -156,8 +221,37 @@ public BorderBehavior radius(Radius radius) { * @param type the type of border */ public BorderBehavior type(Type type) { - this.type = type; + typeModel.setObject(type); + return this; + } + + /** + * Sets new border type. + * + * @param typeModel the model for the type of border + */ + public BorderBehavior type(IModel typeModel) { + this.typeModel = typeModel; + return this; + } + + /** + * Sets new border width. + * + * @param width the width of the border + */ + public BorderBehavior width(Width width) { + widthModel.setObject(width); + return this; + } + /** + * Sets new border width. + * + * @param widthModel the model for the width of the border + */ + public BorderBehavior width(IModel widthModel) { + this.widthModel = widthModel; return this; } } diff --git a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/ColorBehavior.java b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/ColorBehavior.java index 11b4dc959..63c536125 100644 --- a/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/ColorBehavior.java +++ b/bootstrap-core/src/main/java/de/agilecoders/wicket/core/markup/html/bootstrap/utilities/ColorBehavior.java @@ -2,14 +2,18 @@ import org.apache.wicket.Component; import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.BootstrapBaseBehavior; +import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.ICssClassNameProvider; import de.agilecoders.wicket.core.util.Attributes; /** * Adds color utility classes to components. - * See: https://getbootstrap.com/docs/4.1/utilities/colors/#color + * See: https://getbootstrap.com/docs/5.3/utilities/colors/ * + * TODO add more colors for BS 5 * @author Jan Ferko */ public class ColorBehavior extends BootstrapBaseBehavior { @@ -17,26 +21,36 @@ public class ColorBehavior extends BootstrapBaseBehavior { /** * Enum of available text colors. */ - public enum Color { + public enum Color implements ICssClassNameProvider { Primary("primary"), + Primary_emphasis("primary-emphasis"), Secondary("secondary"), + Secondary_emphasis("secondary-emphasis"), Success("success"), + Success_emphasis("success-emphasis"), Danger("danger"), + Danger_emphasis("danger-emphasis"), Warning("warning"), + Warning_emphasis("warning-emphasis"), Info("info"), + Info_emphasis("info-emphasis"), Light("light"), + Light_emphasis("light-emphasis"), Dark("dark"), + Dark_emphasis("dark-emphasis"), Body("body"), - Muted("muted"), + Body_emphasis("body-emphasis"), + Body_secondary("body-secondary"), + Body_tertiary("body-tertiary"), White("white"), Black("black"), Black50("black-50"), White50("white-50"); - private final String value; + private final String cssClassName; Color(String value) { - this.value = value; + this.cssClassName = "text-" + value; } /** @@ -44,28 +58,70 @@ public enum Color { * @return Css class associated with this color. */ public String cssClassName() { - return String.format("text-%s", this.value); + return cssClassName; } } /** * Color that should be added to component. */ - private final Color color; + private IModel colorModel; /** * Constructs new instance for given color. * @param color the color that should be added to component. */ public ColorBehavior(Color color) { - this.color = color; + this(Model.of(color)); } + + /** + * @param colorModel + */ + public ColorBehavior(IModel colorModel) + { + this.colorModel = colorModel; + } + - @Override + @Override public void onComponentTag(Component component, ComponentTag tag) { super.onComponentTag(component, tag); - Attributes.addClass(tag, color.cssClassName()); + Attributes.addClass(tag, colorModel.getObject()); + } + /** + * Sets color. + * @param color + * @return this for chaining + */ + public ColorBehavior color(Color color) { + colorModel.setObject(color); + return this; + } + + /** + * Sets color model. + * @param colorModel + * @return this for chaining + */ + public ColorBehavior color(IModel colorModel) { + this.colorModel = colorModel; + return this; + } + + /** + * @return color + */ + public Color getColor() { + return colorModel.getObject(); + } + + /** + * @return color model + */ + public IModel getColorModel() { + return colorModel; } /** @@ -77,13 +133,29 @@ public static ColorBehavior primary() { } /** - * Constructs new behavior that adds {@link Color#Success} to component + * Constructs new behavior that adds {@link Color#Primary_emphasis} to component + * @return behavior that adds primary emphasis color to component + */ + public static ColorBehavior primaryEmphasis() { + return new ColorBehavior(Color.Primary_emphasis); + } + + /** + * Constructs new behavior that adds {@link Color#Secondary} to component * @return behavior that adds secondary color to component */ public static ColorBehavior secondary() { return new ColorBehavior(Color.Secondary); } + /** + * Constructs new behavior that adds {@link Color#Secondary_emphasis} to component + * @return behavior that adds secondary emphasis color to component + */ + public static ColorBehavior secondaryEmphasis() { + return new ColorBehavior(Color.Secondary_emphasis); + } + /** * Constructs new behavior that adds {@link Color#Success} to component * @return behavior that adds success color to component @@ -92,6 +164,14 @@ public static ColorBehavior success() { return new ColorBehavior(Color.Success); } + /** + * Constructs new behavior that adds {@link Color#Success_emphasis} to component + * @return behavior that adds success emphasis color to component + */ + public static ColorBehavior successEmphasis() { + return new ColorBehavior(Color.Success_emphasis); + } + /** * Constructs new behavior that adds {@link Color#Danger} to component * @return behavior that adds danger color to component @@ -100,6 +180,14 @@ public static ColorBehavior danger() { return new ColorBehavior(Color.Danger); } + /** + * Constructs new behavior that adds {@link Color#Danger_emphasis} to component + * @return behavior that adds danger emphasis color to component + */ + public static ColorBehavior dangerEmphasis() { + return new ColorBehavior(Color.Danger_emphasis); + } + /** * Constructs new behavior that adds {@link Color#Warning} to component * @return behavior that adds warning color to component @@ -108,6 +196,14 @@ public static ColorBehavior warning() { return new ColorBehavior(Color.Warning); } + /** + * Constructs new behavior that adds {@link Color#Warning_emphasis} to component + * @return behavior that adds warning emphasis color to component + */ + public static ColorBehavior warningEmphasis() { + return new ColorBehavior(Color.Warning_emphasis); + } + /** * Constructs new behavior that adds {@link Color#Info} to component * @return behavior that adds info color to component @@ -116,6 +212,14 @@ public static ColorBehavior info() { return new ColorBehavior(Color.Info); } + /** + * Constructs new behavior that adds {@link Color#Info_emphasis} to component + * @return behavior that adds info emphasis color to component + */ + public static ColorBehavior infoEmphasis() { + return new ColorBehavior(Color.Info_emphasis); + } + /** * Constructs new behavior that adds {@link Color#Light} to component * @return behavior that adds light color to component @@ -124,6 +228,14 @@ public static ColorBehavior light() { return new ColorBehavior(Color.Light); } + /** + * Constructs new behavior that adds {@link Color#Light_emphasis} to component + * @return behavior that adds light emphasis color to component + */ + public static ColorBehavior lightEmphasis() { + return new ColorBehavior(Color.Light_emphasis); + } + /** * Constructs new behavior that adds {@link Color#Dark} to component * @return behavior that adds dark color to component @@ -132,6 +244,14 @@ public static ColorBehavior dark() { return new ColorBehavior(Color.Dark); } + /** + * Constructs new behavior that adds {@link Color#Dark_emphasis} to component + * @return behavior that adds dark emphasis color to component + */ + public static ColorBehavior darkEmphasis() { + return new ColorBehavior(Color.Dark_emphasis); + } + /** * Constructs new behavior that adds {@link Color#Body} to component * @return behavior that adds body color to component @@ -141,11 +261,27 @@ public static ColorBehavior body() { } /** - * Constructs new behavior that adds {@link Color#Muted} to component - * @return behavior that adds muted color to component + * Constructs new behavior that adds {@link Color#Body_emphasis} to component + * @return behavior that adds body emphasis color to component + */ + public static ColorBehavior bodyEmphasis() { + return new ColorBehavior(Color.Body_emphasis); + } + + /** + * Constructs new behavior that adds {@link Color#Body_secondary} to component + * @return behavior that adds body secondary color to component + */ + public static ColorBehavior bodySecondary() { + return new ColorBehavior(Color.Body_secondary); + } + + /** + * Constructs new behavior that adds {@link Color#Body_tertiary} to component + * @return behavior that adds body tertiary color to component */ - public static ColorBehavior muted() { - return new ColorBehavior(Color.Muted); + public static ColorBehavior bodyTertiary() { + return new ColorBehavior(Color.Body_tertiary); } /** @@ -156,6 +292,14 @@ public static ColorBehavior white() { return new ColorBehavior(Color.White); } + /** + * Constructs new behavior that adds {@link Color#Black} to component + * @return behavior that adds black color to component + */ + public static ColorBehavior black() { + return new ColorBehavior(Color.Black); + } + /** * Constructs new behavior that adds {@link Color#Black50} to component * @return behavior that adds black-50 color to component @@ -166,7 +310,6 @@ public static ColorBehavior black50() { /** * Constructs new behavior that adds {@link Color#White50} to component - * * @return behavior that adds white-50 color to component */ public static ColorBehavior white50() {