Tool Shell¶
The outer layout of a page that holds several tools. A wide shell lists the tools in a sidebar beside the current tool's heading and content. A narrow shell drops the sidebar and turns the heading into a title menu that lists every tool.
Decision¶
| When | Use |
|---|---|
| A plugin page that gathers several tools, each with its own address | Tool Shell |
| Switching tools in place, without leaving the page | onSelect with event.preventDefault() |
| Sections inside one tool | Sub Tabs or Tabs, inside the shell's content |
| An overview of every tool | A Status Card grid in the shell's content |
Usage¶
import { createToolShell } from './configurationpage?name=myplugin_stolon.js';
var shell = createToolShell({
tools: [
{ key: 'dashboard', name: 'Dashboard', icon: 'dashboard', href: '#/configurationpage?name=myplugin' },
{ key: 'vpn', name: 'VPN', icon: 'vpn_lock', href: '#/configurationpage?name=myplugin_vpn', badge: { label: '2', color: 'orange' } },
{ key: 'storage', name: 'Storage', icon: 'storage', href: '#/configurationpage?name=myplugin_storage' }
],
current: 'vpn'
});
view.querySelector('#page').appendChild(shell.element);
shell.content.appendChild(vpnPage);
Classes: stolon-tool-shell, with the parts stolon-tool-shell-nav, stolon-tool-shell-list, stolon-tool-shell-entry, stolon-tool-shell-item, stolon-tool-shell-main, stolon-tool-shell-head, stolon-tool-shell-title, stolon-tool-shell-switcher, and stolon-tool-shell-content, and the modifier stolon-compact. The handle is { element, content, getCurrent, setCurrent, setTools, destroy }.
States and Modifiers¶
- A tool is
{ key, name, icon, href, badge }. A tool with anhrefis a link, so each tool keeps its own address and the back button works. A tool with nohrefis a button. onSelect(key, tool, event)runs when a tool is chosen in the sidebar or the menu, after the shell marks it current. A link follows itshrefunlessonSelectcallsevent.preventDefault(). A click with Ctrl, Cmd, or Shift, or a middle click, opens the link as the browser does.badgeis text or{ label, color }after the name, gray unless it names a color, in the sidebar and the menu.titlesets the heading, which is the current tool's name by default.setCurrent(key, title)marks another tool and sets the heading to the title or the tool's name.setTools(tools, current)replaces the tools.- The shell turns compact by its own width, when the sidebar and 480 pixels of content no longer fit side by side. It carries
stolon-compact, the sidebar hides, and the heading becomes the title menu, a button such as "VPN" with a dropdown chevron. The heading stays for a screen reader. - The sidebar is a
navlandmark named bylabel, "Tools" by default. The current entry carriesaria-current="page"and the shared selection look. - The title menu is an Overflow Menu with
text. It opens on the current tool, the arrow keys move through the list, Home and End jump, and Escape closes it and returns focus to the button.
Gotchas¶
- The shell draws no back link. The browser's own back button returns to the tool before.
- The sidebar sticks to the top of the page while the content scrolls.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createToolShell¶
function createToolShell(options?: ToolShellOptions): ToolShellHandle
The outer layout of a page that holds several tools. A wide shell lists the tools in a sidebar beside the content. A narrow shell, by its own width, drops the sidebar and turns the heading into a title menu that lists every tool.
| Option | Type | What it does |
|---|---|---|
tools |
ToolShellTool[] |
array of { key, name, icon, href, badge }, where href is the tool's own address and badge is text or { label, color } [optional] |
current |
string |
key of the tool shown, highlighted in the sidebar and the menu [optional] |
title |
string |
heading over the content (default the current tool's name) |
label |
string |
aria-label of the sidebar and the menu (default 'Tools') |
onSelect |
(key: string, tool: ToolShellTool, event: MouseEvent): void |
function(key, tool, event) called when a tool is chosen. A tool with an href follows it unless onSelect calls event.preventDefault() [optional] |
| Handle member | Type |
|---|---|
content |
HTMLElement |
getCurrent |
(): string | null |
setCurrent |
(key: string, title?: string): void |
setTools |
(next: ToolShellTool[], current?: string): void |
destroy |
(): void |
| Type | What it is |
|---|---|
ToolShellTool |
One tool in a tool shell. href is the tool's own address, and badge is text or { label, color } after its name. |
| Class | What it looks like |
|---|---|
stolon-tool-shell |
Page of several tools, a sidebar of tools beside the current tool's heading and content, built by createToolShell |
stolon-tool-shell-nav |
Sidebar that lists every tool, five large controls wide, held in view while the page scrolls |
stolon-tool-shell-item.stolon-menu-item |
One tool in the sidebar, a menu item one large control tall with its icon, name, and badge, the current one in the shared selection look |
stolon-tool-shell-main |
The current tool's heading and content, which take the width beside the sidebar |
stolon-tool-shell-title |
Heading over a tool's content in the page heading size, cut with an ellipsis |
stolon-tool-shell-switcher |
Title menu button that lists every tool, shown in place of the sidebar on a narrow shell, its text in line with the content's edge |
stolon-tool-shell.stolon-compact |
A shell too narrow for its sidebar, by its own width, with the title menu button in place of the sidebar and the heading |
Example¶
Example Code¶
<!-- title: Tool Shell -->
<div id="wide"></div>
<p>The same shell in a narrow frame turns the title into a menu of every tool.</p>
<div id="narrow" style="max-width: 360px; padding: 16px; border: 1px dashed var(--stolon-border);"></div>
<script type="module">
const base = await window.__baseReady;
const tools = [
{ key: 'dashboard', name: 'Dashboard', icon: 'dashboard', href: '#dashboard' },
{ key: 'ddns', name: 'DDNS', icon: 'public', href: '#ddns' },
{ key: 'access', name: 'Access', icon: 'lock', href: '#access' },
{ key: 'vpn', name: 'VPN', icon: 'vpn_lock', href: '#vpn', badge: { label: '4', color: 'orange' } },
{ key: 'users', name: 'Users', icon: 'group', href: '#users' },
{ key: 'scripts', name: 'Scripts', icon: 'code', href: '#scripts', badge: { label: 'Failed', color: 'red' } },
{ key: 'storage', name: 'Storage', icon: 'storage', href: '#storage' },
{ key: 'settings', name: 'Settings', icon: 'settings', href: '#settings' }
];
const cards = {
ddns: { status: 'Ok', statusColor: 'green', detail: 'Updated 4 minutes ago' },
access: { status: 'Off', statusColor: 'gray', detail: 'No rules are on' },
vpn: { status: 'Check', statusColor: 'orange', detail: '3 of 7 peers online' },
users: { status: 'Ok', statusColor: 'green', detail: '12 users, 2 signed in now' },
scripts: { status: 'Failed', detail: 'The nightly cleanup stopped at step 3 of 5' },
storage: { status: 'Check', statusColor: 'orange', detail: 'Media at 82%' },
settings: { status: 'Ok', statusColor: 'green', detail: 'Saved yesterday' }
};
function build(mount, current) {
let page = null;
const shell = base.createToolShell({
tools: tools,
current: current,
onSelect: (key, tool, event) => { event.preventDefault(); show(key); }
});
function show(key) {
if (page) page.destroy();
page = null;
shell.setCurrent(key);
shell.content.textContent = '';
if (key === 'dashboard') {
page = base.createStatusCardGrid({ cards: tools.filter((t) => cards[t.key]).map((t) => Object.assign({ icon: t.icon, title: t.name, href: t.href }, cards[t.key])) });
page.element.addEventListener('click', (e) => {
const card = e.target.closest('a');
if (!card) return;
e.preventDefault();
show(card.getAttribute('href').slice(1));
});
shell.content.appendChild(page.element);
return;
}
page = base.createSubTabs({ tabs: [{ id: 'status', label: 'Status', text: cards[key].detail + '.' }, { id: 'settings', label: 'Settings', text: 'The settings of this tool.' }] });
shell.content.appendChild(page.element);
}
mount.appendChild(shell.element);
show(current);
}
build(document.getElementById('wide'), 'dashboard');
build(document.getElementById('narrow'), 'vpn');
</script>