Class Badge

java.lang.Object
org.apache.juneau.console.widgets.Badge

@BeanType(properties="count,dot,max,tone,label") public class Badge extends Object
An overlay badge on a header action (a bell count, for example) or a BarBadge.

A badge is exactly one of a count badge (count) or a dot badge (dot); it never carries both. The optional max clamps a large count to "<max>+" and tone selects the badge colour from the shared StatusTone palette. A count is painted with textContent — never innerHTML.

The tone is serialized as its enum name (e.g. "WARNING"); the client lowercases it into the data-juneau-badge-tone attribute. Colours map as:

Example:

// A red unread-count badge that caps at "99+". Badge badge = Badge.count(120).tone(StatusTone.ERROR).max(99).label("unread notifications"); badge.validate();

Since:
10.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    A count badge value (mutually exclusive with dot); when set must be >= 0.
    A dot (presence) badge with no number (mutually exclusive with count).
    Optional visually-hidden context for screen readers, e.g.
    Optional display clamp; a count above this renders as "<max>+".
    Optional colour tone; null leaves the badge in its default colour.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Badge
    count(int value)
    Creates a count badge.
    static Badge
    dot()
    Creates a dot (presence) badge with no number.
    label(String value)
    Sets the visually-hidden screen-reader context.
    max(int value)
    Sets the display clamp.
    Sets the color tone.
    void
    Fail-closed bean validation; called by the enclosing bean's validate().

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • count

      public Integer count
      A count badge value (mutually exclusive with dot); when set must be >= 0.
    • dot

      public Boolean dot
      A dot (presence) badge with no number (mutually exclusive with count).
    • max

      public Integer max
      Optional display clamp; a count above this renders as "<max>+". When set must be >= 1.
    • tone

      public StatusTone tone
      Optional colour tone; null leaves the badge in its default colour.
    • label

      public String label
      Optional visually-hidden context for screen readers, e.g. "unread notifications".
  • Constructor Details

  • Method Details

    • count

      public static Badge count(int value)
      Creates a count badge.
      Parameters:
      value - The count. Must be >= 0.
      Returns:
      A new Badge.
    • dot

      public static Badge dot()
      Creates a dot (presence) badge with no number.
      Returns:
      A new Badge.
    • tone

      public Badge tone(StatusTone value)
      Sets the color tone.
      Parameters:
      value - The tone. Can be null to use the default colour.
      Returns:
      This object.
    • max

      public Badge max(int value)
      Sets the display clamp.
      Parameters:
      value - The clamp. Must be >= 1.
      Returns:
      This object.
    • label

      public Badge label(String value)
      Sets the visually-hidden screen-reader context.
      Parameters:
      value - The label.
      Returns:
      This object.
    • validate

      public void validate()
      Fail-closed bean validation; called by the enclosing bean's validate().
      Throws:
      IllegalArgumentException - If this badge is not well-formed.