Skip to content

Record List

A List of static rows, each a title, a secondary line, tags with an icon and an off state, and at its end a chevron that opens the row or an aside control. Each row is a boxed stolon-item-row whose title and secondary text line up down the list, and a refresh keeps the rows that did not change.

Decision

When Use
A short list of records the reader opens one at a time, such as destinations, rules, or accounts Record List
Records that are ordered and edited in place Sortable Card List
Many records with columns Data Table

Usage

import { createRecordList } from './configurationpage?name=myplugin_stolon.js';

var list = createRecordList({
    items: destinations.map(function (d) {
        return { id: d.Id, title: d.Name, secondary: d.Url, tags: d.Libraries.map(function (l) { return { label: l.Name, icon: 'video_library', off: !l.Enabled }; }) };
    }),
    onOpen: function (item) { openEditor(item.id); }
});
view.querySelector('#listHost').appendChild(list.element);

Classes: stolon-record-list, stolon-record-list-row, stolon-record-list-body, stolon-record-list-tags, stolon-record-list-open, stolon-record-list-aside, and the List's stolon-item-row parts. The handle is { element, getValue, setValue, setItems, setHeight, destroy }.

States and Modifiers

  • An item is { id, title, secondary, tags, aside }. A tag is { label, icon, color, off }, where color is a status color name or a hex code that tints it. An off tag is faded and struck through, stolon-tag-off, with a hidden word, "off" by offText.
  • With onOpen a row opens by a click, by Enter or Space, and by its chevron, "Open {value}" by openLabel.
  • aside is a node or a handle with an element, such as a button, drawn in place of the chevron. A click on it opens nothing.
  • label sets the list's aria-label.
  • rowKey names a row, id by default, so setItems keeps a row whose content did not change.
  • emptyText shows while there is no row, "Nothing to show." by default. height, maxHeight, and minHeight work as a List's do.

Reference

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

createRecordList

function createRecordList(options?: RecordListOptions): RecordListHandle

A List of static rows, each a title, a secondary line, tags with an icon and an off state, and at its end a chevron that opens the row or an aside control. Each row is a boxed item row whose title and secondary text line up down the list, and a refresh keeps the rows whose title, secondary line, and tags did not change, with their aside.

Option Type What it does
items RecordListItem[] | null array of { id, title, secondary, tags: [{ label, icon, color, off }], aside }, where color is a status color name or a hex code [optional]
Handle member Type
getValue (): RecordListItem[]
setValue (next: RecordListItem[] | null): void
setItems (next: RecordListItem[] | null): void
setHeight (height: ListHeight, maxHeight?: number | string | null): void
destroy (): void
Type What it is
RecordListTag A tag on a record row. icon is a Material icon before its label, color tints it with a status color name or a hex code, and off shows it faded and struck through, such as a destination that is turned off.
RecordListItem One record row. aside is a control drawn at the row's end in place of the chevron, such as a button or a toggle.
Class What it looks like
stolon-record-list.stolon-list.stolon-plain A List of boxed record rows a gap apart
stolon-record-list-row One record row: its title and secondary line, its tags under them, and a chevron or an aside control at its end. A row that opens takes the shared hover and focus ring
stolon-record-list-tags The row's tags, each an icon and a label, which wrap under the text
stolon-record-list-open The chevron at the end of a row that opens, and the aside control that takes its place

Example

Example Code

<!-- title: Record List -->
<div id="list"></div>
<script type="module">
const base = await window.__baseReady;
const unblock = document.createElement('button');
unblock.className = 'raised stolon-button stolon-secondary stolon-small';
unblock.type = 'button';
unblock.textContent = 'Unblock';
const list = base.createRecordList({
    items: [
        { id: 'discord', title: 'Discord', secondary: 'Every sync result', tags: [{ label: 'Movies', icon: 'movie' }, { label: 'Shows', icon: 'tv' }, { label: 'Music', icon: 'album', off: true }] },
        { id: 'email', title: 'Email', secondary: 'Failures only', tags: [{ label: 'All Libraries', icon: 'video_library' }] },
        { id: 'blocked', title: '203.0.113.7', secondary: 'Blocked after 5 failed sign ins', aside: unblock }
    ],
    onOpen: function () {}
});
document.getElementById('list').appendChild(list.element);
</script>