Detail Drawer¶
A panel that slides in from the right edge to show the details of one item, with a header, a body that scrolls, and optional footer buttons. It is a Dialog on the same panel and the same modal behavior, docked to the edge.
Decision¶
| When | Use |
|---|---|
| Opening a row of a Filtered List or a Data Table to show everything about it | Detail Drawer |
| Editing a record with change tracking | Editor Dialog |
| A short task | Dialog |
Usage¶
import { detailDrawerOpener, createDataTable, createDefinitionList } from './configurationpage?name=myplugin_stolon.js';
var show = detailDrawerOpener(function (row) {
return {
title: row.name,
subtitle: row.kind + ' on ' + row.peer,
badge: { label: row.state, color: row.state },
body: createDefinitionList({ items: [{ label: 'Items', value: row.items }, { label: 'Size', value: row.size }] }).element,
buttons: [{ text: 'Done', className: 'stolon-button primary' }]
};
});
var table = createDataTable({ columns: columns, rows: rows, onOpen: show });
openDetailDrawer(options) opens one directly and returns { element, content, close, dismiss, isOpen, setTitle, setContent, destroy }, where content is the body.
States and Modifiers¶
- The header shows
title, an optionalsubtitleunder it, and an optionalbadgebeside it,{ label, color }, wherecoloris a status color name, a hex code, or a Badge state name. The close button sits in the top right corner, inset by the panel's padding, as in every dialog. - The body scrolls on its own between the header and the footer.
bodyis HTML or a node. buttonsis the footer, a dialog button row pinned to the bottom, as Dialog takes them. A destructive button sits apart on the left.sizetakes its width from the dialog scale:smallis 40% of the window,medium60% (the default), andlarge80%. Below 600px the drawer is a full screen sheet that slides up.setContent({ title, subtitle, badge, body, buttons })swaps what it shows without closing it. A footer button that swaps the content, such as Next, keeps focus on the same button in the new footer.detailDrawerOpener(render, options)returns a function foronOpen. The first item opens a drawer, and each later item swaps its content in while it is open.- Escape, the backdrop, and the close button close it, asking
beforeClosefirst. Focus moves in, stays inside, and returns to the row that opened it, and the page behind does not scroll. - The slide is off under
prefers-reduced-motion: reduce.
Gotchas¶
- A string
bodyis HTML, so escape data in it. - The drawer is modal, so the rows behind it cannot be clicked while it is open. Swap items from inside it, such as with Previous and Next.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
openDetailDrawer¶
function openDetailDrawer(opts?: DetailDrawerOptions): DetailDrawerHandle
Opens a detail drawer, a dialog that slides in from the right edge, with a header of a title, an optional subtitle and badge, and the close button in its corner, a body that scrolls, and an optional footer of buttons. Below the compact width it is a full screen sheet that slides up. It closes, traps focus, locks the page scroll, and returns focus as every dialog does.
| Option | Type | What it does |
|---|---|---|
| Handle member | Type |
|---|---|
element |
HTMLDivElement |
content |
HTMLDivElement |
close |
(value?: unknown): void |
dismiss |
(): void |
isOpen |
(): boolean |
setTitle |
(text: string): void |
setContent |
(next: DetailDrawerContent): void |
destroy |
(): void |
detailDrawerOpener¶
function detailDrawerOpener<T>(render: (item: T) => DetailDrawerContent, opts?: DetailDrawerOptions): (item: T) => DetailDrawerHandle
Returns a function that shows an item in a detail drawer, for a Filtered List's or Data Table's onOpen. It opens the drawer for the first item, and while that drawer is open it swaps in the next item's content without closing it.
| Option | Type | What it does |
|---|---|---|
| Type | What it is |
|---|---|
DetailDrawerContent |
What a detail drawer shows: a title, an optional subtitle and badge, the body, and the footer buttons. |
| Class | What it looks like |
|---|---|
stolon-dialog.stolon-drawer |
A dialog overlay whose panel docks to the right edge of the window at full height |
stolon-dialog-content.stolon-drawer-content |
The drawer panel, as wide as a dialog of its size, that slides in from the right with its header and footer fixed and its body scrolling between them |
stolon-drawer-head |
The drawer header, the title with its badge and the subtitle under it, clear of the close button |
stolon-drawer-badge |
The badge beside the drawer title |
stolon-drawer-subtitle |
The dimmed line under the drawer title |
stolon-drawer-content |
The drawer body, which scrolls on its own between the header and the footer, edge to edge so its scroll bar sits at the panel edge |
Example¶
Example Code¶
<!-- title: Detail Drawer -->
<!-- min-height: 520 -->
<div id="table"></div>
<p class="fieldDescription">Select a row to open its details. Previous and Next swap the content without closing the drawer.</p>
<script type="module">
const base = await window.__baseReady;
const rows = [
{ id: 1, name: 'Movies', kind: 'Library', items: 1204, size: '2.1 TB', state: 'Synced', peer: 'Den' },
{ id: 2, name: 'Shows', kind: 'Library', items: 8711, size: '6.4 TB', state: 'Queued', peer: 'Cabin' },
{ id: 3, name: 'Music', kind: 'Library', items: 23090, size: '412 GB', state: 'Errored', peer: 'Office' },
{ id: 4, name: 'Home Videos', kind: 'Folder', items: 96, size: '88 GB', state: 'Synced', peer: 'Den' }
];
const stepTo = (row, by) => rows[(rows.indexOf(row) + by + rows.length) % rows.length];
// One opener serves the table, and while its drawer is open it swaps the content in place.
const show = base.detailDrawerOpener((row) => ({
title: row.name,
subtitle: row.kind + ' on ' + row.peer,
badge: { label: row.state, color: row.state },
body: base.createDefinitionList({ items: [
{ label: 'Items', value: row.items.toLocaleString() },
{ label: 'Size', value: row.size },
{ label: 'Server', value: row.peer },
{ label: 'Path', value: '/media/' + row.name.toLowerCase().replace(/ /g, '-'), mono: true }
] }).element,
buttons: [
{ text: 'Previous', action: () => show(stepTo(row, -1)) },
{ text: 'Next', action: () => show(stepTo(row, 1)) },
{ text: 'Done', className: 'stolon-button stolon-primary' }
]
}), { size: 'small' });
const table = base.createDataTable({
columns: [{ key: 'name', label: 'Name' }, { key: 'kind', label: 'Kind' }, { key: 'state', label: 'State' }, { key: 'peer', label: 'Server' }],
rows,
onOpen: show
});
document.getElementById('table').appendChild(table.element);
</script>