Skip to content

Badge

A short status label in a status color. There are two badges. stolon-badge takes a color name, and stolon-table-status-badge takes a state name, as the table status column uses.

Decision

When Use
A label you color yourself shared.badge.
A status code mapped to a color shared.statusBadge.
A button A real button, never a badge. The table status column renders its own button. See Paginated Table.

Usage

<span class="stolon-badge stolon-green">Active</span>
<span class="stolon-table-status-badge stolon-Queued">Queued</span>
import { BADGE_STATES } from './configurationpage?name=myplugin_stolon.js';
container.innerHTML = shared.badge('green', 'Active') + shared.statusBadge('Queued', 'Queued');

Classes: stolon-badge, stolon-table-status-badge.

States and Modifiers

  • Color names for stolon-badge: green, red, orange, purple, blue, gray, yellow, pink, and teal.
  • State names for stolon-table-status-badge: Active, Synced, Downloaded, Completed, and Enabled are green. Disabled, Errored, Error, Deleting, Pending-Deletion, and Failed are red. Expired, Queued, and Paused are orange. Locked, Running, Downloading, Pending, and Pending-Download are purple. Admin, Imported, and Pending-Replacement are blue. Ignored, Group, Skipped, and Unknown are gray.
  • BADGE_STATES is { names, colors, stateColors }, the one source of truth for mapping a status code to a badge. stateColors gives the color each state name draws in.
  • shared.badge(cls, label) escapes the label. A color name or hex code in cls colors it, medium or large sizes it, and any other word stays as a class reduced to letters, digits, _, and -.
  • shared.statusBadge(text, stateClass) draws a stolon-badge in the color stateColors gives the state, or in the color itself when stateClass is a color name or a hex code, and keeps stolon-table-status-badge and the state name as classes, such as <span class="stolon-badge stolon-orange stolon-table-status-badge stolon-Queued">.
  • Every badge Stolon draws, in the bag, the Media Card, and the Sortable Card List, comes from one badge maker, so they look the same.
  • A plugin may set the class on an existing element, such as el.className = 'stolon-table-status-badge ' + status.
  • The swatches are the same in light and dark themes.

Gotchas

  • A state name outside the list gets the base pill with no color.
  • A state with spaces is split into several classes.
  • stolon-badge and stolon-table-status-badge read the same swatch tokens, and statusBadge works anywhere, not only in tables.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

BADGE_STATES

var BADGE_STATES: { names: BadgeState[]; colors: BadgeColor[]; stateColors: Record<BadgeState, BadgeColor>; }

The state names a badge knows, in names, the color modifiers that stolon-badge takes, in colors, and the color each state draws in, in stateColors. A plugin maps its own statuses onto these so the mapping has one source.

Class What it looks like
stolon-badge Pill that shows a short status label in a status color
stolon-badge.stolon-medium A badge at the medium or large size of the scale

Example

Example Code

<!-- title: Badge -->
<!-- min-height: 0 -->
<div id="colors" style="display: flex; flex-wrap: wrap; gap: 8px;"></div>
<div id="states" style="display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px;"></div>

<script type="module">
const base = await window.__baseReady;
const shared = base.createShared(document.getElementById('view'), 'preview-plugin', 'Preview');

base.BADGE_STATES.colors.forEach(color => {
    document.getElementById('colors').insertAdjacentHTML('beforeend', shared.badge(color, color));
});
base.BADGE_STATES.names.forEach(name => {
    document.getElementById('states').insertAdjacentHTML('beforeend', shared.statusBadge(name, name));
});
</script>