You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2018/03/01 15:14:49 UTC
[myfaces-tobago] 01/02: TOBAGO-1861 Badge component
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit d6fa72fbdbe85b08648cb1a52eb3a1e35e020018
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Thu Mar 1 16:01:30 2018 +0100
TOBAGO-1861 Badge component
* add a badge component
* add a badge markup for buttons
* adjust styles for standard and speyside
* add a demo
---
.../myfaces/tobago/component/RendererTypes.java | 4 +
.../org/apache/myfaces/tobago/context/Markup.java | 4 +
.../tobago/internal/component/AbstractUIBadge.java | 28 +++++
.../renderer/BadgeInsideButtonsRenderer.java | 31 +++++
.../internal/renderkit/renderer/BadgeRenderer.java | 94 +++++++++++++++
.../renderkit/renderer/ButtonRenderer.java | 20 +++-
.../renderkit/renderer/ButtonsRenderer.java | 4 +
.../renderkit/renderer/CommandRendererBase.java | 15 ++-
.../taglib/component/BadgeTagDeclaration.java | 90 ++++++++++++++
.../taglib/component/ButtonTagDeclaration.java | 8 ++
.../tobago/renderkit/css/BootstrapClass.java | 4 +
.../myfaces/tobago/renderkit/css/TobagoClass.java | 1 +
tobago-core/src/main/resources/scss/_tobago.scss | 13 ++
.../tobago/example/demo/BadgeController.java | 57 +++++++++
.../apache/myfaces/tobago/example/demo/Demo.xml | 1 +
.../20-component/020-output/25-badge/badge.xhtml | 133 +++++++++++++++++++++
.../content/20-component/020-output/output.xhtml | 5 +
.../src/main/scss/_speyside-overwrites.scss | 7 +-
18 files changed, 515 insertions(+), 4 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
index 85efc7c..c395688 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
@@ -24,6 +24,8 @@ package org.apache.myfaces.tobago.component;
*/
public enum RendererTypes {
+ Badge,
+ BadgeInsideButtons,
Bar,
Box,
Button,
@@ -101,6 +103,8 @@ public enum RendererTypes {
TreeNode,
TreeSelect;
+ public static final String BADGE = "Badge";
+ public static final String BADGE_INSIDE_BUTTONS = "BadgeInsideButtons";
public static final String BAR = "Bar";
public static final String BOX = "Box";
public static final String BUTTON = "Button";
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Markup.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Markup.java
index 6302a9c..5b4b5d3 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Markup.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Markup.java
@@ -57,6 +57,7 @@ public final class Markup implements Serializable, Iterable<String> {
public static final Markup NULL = new Markup((String) null);
public static final Markup ASCENDING = valueOf("ascending");
+ public static final Markup BADGE = valueOf("badge");
public static final Markup BIG = valueOf("big");
public static final Markup BORDERED = valueOf("bordered");
public static final Markup CENTER = valueOf("center");
@@ -98,6 +99,7 @@ public final class Markup implements Serializable, Iterable<String> {
public static final Markup NONE = valueOf("none");
public static final Markup NUMBER = valueOf("number");
public static final Markup ODD = valueOf("odd");
+ public static final Markup PILL = valueOf("pill");
public static final Markup PORTLET = valueOf("portlet");
public static final Markup PRIMARY = valueOf("primary");
public static final Markup READONLY = valueOf("readonly");
@@ -135,6 +137,7 @@ public final class Markup implements Serializable, Iterable<String> {
public static final Markup WARNING = valueOf("warning");
public static final String STRING_ASCENDING = "ascending";
+ public static final String STRING_BADGE = "badge";
public static final String STRING_BIG = "big";
public static final String STRING_BORDERED = "bordered";
public static final String STRING_CENTER = "center";
@@ -176,6 +179,7 @@ public final class Markup implements Serializable, Iterable<String> {
public static final String STRING_NONE = "none";
public static final String STRING_NUMBER = "number";
public static final String STRING_ODD = "odd";
+ public static final String STRING_PILL = "pill";
public static final String STRING_PORTLET = "portlet";
public static final String STRING_PRIMARY = "primary";
public static final String STRING_READONLY = "readonly";
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIBadge.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIBadge.java
new file mode 100644
index 0000000..8b436fd
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIBadge.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.internal.component;
+
+import org.apache.myfaces.tobago.component.Visual;
+
+import javax.faces.component.UIOutput;
+
+public abstract class AbstractUIBadge extends UIOutput implements Visual {
+
+}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeInsideButtonsRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeInsideButtonsRenderer.java
new file mode 100644
index 0000000..a2d4549
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeInsideButtonsRenderer.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.internal.renderkit.renderer;
+
+import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
+import org.apache.myfaces.tobago.renderkit.css.CssItem;
+
+public class BadgeInsideButtonsRenderer extends BadgeRenderer {
+
+ @Override
+ protected CssItem getAdditionalCssItem() {
+ return BootstrapClass.BTN;
+ }
+}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRenderer.java
new file mode 100644
index 0000000..b66afa5
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRenderer.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.internal.renderkit.renderer;
+
+import org.apache.myfaces.tobago.context.Markup;
+import org.apache.myfaces.tobago.internal.component.AbstractUIBadge;
+import org.apache.myfaces.tobago.internal.util.RenderUtils;
+import org.apache.myfaces.tobago.renderkit.RendererBase;
+import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
+import org.apache.myfaces.tobago.renderkit.css.CssItem;
+import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
+import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.io.IOException;
+
+public class BadgeRenderer extends RendererBase {
+
+ @Override
+ public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
+ final TobagoResponseWriter writer = getResponseWriter(facesContext);
+ final AbstractUIBadge badge = (AbstractUIBadge) component;
+ final Markup markup = badge.getMarkup() != null ? badge.getMarkup() : Markup.NULL;
+ final String value = RenderUtils.currentValue(badge);
+
+ writer.startElement(HtmlElements.SPAN);
+ writer.writeIdAttribute(badge.getClientId(facesContext));
+ writer.writeClassAttribute(
+ TobagoClass.BADGE,
+ TobagoClass.BADGE.createMarkup(markup),
+ BootstrapClass.BADGE,
+ getBadgeColor(markup),
+ markup.contains(Markup.PILL) ? BootstrapClass.BADGE_PILL : null,
+ getAdditionalCssItem(),
+ badge.getCustomClass());
+
+ if (value != null) {
+ writer.writeText(value);
+ }
+ }
+
+ @Override
+ public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
+ final TobagoResponseWriter writer = getResponseWriter(facesContext);
+ writer.endElement(HtmlElements.SPAN);
+ }
+
+ protected CssItem getAdditionalCssItem() {
+ return null;
+ }
+
+ private BootstrapClass getBadgeColor(final Markup markup) {
+ if (markup.contains(Markup.NONE)) {
+ return null;
+ } else if (markup.contains(Markup.PRIMARY)) {
+ return BootstrapClass.BADGE_PRIMARY;
+ } else if (markup.contains(Markup.SECONDARY)) {
+ return BootstrapClass.BADGE_SECONDARY;
+ } else if (markup.contains(Markup.SUCCESS)) {
+ return BootstrapClass.BADGE_SUCCESS;
+ } else if (markup.contains(Markup.DANGER)) {
+ return BootstrapClass.BADGE_DANGER;
+ } else if (markup.contains(Markup.WARNING)) {
+ return BootstrapClass.BADGE_WARNING;
+ } else if (markup.contains(Markup.INFO)) {
+ return BootstrapClass.BADGE_INFO;
+ } else if (markup.contains(Markup.LIGHT)) {
+ return BootstrapClass.BADGE_LIGHT;
+ } else if (markup.contains(Markup.DARK)) {
+ return BootstrapClass.BADGE_DARK;
+ } else {
+ return BootstrapClass.BADGE_SECONDARY;
+ }
+ }
+}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonRenderer.java
index 58b57f7..25d8fe8 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonRenderer.java
@@ -21,13 +21,17 @@ package org.apache.myfaces.tobago.internal.renderkit.renderer;
import org.apache.myfaces.tobago.component.Attributes;
import org.apache.myfaces.tobago.context.Markup;
+import org.apache.myfaces.tobago.internal.component.AbstractUIBadge;
+import org.apache.myfaces.tobago.internal.component.AbstractUIButton;
import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
import org.apache.myfaces.tobago.renderkit.css.CssItem;
import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
import org.apache.myfaces.tobago.util.ComponentUtils;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import java.io.IOException;
public class ButtonRenderer extends CommandRendererBase {
@@ -39,10 +43,13 @@ public class ButtonRenderer extends CommandRendererBase {
@Override
protected CssItem[] getCssItems(final FacesContext facesContext, final AbstractUICommand command) {
final boolean defaultCommand = ComponentUtils.getBooleanAttribute(command, Attributes.defaultCommand);
+ final Markup markup = command.getMarkup() != null ? command.getMarkup() : Markup.NULL;
return new CssItem[]{
BootstrapClass.BTN,
- getButtonColor(command.getMarkup(), defaultCommand)
+ getButtonColor(command.getMarkup(), defaultCommand),
+ markup.contains(Markup.BADGE) ? BootstrapClass.BADGE : null,
+ markup.contains(Markup.BADGE) && markup.contains(Markup.PILL) ? BootstrapClass.BADGE_PILL : null,
};
}
@@ -70,4 +77,15 @@ public class ButtonRenderer extends CommandRendererBase {
}
return defaultCommand ? BootstrapClass.BTN_PRIMARY : BootstrapClass.BTN_SECONDARY;
}
+
+ @Override
+ protected void encodeBadge(FacesContext facesContext, AbstractUICommand command) throws IOException {
+ final AbstractUIButton button = (AbstractUIButton) command;
+
+ for (final UIComponent child : button.getChildren()) {
+ if (child instanceof AbstractUIBadge) {
+ child.encodeAll(facesContext);
+ }
+ }
+ }
}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonsRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonsRenderer.java
index 467ccc0..39f6ce5 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonsRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ButtonsRenderer.java
@@ -21,6 +21,7 @@ package org.apache.myfaces.tobago.internal.renderkit.renderer;
import org.apache.myfaces.tobago.component.RendererTypes;
import org.apache.myfaces.tobago.context.Markup;
+import org.apache.myfaces.tobago.internal.component.AbstractUIBadge;
import org.apache.myfaces.tobago.internal.component.AbstractUIButton;
import org.apache.myfaces.tobago.internal.component.AbstractUIButtons;
import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
@@ -76,6 +77,9 @@ public class ButtonsRenderer extends RendererBase {
if (child instanceof AbstractUIButton) {
child.setRendererType(RendererTypes.ButtonInsideButtons.name());
child.encodeAll(facesContext);
+ } else if (child instanceof AbstractUIBadge) {
+ child.setRendererType(RendererTypes.BadgeInsideButtons.name());
+ child.encodeAll(facesContext);
} else {
child.encodeAll(facesContext);
}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java
index 3c612d0..dd60373 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/CommandRendererBase.java
@@ -21,6 +21,7 @@ package org.apache.myfaces.tobago.internal.renderkit.renderer;
import org.apache.myfaces.tobago.component.Attributes;
import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.internal.component.AbstractUIBadge;
import org.apache.myfaces.tobago.internal.component.AbstractUICommand;
import org.apache.myfaces.tobago.internal.component.AbstractUIFormBase;
import org.apache.myfaces.tobago.internal.component.AbstractUILink;
@@ -134,6 +135,7 @@ public abstract class CommandRendererBase extends DecodingCommandRendererBase {
writer.startElement(HtmlElements.SPAN);
HtmlRendererUtils.writeLabelWithAccessKey(writer, label);
writer.endElement(HtmlElements.SPAN);
+ encodeBadge(facesContext, command);
}
if (anchor) {
@@ -163,7 +165,9 @@ public abstract class CommandRendererBase extends DecodingCommandRendererBase {
writer.writeAttribute(Arias.LABELLEDBY, "dropdownMenuButton", false);
for (final UIComponent child : component.getChildren()) {
- if (!(child instanceof UIParameter) && child.isRendered()) {
+ if (child.isRendered()
+ && !(child instanceof UIParameter)
+ && !(child instanceof AbstractUIBadge)) {
if (child instanceof AbstractUILink) {
child.setRendererType(RendererTypes.LinkInsideCommand.name());
child.encodeAll(facesContext);
@@ -189,7 +193,11 @@ public abstract class CommandRendererBase extends DecodingCommandRendererBase {
}
writer.endElement(HtmlElements.DIV);
} else {
- super.encodeChildren(facesContext, component);
+ for (final UIComponent child : component.getChildren()) {
+ if (!(child instanceof AbstractUIBadge)) {
+ child.encodeAll(facesContext);
+ }
+ }
}
}
@@ -238,4 +246,7 @@ public abstract class CommandRendererBase extends DecodingCommandRendererBase {
protected CssItem[] getDropdownCssItems(final FacesContext facesContext, final AbstractUICommand command) {
return null;
}
+
+ protected void encodeBadge(final FacesContext facesContext, final AbstractUICommand command) throws IOException {
+ }
}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/BadgeTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/BadgeTagDeclaration.java
new file mode 100644
index 0000000..c187555
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/BadgeTagDeclaration.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.internal.taglib.component;
+
+import org.apache.myfaces.tobago.apt.annotation.Markup;
+import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasValue;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsVisual;
+
+import javax.faces.component.UIOutput;
+
+/**
+ * Renders a badge element.
+ */
+@Tag(name = "badge")
+@UIComponentTag(
+ uiComponent = "org.apache.myfaces.tobago.component.UIBadge",
+ uiComponentBaseClass = "org.apache.myfaces.tobago.internal.component.AbstractUIBadge",
+ uiComponentFacesClass = "javax.faces.component.UIOutput",
+ interfaces = {
+ // As long as no behavior event names are defined, ClientBehaviorHolder must be implemented for Majorra.
+ "javax.faces.component.behavior.ClientBehaviorHolder"
+ },
+ componentFamily = UIOutput.COMPONENT_FAMILY,
+ rendererType = {RendererTypes.BADGE, RendererTypes.BADGE_INSIDE_BUTTONS},
+ allowedChildComponenents = "NONE",
+ markups = {
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_PILL,
+ description = "Make badges more rounded."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_PRIMARY,
+ description = "Set badge color to primary color of the theme."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_SECONDARY,
+ description = "Set badge color to secondary color of the theme."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_DANGER,
+ description = "Set badge color to danger color of the theme."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_WARNING,
+ description = "Set badge color to warning color of the theme."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_SUCCESS,
+ description = "Set badge color to success color of the theme."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_INFO,
+ description = "Set badge color to info color of the theme."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_LIGHT,
+ description = "Set badge color to light color of the theme."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_DARK,
+ description = "Set badge color to dark color of the theme."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_NONE,
+ description = "Colorless badge."
+ )
+ })
+public interface BadgeTagDeclaration extends HasIdBindingAndRendered, IsVisual, HasValue {
+}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ButtonTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ButtonTagDeclaration.java
index 66d89ec..95bf6fe 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ButtonTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ButtonTagDeclaration.java
@@ -120,6 +120,14 @@ import javax.faces.component.UICommand;
@Markup(
name = org.apache.myfaces.tobago.context.Markup.STRING_NONE,
description = "Colorless button."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_BADGE,
+ description = "Display the button as a badge."
+ ),
+ @Markup(
+ name = org.apache.myfaces.tobago.context.Markup.STRING_PILL,
+ description = "Make badges more rounded if button is displayed as a badge."
)
})
public interface ButtonTagDeclaration
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
index afd6ada..e2015f2 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
@@ -62,13 +62,17 @@ public enum BootstrapClass implements CssItem {
BG_INVERSE("bg-dark"),
BADGE("badge"),
BADGE_DANGER("badge-danger"),
+ BADGE_DARK("badge-dark"),
/**
* @deprecated since 4.0.0
*/
@Deprecated
BADGE_DEFAULT("badge-default"),
BADGE_INFO("badge-info"),
+ BADGE_LIGHT("badge-light"),
+ BADGE_PILL("badge-pill"),
BADGE_PRIMARY("badge-primary"),
+ BADGE_SECONDARY("badge-secondary"),
BADGE_SUCCESS("badge-success"),
BADGE_WARNING("badge-warning"),
BORDER_DANGER("border-danger"),
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java
index 23a92cc..7e8144a 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/TobagoClass.java
@@ -115,6 +115,7 @@ public enum TobagoClass implements CssItem {
// component based classes
+ BADGE("tobago-badge"),
BAR("tobago-bar"),
BOX("tobago-box"),
BOX__HEADER("tobago-box-header"),
diff --git a/tobago-core/src/main/resources/scss/_tobago.scss b/tobago-core/src/main/resources/scss/_tobago.scss
index a56da99..b24ba99 100644
--- a/tobago-core/src/main/resources/scss/_tobago.scss
+++ b/tobago-core/src/main/resources/scss/_tobago.scss
@@ -100,6 +100,19 @@ Todo: check, if this is needed? (It doesn't work with the build system)
.tobago-label-container {
}
+/* badge -------------------------------------------------------------- */
+.tobago-badge {
+}
+
+.badge.btn {
+ border: 0;
+}
+
+.btn-group > .tobago-badge.badge.btn {
+ z-index: initial;
+ cursor: initial;
+}
+
/* bar -------------------------------------------------------------- */
.tobago-bar {
&.navbar-light .navbar-brand > .tobago-link {
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/BadgeController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/BadgeController.java
new file mode 100644
index 0000000..8b948bf
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/BadgeController.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.tobago.example.demo;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Named;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+@SessionScoped
+@Named
+public class BadgeController implements Serializable {
+
+ private List<String> badges;
+
+ public BadgeController() {
+ reset();
+ }
+
+ public void reset() {
+ badges = new ArrayList<>();
+ badges.add("primary");
+ badges.add("secondary");
+ badges.add("danger");
+ badges.add("warning");
+ badges.add("success");
+ badges.add("info");
+ badges.add("light");
+ badges.add("dark");
+ }
+
+ public void remove(final String string) {
+ badges.remove(string);
+ }
+
+ public List<String> getBadges() {
+ return badges;
+ }
+}
diff --git a/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/Demo.xml b/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/Demo.xml
index 04e4204..1317ab5 100644
--- a/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/Demo.xml
+++ b/tobago-example/tobago-example-demo/src/main/resources/org/apache/myfaces/tobago/example/demo/Demo.xml
@@ -78,6 +78,7 @@
<entry key="buttons">Button Group</entry>
<entry key="buttons_customizer">Button Group Customizer</entry>
<entry key="links">Link Group</entry>
+ <entry key="badge">Badge</entry>
<entry key="container">Container</entry>
<entry key="box">Content Box</entry>
<entry key="panel">Panel</entry>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/25-badge/badge.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/25-badge/badge.xhtml
new file mode 100644
index 0000000..749c042
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/25-badge/badge.xhtml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<ui:composition template="/main.xhtml"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:c="http://java.sun.com/jsp/jstl/core"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:ui="http://java.sun.com/jsf/facelets">
+ <ui:param name="title" value="#{demoBundle.badge}"/>
+ <p>A simple badge can be created with <code class="language-markup"><tc:badge/></code>.<br/>
+ Buttons can be displayed as a badge with the <code>badge</code> markup.</p>
+ <p>Tag Library Documentation:
+ <tc:link label="<tc:badge/>" image="#{request.contextPath}/image/feather-leaf.png"
+ link="#{demoBundle.tagDocUrl}/#{info.stableVersion}/tld/tc/badge.html"/>
+ |
+ <tc:link label="<tc:button/>" image="#{request.contextPath}/image/feather-leaf.png"
+ link="#{demoBundle.tagDocUrl}/#{info.stableVersion}/tld/tc/button.html"/></p>
+
+ <tc:section label="Basics">
+ <p>A simple badge rendered with <code class="language-markup"><tc:badge value="Simple Badge"/></code>.</p>
+ <tc:badge value="Simple Badge"/>
+
+ <tc:separator/>
+ <p>Badges can placed inside buttons.</p>
+ <pre><code class="language-markup"><tc:button label="Unreaded Messages" omit="true" markup="primary">
+ <tc:badge value="9" markup="light"/>
+</tc:button></code></pre>
+ <tc:button label="Unreaded Messages" omit="true" markup="primary">
+ <tc:badge value="9" markup="light"/>
+ </tc:button>
+
+ <tc:separator/>
+ <p>Badges can be placed inside button groups. So it's possible to use them together with buttons. </p>
+ <pre><code class="language-markup"><tc:buttons>
+ <tc:badge value="badge" markup="warning"/>
+ <tc:button image="fa-times" markup="badge" tip="remove" omit="true"/>
+</tc:buttons></code></pre>
+ <tc:buttons>
+ <tc:badge value="badge" markup="warning"/>
+ <tc:button image="fa-times" markup="badge" tip="remove" omit="true"/>
+ </tc:buttons>
+ <p/>
+ </tc:section>
+
+ <tc:section label="Markups">
+ <p>Colors can be set with markups. Markup <code>none</code> unset the color.
+ Markup <code>pill</code> make the shape more rounded.
+ If no markup is set, the secondary theme color will be applied.</p>
+ <pre><code class="language-markup"><tc:badge value="primary" markup="primary"/>
+<tc:badge value="secondary" markup="secondary"/>
+<tc:badge value="danger" markup="danger"/>
+<tc:badge value="warning" markup="warning"/>
+<tc:badge value="success" markup="success"/>
+<tc:badge value="info" markup="info"/>
+<tc:badge value="light" markup="light"/>
+<tc:badge value="dark" markup="dark"/>
+<tc:badge value="none" markup="none"/>
+<tc:badge value="pill" markup="pill"/></code></pre>
+
+ <tc:badge value="primary" markup="primary"/>
+ <tc:badge value="secondary" markup="secondary"/>
+ <tc:badge value="danger" markup="danger"/>
+ <tc:badge value="warning" markup="warning"/>
+ <tc:badge value="success" markup="success"/>
+ <tc:badge value="info" markup="info"/>
+ <tc:badge value="light" markup="light"/>
+ <tc:badge value="dark" markup="dark"/>
+ <tc:badge value="none" markup="none"/>
+ <tc:badge value="pill" markup="pill"/>
+
+ <p/>
+ </tc:section>
+
+ <tc:section label="Buttons">
+ <p>If you need badges with the functionality of buttons use the <code>badge</code> markup.</p>
+
+ <pre><code class="language-markup"><tc:button label="Badge Button" markup="badge" omit="true"/>
+<tc:button label="Pill" markup="badge pill" omit="true"/>
+<tc:button label="Warning" markup="badge warning" omit="true"/>
+<tc:button label="Link" markup="badge" link="https://www.apache.org/"/>
+<tc:button label="Disabled" markup="badge" disabled="true"/></code></pre>
+
+ <tc:button label="Badge Button" markup="badge" omit="true"/>
+ <tc:button label="Pill" markup="badge pill" omit="true"/>
+ <tc:button label="Warning" markup="badge warning" omit="true"/>
+ <tc:button label="Link" markup="badge" link="https://www.apache.org/"/>
+ <tc:button label="Disabled" markup="badge" disabled="true"/>
+
+ <p/>
+ </tc:section>
+
+ <tc:section label="Button group">
+ <p>This example shows multiple button groups with a badge and a button.
+ Clicking the button will remove the current group.</p>
+ <pre><code class="language-markup"><tc:buttons>
+ <tc:badge value="label" markup="warning"/>
+ <tc:button image="fa-times" markup="badge secondary"/>
+</tc:buttons></code></pre>
+
+ <tc:button label="Reset" action="#{badgeController.reset}">
+ <f:ajax render="badgesButtonGroup"/>
+ </tc:button>
+ <tc:panel id="badgesButtonGroup">
+ <c:forEach var="item" items="#{badgeController.badges}">
+ <span>
+ <tc:buttons>
+ <tc:badge value="#{item}" markup="#{item}"/>
+ <tc:button image="fa-times" markup="badge secondary" action="#{badgeController.remove(item)}">
+ <f:ajax render="badgesButtonGroup"/>
+ </tc:button>
+ </tc:buttons>
+ </span>
+ </c:forEach>
+ </tc:panel>
+ </tc:section>
+</ui:composition>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/output.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/output.xhtml
index 8fcdb3f..75e48fe 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/output.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/output.xhtml
@@ -37,6 +37,11 @@
<tc:label value="Some Text"/>
</tc:section>
+ <tc:section label="#{demoBundle.badge}">
+ <pre><code class="language-markup"><tc:badge value="Badge"/></code></pre>
+ <tc:badge value="Badge"/>
+ </tc:section>
+
<tc:section label="#{demoBundle.messages}">
<pre><code class="language-markup"><tc:messages/></code></pre>
<tc:messages/>
diff --git a/tobago-theme/tobago-theme-speyside/src/main/scss/_speyside-overwrites.scss b/tobago-theme/tobago-theme-speyside/src/main/scss/_speyside-overwrites.scss
index af393d4..a2660a4 100644
--- a/tobago-theme/tobago-theme-speyside/src/main/scss/_speyside-overwrites.scss
+++ b/tobago-theme/tobago-theme-speyside/src/main/scss/_speyside-overwrites.scss
@@ -483,6 +483,11 @@ p, .control-label {
hyphens: auto;
}
+// Badge
+.badge-pill {
+ border-radius: 10rem;
+}
+
// Tabs
.nav-tabs {
background-color: $gray-300;
@@ -714,7 +719,7 @@ li:last-child {
}
}
-.btn {
+.btn:not(.badge) {
padding: $btn-padding-y $btn-padding-x;
box-shadow: 1px 2px 4px 0px rgba(0, 0, 0, 0.1);
}
--
To stop receiving notification emails like this one, please contact
hnoeth@apache.org.