Skip to main content

Desktop tools on the web

The elements an editor, an admin console or any other window-sized app needs. Set them up as in Getting started; @srctool/camouflage-core/define defines them all, and every skin draws them.

Each one reports what the user did and leaves the decision to your app. What the user arranges (tabs, columns, docked windows) is plain data, so you can store it and give it back.

Context menus​

camo-context-menu-area opens the entries in its items slot on a right-click, a long press, the Menu key or Shift+F10. The browser's own menu is replaced only inside the area.

<camo-context-menu-area>
<camo-list-item headline="report.pdf"></camo-list-item>
<camo-menu-item slot="items" text="Copy"></camo-menu-item>
<camo-menu-item slot="items" text="Delete"></camo-menu-item>
</camo-context-menu-area>

A long camo-menu can also filter as the user types: add speed-search.

Adaptive navigation​

camo-adaptive-navigation draws one set of destinations as a bottom bar, a rail or a drawer, following the window's width. The screen in the middle keeps its state when the navigation changes shape.

<camo-adaptive-navigation value="home" label="Main">
<camo-nav-item slot="items" value="home" label="Home" icon="home"></camo-nav-item>
<camo-nav-item slot="items" value="songs" label="Songs" icon="favorite"></camo-nav-item>
<camo-nav-item slot="items" value="people" label="People" icon="person"></camo-nav-item>
<main>…</main>
</camo-adaptive-navigation>

Listen to change and read value to show the matching screen. It fills the height of its container.

Speed search and highlighting​

Trees and data tables take speed-search="filter" (hide what doesn't match) or speed-search="jump" (move to the match). camo-search-change reports the typed text.

For a list you filter yourself, camoMatch does the matching and camo-highlighted-text marks what matched:

import { camoMatch } from "@srctool/camouflage-core";

const names = ["featureLogin", "featureLogout", "settings"];
const query = "fLog";
const matches = names.filter((name) => camoMatch(query, name) !== null);
<camo-highlighted-text text="featureLogin" query="fLog"></camo-highlighted-text>

Document tabs​

Tabs for open documents. Users close, reorder and pin them; your app owns the list.

const tabs = document.querySelector("camo-document-tabs");
tabs.documents = [
{ id: "a", title: "main.ts" },
{ id: "b", title: "README.md", modified: true },
];
tabs.value = "a";

// Closing only asks: remove the document and choose what is selected next.
tabs.addEventListener("camo-document-close", (event) => {
tabs.documents = tabs.documents.filter((d) => d.id !== event.detail.id);
if (tabs.value === event.detail.id) tabs.value = tabs.documents[0]?.id ?? "";
});

// The order and the pinned tabs, to store.
tabs.addEventListener("camo-order-change", (event) => {
localStorage.setItem("tabs", JSON.stringify(event.detail));
});

To restore, set tabs.order and tabs.pinned from what you stored. Set tabs.actions to a function that returns { text, onSelect } entries for a tab's context menu.

Table columns​

Add column-controls to a data table and users can resize, reorder and hide columns, with the pointer or the keyboard.

<camo-data-table caption="People" column-controls></camo-data-table>
const table = document.querySelector("camo-data-table");
table.columns = [
{ key: "name", header: "Name" },
{ key: "role", header: "Role" },
];
table.rows = [{ id: 1, name: "Ada Lovelace", role: "Analyst" }];

table.columnState = JSON.parse(localStorage.getItem("columns") ?? "{}");
table.addEventListener("camo-columns-change", (event) => {
localStorage.setItem("columns", JSON.stringify(event.detail));
});

Command palette​

One search field over any number of sources. Give a source items and the palette matches and ranks them, or give it an async search. Which keys open it is your app's choice.

<camo-command-palette label="Find action"></camo-command-palette>
const palette = document.querySelector("camo-command-palette");
palette.sources = [
{
title: "Actions",
items: [{ id: "pull", title: "Git: Pull", onSelect: () => console.log("pull") }],
},
{
title: "Files",
search: async (query, signal) => {
const response = await fetch(`/files?q=${encodeURIComponent(query)}`, { signal });
return response.json(); // [{ id, title, subtitle? }]
},
},
];

addEventListener("keydown", (event) => {
if ((event.ctrlKey || event.metaKey) && event.key === "k") {
event.preventDefault();
palette.open = true;
}
});

palette.recent holds the ids run lately; store it if it should survive a reload.

Dock layout​

Tool windows around a center, as in an IDE. Stripes on the edges show and hide them, dividers resize them (also between windows stacked on one edge), and each can move to another edge or be maximized.

<camo-dock-layout style="block-size: 100vh">
<camo-tool-window name="files" heading="Files" edge="left" open>…</camo-tool-window>
<camo-tool-window name="log" heading="Log" edge="bottom">…</camo-tool-window>
<main>…</main>
</camo-dock-layout>
const dock = document.querySelector("camo-dock-layout");
const saved = localStorage.getItem("dock");
if (saved) dock.apply(JSON.parse(saved));
dock.addEventListener("camo-dock-change", (event) => {
localStorage.setItem("dock", JSON.stringify(event.detail));
});

// For your own shortcut: open a window and move focus into it.
dock.focusWindow("files");

Tool windows appear once scripting runs; a server renders the center only.

Scrollbars​

Data tables, select lists and menus draw the skin's scrollbar themselves. Put a tree or a paged list inside camo-scrollbar to give it the same one.

The words​

Speed search, the command palette, document tabs and the data table's header menu say a few things themselves ("No matches", "No results", "Close"). Change them in the theme, as plain text; {count} stands for a number, and an attribute on the element, such as placeholder, wins:

import { applyTheme } from "@srctool/camouflage-core";

applyTheme(document.querySelector("camo-provider"), {
components: {
speedSearch: { noMatches: "Nichts", oneMatch: "ein Treffer", matches: "{count} Treffer" },
commandPalette: { placeholder: "Suchen", noResults: "Nichts gefunden" },
documentTabs: { close: "Schließen", modified: "geändert" },
},
});

Current limits​

  • The command palette draws every row a source returns, up to its limit; the list is not virtualized.
  • Closing and moving tabs, and arranging columns, are in each tab's and header's menu (the Menu key or Shift+F10). They have been tried in the browser, not yet with VoiceOver, NVDA or TalkBack.

The full list is in What differs from Kotlin and Flutter, and every attribute, property and event is in the element reference.