Status Text¶
A small status line after a save or an error, colored by class rather than inline style.
Decision¶
| When | Use |
|---|---|
| The result of a save in one sentence, beside the Save button | Status Text |
| A message that should float over the page | Toast |
Usage¶
<span id="serverListStatus" class="stolon-status-text" role="status"></span>
shared.setStatus('serverListStatus', 'Server order saved.', false);
shared.setStatus('serverListStatus', 'Could not save.', true, { timeout: 0 });
Classes: stolon-status-text, with the state class stolon-success, stolon-error, stolon-warn, or stolon-info and stolon-icon-text, and stolon-status-ok or stolon-status-bad beside it. shared.saveConfigWith calls setStatus for you.
States and Modifiers¶
shared.setStatus(elementIdOrEl, message, isError, opts)writes the message with the icon of its state beside it, as a Field Message shows it.isErrorpickserror, elsesuccess.opts.statepickssuccess,error,warn, orinfooverisError, such asinfofor a line like "Checking…".warnanderroralso takestolon-status-bad, and the othersstolon-status-ok.- The message clears after
opts.timeoutms, 5000 by default, and 0 keeps it. A newer message is not cleared by an older timer. An empty message clears the line at once. - Before it writes the text, it sets
role="alert"for an error androle="status"for any other state, so a screen reader announces it.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
| Type | What it is |
|---|---|
StatusOptions |
What setStatus takes beyond the message. state picks the look over isError, such as 'info' for a line like Checking. |
| Class | What it looks like |
|---|---|
stolon-status-text |
Status line under a form, such as after a save or a check, built as stolon-icon-text with the icon of its state |
stolon-status-ok |
The older ok and bad classes setStatus also sets, in the success and error colors. Each state's own color is the shared message rule |
Example¶
Example Code¶
<!-- title: Status Text -->
<div style="display: flex; flex-wrap: wrap; gap: 10px; align-items: center;">
<button type="button" id="btnOk" class="raised stolon-button stolon-small"><span>Show Saved</span></button>
<button type="button" id="btnBad" class="raised stolon-button stolon-secondary stolon-small"><span>Show Error</span></button>
<span id="saveStatus" class="stolon-status-text" role="status"></span>
</div>
<script type="module">
const base = await window.__baseReady;
const shared = base.createShared(document.getElementById('view'), 'preview-plugin', 'Preview');
shared.bindClick('btnOk', () => shared.setStatus('saveStatus', 'Server order saved.', false));
shared.bindClick('btnBad', () => shared.setStatus('saveStatus', 'Could not save.', true, { timeout: 0 }));
</script>