Banner¶
A callout with a Dismiss button. It remembers a dismissal only when the caller gives a key and a storage object, so Stolon never touches browser storage on its own.
Decision¶
| When | Use |
|---|---|
| A notice the user may close, such as a tip | Banner |
| A notice that stays | Callout |
Usage¶
import { createBanner } from './configurationpage?name=myplugin_stolon.js';
var banner = createBanner({
kind: 'warn',
text: 'Back up first.',
key: 'backup-tip',
storage: { get: function (k) { return store[k]; }, set: function (k, v) { store[k] = v; } }
});
container.appendChild(banner.element);
Classes: stolon-banner, stolon-banner-close. The handle is { element, getValue, setValue, show, dismiss, destroy }.
Parts: stolon-banner-body, stolon-banner-title.
States and Modifiers¶
kindisinfo(default),success,warn,error, orneutral. The banner also takes the matching Callout class, and shows the icon of its kind beside the text.titleadds a bold first line.dismissible: falsehides the button.dismissLabelreplaces "Dismiss".- Dismissal is remembered only with both
keyandstorage. With a key and a storage whoseget(key)is true, the banner starts hidden. getValue()returns{ kind, title, text, dismissed }, andsetValue({ kind, title, text })changes what it shows.show()brings back a dismissed banner, anddismiss()closes it from code.onDismiss()runs when it is dismissed.actionsare small buttons under the text,[{ text, primary, className, onClick(button) }], such as Apply.primarydraws the main one, and the rest are secondary.setActions(actions)replaces them, andnullremoves them.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createBanner¶
function createBanner(options?: BannerOptions): BannerHandle
A callout with a Dismiss button. It remembers a dismissal only when the caller gives a key and a storage object, so Stolon never touches browser storage on its own.
| Option | Type | What it does |
|---|---|---|
kind |
BannerKind | string |
'info', 'success', 'warn', 'error', or 'neutral' (default 'info') |
title |
string |
bold first line [optional] |
text |
string |
the message sentence [optional] |
dismissible |
boolean |
false hides the button (default true) |
dismissLabel |
string |
title and aria-label of the button (default 'Dismiss') |
key |
string |
name that identifies this banner in the storage [optional] |
storage |
BannerStorage | null |
{ get: function(key), set: function(key, true) } that remembers a dismissal [optional] |
actions |
BannerAction[] | null |
array of { text, primary, className, onClick(button) } drawn as small buttons under the text, such as Apply [optional] |
onDismiss |
(): void |
function() called when the user dismisses it [optional] |
| Handle member | Type |
|---|---|
getValue |
(): BannerValue |
setValue |
(next: BannerValue): void |
show |
(): void |
dismiss |
(): void |
setActions |
(actions: BannerAction[] | null | undefined): void |
destroy |
(): void |
| Type | What it is |
|---|---|
BannerKind |
The tone of a banner, which picks its tint and glyph. |
BannerStorage |
Where a banner remembers a dismissal, given by the caller so Stolon never touches browser storage itself. |
BannerValue |
What a banner's getValue returns, and the kind, title, and text its setValue takes. |
BannerAction |
A button under a banner's text. primary draws it as the main action, and onClick gets the button, which it may disable while it works. |
| Class | What it looks like |
|---|---|
stolon-banner-actions |
The buttons under a banner's text, such as Apply |
Example¶
Example Code¶
<!-- title: Banner -->
<div id="mount"></div>
<script type="module">
const base = await window.__baseReady;
const view = document.getElementById('view');
const mount = document.getElementById('mount');
['info', 'success', 'warn', 'error', 'neutral'].forEach((kind) => {
mount.appendChild(base.createBanner({ kind, title: kind === 'warn' ? 'Back up first' : '', text: 'This is a ' + kind + ' banner.' }).element);
});
</script>