UI Toolbox logoUI Toolbox

Badge

A Badge is a small label for a status or a count, such as "New" or "12". Put it next to a title, in a list row, or on the corner of a button or a UserAvatar.

Badges in the five tones, a count of 99+, and a count on the corner of an Inbox button

How to add a badge:

<tb:Badge text="New" />
<tb:Badge text="Online" tone="Success" />
<tb:Badge count="120" tone="Error" />
<ui:VisualElement>
    <ui:Button text="Inbox" name="inbox" />
    <tb:Badge name="unread" count="5" tone="Error" corner="true" />
</ui:VisualElement>
<tb:Badge text="Draft" tone="Warning" outline="true" />
<tb:Badge name="filter" text="Clear filter" outline="true" clickable="true" />
var unread = root.Q<Badge>("unread");
mailbox.Changed += () => unread.Count = mailbox.UnreadCount; // 0 hides the badge

var filter = root.Q<Badge>("filter");
filter.Icon = Background.FromSprite(closeIcon);
filter.Clicked += ClearFilter;
Member Description
text The text of a status badge. Badge is a Label.
Tone (tone) Neutral (the default), Accent, Success, Warning or Error. It sets the class tb-badge--neutral, --accent, --success, --warning or --error.
Count (count) A number to show in place of the text. 0 hides the badge. Badge.NO_COUNT (-1, the default) shows the text.
MaxCount (max-count) The largest count that shows as a number (default 99). A larger count shows as "99+".
Dot (dot) Shows a 10 px dot and no text.
Corner (corner) Puts the badge on the top right corner of its parent, outside the layout.
Outline (outline) Shows the badge with no fill. The text takes the color of the tone.
Icon (icon) A picture in front of the text, in the color of the text. An empty Background takes it away.
Clickable (clickable) Makes the badge a button: it takes the pointer and the focus.
Clicked Raised by a click or a submit on a clickable badge.

Tips:

Styling

Class Element
tb-badge The badge, a Label: bold small text, a border and a radius of 9 px, on --tb-color-surface-alt.
tb-badge--neutral, --accent, --success, --warning, --error The tone. It sets the background, the border and the text color. Error uses --tb-color-danger.
tb-badge--outline A badge with Outline on: a transparent background, and the text in the tone color.
tb-badge--icon A badge with an Icon: the picture is the background image, 11 px, left of the text.
tb-badge--clickable A badge with Clickable on. It becomes a little transparent under the pointer, and the focused badge has a border in --tb-color-text.
tb-badge--dot A badge with Dot on: 10 px and no text. The rule is after the tones.
tb-badge--corner A badge with Corner on: position: absolute, 4 px outside the top right corner of the parent.

To make the error badges square and move the corner badges in:

.tb-badge--error { border-radius: 2px; }
.tb-badge--corner { top: 0; right: 0; }