Status Card¶
A bordered card on the surface color with an icon, a status pill, a bold title, and one quiet line of detail. It can show a large value for a metric, and an href or onClick makes the whole card a link or a button. createStatusCardGrid lays the cards out in balanced rows.
Decision¶
| When | Use |
|---|---|
| The state of each part of a plugin, such as one card per tool on a dashboard | createStatusCardGrid |
| A headline number with a label, such as a count of items | value and valueLabel |
| A card that opens the page it describes | href, or onClick for an in-page action |
| A plain row of colored counts | Count Cards |
| A state on a row of a list or table | Badge |
Usage¶
import { createStatusCardGrid } from './configurationpage?name=myplugin_stolon.js';
var grid = createStatusCardGrid({ cards: [
{ icon: 'vpn_lock', title: 'VPN', status: 'Check', statusColor: 'orange', detail: '3 of 7 peers online', href: '#vpn' },
{ icon: 'storage', title: 'Storage', status: 'Ok', statusColor: 'green', detail: 'Media at 82%', href: '#storage' }
] });
view.querySelector('#overview').appendChild(grid.element);
var vpn = grid.getCards()[0];
vpn.setStatus('Ok', 'green');
vpn.setDetail('7 of 7 peers online');
Classes: stolon-status-cards for the grid and stolon-status-card for a card, with the parts stolon-status-card-head, stolon-status-card-icon, stolon-status-card-pill, stolon-status-card-title, stolon-status-card-value, stolon-status-card-detail, and stolon-status-card-sparkline. A card that links or acts carries stolon-clickable. The card handle is { element, getValue, setValue, setStatus, setDetail, setSparkline, destroy }, and the grid handle is { element, getCards, setCards, add, destroy }.
States and Modifiers¶
statusis the pill text, such as "Ok", "Check", "Off", or "Failed". The pill is a small Badge and never wraps or shrinks.statusColoris a status color name, a hex code, or a badge state name. With no color, a status that is a badge state, such as "Failed" or "Running", takes that state's color, and any other status is gray.detailis one dimmed line. A line too long for the card ends in an ellipsis, with the full text as its tooltip. The title does the same.valueis drawn large in even width digits, withvalueLabelsmall after it. Each part hides while it is empty.sparklineis a list of numbers drawn as a Sparkline under the value, named by the title, in the accent orsparklineColor.hrefmakes the card a link andonClickmakes it a button. Either one gives the card the shared card hover and the accent focus ring.setValue(value, label),setStatus(label, color),setDetail(text), andsetSparkline(values)change a card in place.- The grid keeps a card at least
minWidthwide, 200 by default, and balances the rows so a wrapped row never holds one card alone. The cards in a row share one height.
Gotchas¶
- A linked card is named by all of its text, so keep the title and detail short. The icon is hidden from assistive tech.
setCardsreplaces every card and returns the new handles. A handle from before it no longer drives a card on the page.- The page's
bindBalancedRowsalso balances astolon-status-cardsgroup built in markup.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createStatusCard¶
function createStatusCard(options?: StatusCardOptions): StatusCardHandle
A bordered card on the surface color with an icon, a status pill, a bold title, and one quiet line of detail. An optional large value shows a metric, and an href or onClick makes the whole card a link or a button.
| Option | Type | What it does |
|---|---|---|
icon |
string |
Material icon name at the top left [optional] |
title |
string |
bold name under the icon, cut with an ellipsis [optional] |
status |
string |
short pill text at the top right, such as 'Ok' or 'Failed', which never wraps [optional] |
statusColor |
string |
status color name, hex code, or badge state name of the pill (default the color of a badge state named by status, else gray) |
detail |
string |
one dimmed line under the title, such as '3 of 7 peers online', cut with an ellipsis and titled with its full text [optional] |
value |
unknown |
number or short text shown large under the title, such as 1204 [optional] |
valueLabel |
string |
small text after the value, such as 'items' [optional] |
sparkline |
Array<number | null | undefined> | null |
numbers drawn as a small line under the value, through createSparkline, named by the title [optional] |
sparklineColor |
string |
status color name or hex code of the line (default the accent) |
href |
string |
address the card links to, which makes the card a link [optional] |
onClick |
(event: MouseEvent): void |
function(event) called on a click, which makes the card a button when there is no href [optional] |
| Handle member | Type |
|---|---|
getValue |
(): unknown |
setValue |
(value: unknown, label?: string): void |
setStatus |
(label: string, color?: string): void |
setDetail |
(text: string): void |
setSparkline |
(values: Array<number | null | undefined> | null): void |
destroy |
(): void |
createStatusCardGrid¶
function createStatusCardGrid(options?: StatusCardGridOptions): StatusCardGridHandle
A grid of status cards in balanced rows, so a wrapped row never holds a single card. Every card in a row is the same height.
| Option | Type | What it does |
|---|---|---|
cards |
StatusCardOptions[] |
array of status card options, one card each [optional] |
minWidth |
number |
least width of a card in pixels before the row wraps (default 200) |
maxColumns |
number |
most cards in a row [optional] |
| Handle member | Type |
|---|---|
getCards |
(): StatusCardHandle[] |
setCards |
(next: StatusCardOptions[]): StatusCardHandle[] |
add |
(card: StatusCardOptions): StatusCardHandle |
destroy |
(): void |
| Class | What it looks like |
|---|---|
stolon-status-cards |
Grid of status cards a wide space apart, laid out in balanced rows by createStatusCardGrid |
stolon-status-card |
Rounded bordered card on the surface color with an icon and a status pill over a bold title and one quiet detail line. As a link or a button it takes the shared card hover and focus ring |
stolon-status-card-head |
Top row of a status card, the icon at the start and the pill at the end |
stolon-status-card-icon |
Material icon of a status card, one small control tall, in the muted text color |
stolon-status-card-pill |
Status pill at the top right of a status card, a badge that never wraps or shrinks |
stolon-status-card-title |
Bold title of a status card, cut with an ellipsis and titled with its full text |
stolon-status-card-value |
Large value of a status card, such as a count, in even width digits with a small label after it |
stolon-status-card-sparkline |
Sparkline under a status card's value, a narrow space below it |
stolon-status-card-detail |
Quiet detail line of a status card, dimmed, cut with an ellipsis, and titled with its full text |
Example¶
Example Code¶
<!-- title: Status Card -->
<div id="tools"></div>
<div id="metrics" style="margin-top: 16px;"></div>
<p><button type="button" class="raised stolon-button secondary small" id="refresh">Refresh VPN</button></p>
<span id="cardStatus" class="stolon-status-text"></span>
<script type="module">
const base = await window.__baseReady;
const note = document.getElementById('cardStatus');
const grid = base.createStatusCardGrid({ cards: [
{ icon: 'dashboard', title: 'Dashboard', status: 'Ok', statusColor: 'green', detail: 'Every tool is running', href: '#dashboard' },
{ icon: 'public', title: 'DDNS', status: 'Ok', statusColor: 'green', detail: 'Updated 4 minutes ago', href: '#ddns' },
{ icon: 'lock', title: 'Access', status: 'Off', statusColor: 'gray', detail: 'No rules are on', href: '#access' },
{ icon: 'vpn_lock', title: 'VPN', status: 'Check', statusColor: 'orange', detail: '3 of 7 peers online', href: '#vpn' },
{ icon: 'group', title: 'Users', status: 'Ok', statusColor: 'green', detail: '12 users, 2 signed in now', href: '#users' },
{ icon: 'code', title: 'Scripts', status: 'Failed', detail: 'The nightly cleanup stopped at step 3 of 5 with an error', href: '#scripts' },
{ icon: 'storage', title: 'Storage', status: 'Check', statusColor: 'orange', detail: 'Media at 82%', href: '#storage' },
{ icon: 'settings', title: 'Settings', status: 'Ok', statusColor: 'green', detail: 'Saved yesterday', href: '#settings' }
] });
document.getElementById('tools').appendChild(grid.element);
grid.element.addEventListener('click', (e) => {
const card = e.target.closest('a');
if (!card) return;
e.preventDefault();
note.textContent = 'Opens ' + card.getAttribute('href') + '.';
});
const metrics = base.createStatusCardGrid({ cards: [
{ icon: 'movie', title: 'Items', value: '1,204', valueLabel: 'in 6 libraries', status: 'Synced' },
{ icon: 'sync', title: 'Syncs', value: 47, valueLabel: 'this week', status: 'Running', sparkline: [3, 5, 4, 8, 6, 9, 12] },
{ icon: 'error_outline', title: 'Errors', value: 2, valueLabel: 'today', status: 'Check', statusColor: 'orange', detail: 'Last at 14:02', onClick: () => { note.textContent = 'Opens the errors.'; } }
] });
document.getElementById('metrics').appendChild(metrics.element);
const vpn = grid.getCards()[3];
document.getElementById('refresh').addEventListener('click', () => {
vpn.setStatus('Ok', 'green');
vpn.setDetail('7 of 7 peers online');
});
</script>