SpaceMIX v0.1.0 (latest)

Look and feel

experimentalfor bothsince protocol 1

Making a widget look like the rest of SpaceMIX - the spacemix.ui helpers and op-* classes with recipes for a list, a stat, bars, a spark line, a donut, a legend, a line chart, a meter, a gauge and a heatmap, the theme variables in light and dark, the grid and sizing, phones and reduced motion.

The widget frame ships a kit: CSS classes prefixed op- and helpers in spacemix.ui. Build from them instead of writing your own styles, and the widget looks like the rest of SpaceMIX in light and in dark. Add a little CSS of your own only for what the kit doesn't cover, on your own classes and ids.

The complete list of helpers, classes, modifiers and variables is in spacemix in the widget. This page shows how they fit together. Every example uses only what apps/desktop/src-tauri/src/widget_frame.html provides.

The helpers, classes and variables this page shows are the stable widget frame surface. The page as a whole is experimental because it also describes how Dashboards and Team Chat show a widget; see Stability.

Building markup

Build markup with the html tag and put it on the page with render:

const { html, render } = spacemix.ui;
render("#list", items.map((t) => html`<li class="op-item"><span class="op-item-title">${t.title}</span></li>`));
  • html`…${v}…` escapes every value (<, >, &, quotes). Arrays are joined; nested html and the kit's helpers pass through unescaped. Never build markup by adding strings: a title with < in it would break the widget, or inject markup.
  • render(target, content) takes an element or a selector, and html output, a string of markup, or an array of them. It does nothing when the selector matches nothing.
  • raw(s) marks markup you trust so html passes it through; esc(v) escapes a value to a string.

Formatting helpers: num(n) gives 1,234, num(n, { compact: true }) gives 12K, num(n, { decimals: 2 }) shows at most two decimals, and anything that isn't a number gives –. pct(part, whole) gives "42%", or – when whole is 0. ago(at) gives "just now", "5m ago", "3h ago", "2d ago", then a date; date(at, options?) a short date (options are toLocaleDateString options). Both take ms, an ISO string or a Date.

Recipes

Each recipe is the inside of a spacemix.onData callback, or the markup it fills. Check the source with failed first; see Handling errors.

A stat. One big number with a label. .lg and .sm make the number bigger or smaller. The widget renders whole from its root each time, so the error state doesn't leave later data with nowhere to go.

<div class="op-widget center"></div>
<script>
  const { html, render, num, error, failed } = spacemix.ui;
  spacemix.onData(({ deals }) => {
    if (failed(deals)) return render(".op-widget", error(deals));
    render(".op-widget", html`<div class="op-stat lg"><div class="op-stat-value">${num(deals.total, { compact: true })}</div><div class="op-stat-label">open deals</div></div>`);
  });
</script>

To show a change under the number, add <span class="op-delta up"> (or .down) after the stat, filled from a source that returns the change itself. Counting items doesn't give one: a *_list result holds at most limit items, whatever their dates.

Several stats side by side: put them in .op-grid, which fits as many columns as there is room for (set --min to change the narrowest column, default 110px).

A list. Lists scroll inside the widget with .op-scroll. A row with data-open opens that extension when clicked.

render("#w", html`<ul class="op-list op-scroll">${tasks.items.map((t) => html`
  <li class="op-item" data-open="ai.spacemix.tasks">
    <span class="op-dot ${t.urgent ? "danger" : ""}"></span>
    <span class="op-item-title">${t.title}</span>
    <span class="op-item-meta">${ago(t.updatedAt)}</span>
  </li>`)}</ul>`);

Dots take .ok, .warn, .danger, .info or .muted; .op-check (with .done) is a checkbox look. For columns, use <table class="op-table">; a cell with .op-num or .right is right-aligned, and a row with data-open is clickable.

Bars. Vertical bars from numbers or { label, value, color }. They fill their container's height unless height (px) is given.

render("#chart", bars(days.map((d) => ({ label: d.day, value: d.count }))));

A ranking. Labelled horizontal bars, with format for the numbers:

render("#top", hbars(people.map((p) => ({ label: p.name, value: p.revenue })), { format: (v) => num(v, { compact: true }) }));

A spark line. A trend from numbers; area: false drops the fill under it, height is in px (default 48).

render("#trend", spark(weeks.map((w) => w.total), { height: 40 }));

A donut with its legend. Parts of a whole; each part gets the next series color unless it sets color. center is text in the middle; legend: false leaves the legend out; size (default 76) and thickness (default 10) are in px.

render("#split", donut([{ label: "Won", value: won }, { label: "Lost", value: lost }], { center: pct(won, won + lost) }));

A legend on its own, for a chart you draw yourself:

render("#key", html`<div class="op-legend">${series.map((s, i) => html`<div><i style="--color:${color(i)}"></i><span class="op-truncate op-grow">${s.name}</span></div>`)}</div>`);

A meter. progress(fraction, { color? }) for 0–1, clamped.

A line chart. One or more series over the same x positions, with x labels and a legend. line(numbers) draws one line with a fill; line([{ label, values, color }]) one per series:

render("#trend", line([{ label: "Opened", values: opened }, { label: "Closed", values: closed }], { labels: days, height: 120 }));

Parts in one bar, a dial, a grid of days. meter([{ label, value, color }], { max?, legend?, format? }) puts parts side by side in one bar with a legend (a status mix, a budget split); gauge(fraction, { center?, label? }) is a half ring for one ratio; heatmap(values, { columns: 7 }) shades a cell per value (activity per day):

render("#mix", meter([{ label: "Done", value: done, color: "var(--op-success)" }, { label: "Blocked", value: blocked, color: "var(--op-danger)" }]));
render("#quota", gauge(used / limit, { label: "Storage" }));

Colors for line, meter, gauge, heatmap and avatar must be a var(--op-…) or a hex color; anything else gets the default.

People and time. avatar(name) gives initials in a circle colored by the name (.op-avatars overlaps a row of them); duration(ms) gives "1h 5m"; .op-clock is a big tabular time and .op-countdown a row of <div><b>02</b><span>days</span></div> cells, both updated from your own setInterval.

Also in the kit: .op-badge (.accent, .ok, .warn, .danger, .info, .outline), .op-button (.primary, .ghost, .danger, .sm, .icon), .op-tabs (a row of <button>s, the current one with aria-selected="true"; see the example in spacemix.call), .op-segmented (the same, sharing the row, the current one with aria-pressed="true"), .op-chips and .op-chip (filter chips with aria-pressed), .op-card, .op-toolbar, .op-kv (a <dl> of details), .op-timeline, the form controls .op-input, .op-select, .op-textarea, .op-field, .op-checkbox, .op-radio and .op-switch, and the states .op-empty, .op-error, .op-skeleton, .op-spinner and .op-callout. The complete list with modifiers is in spacemix in the widget.

Colors and the theme

Use the theme variables, never hard-coded colors:

Variables For
--op-fg, --op-muted, --op-subtle Text, from strongest to quietest.
--op-bg, --op-surface, --op-elevated, --op-hover Backgrounds.
--op-border, --op-border-strong Lines.
--op-accent, --op-accent-soft, --op-accent-fg The accent, its soft background, and text on the accent.
--op-danger Errors and losses.
--op-success, --op-warning, --op-info Status text, icons and dots: done, needs attention, news. The kit's .ok and .warn use the first two.
--op-success-soft, --op-warning-soft, --op-info-soft, --op-danger-soft A tinted background behind status text; never white text on a solid status color.
--op-c1 … --op-c6 Series colors; --op-c1 is the accent. spacemix.ui.color(i) gives var(--op-c<i+1>), wrapping after 6.

The parent sends the app's theme into the frame and again whenever it changes, so anything styled with var(--op-…) follows light and dark live. spacemix.theme is "light" or "dark", but nothing tells the script when it changes: don't compute colors in script from it, write var(--op-…) into the markup instead. --op-c1 follows the accent, and dark has its own lifted --op-c2 to --op-c6, so a chart that uses the variables reads in both themes.

Style your own classes and ids only. The frame document around your fragment (html, body, the root element) isn't part of the contract and may change.

The grid and sizing

On a dashboard a widget takes whole cells of a 12-column grid (GRID_COLS). Rows are 40 px (ROW_HEIGHT) with 10 px (GRID_GAP) between cells, so a widget h rows tall is h × 40 + (h − 1) × 10 px: 5 rows is 240 px, 8 rows is 390 px. Columns share the dashboard's width. A widget is at least 2×2 (MIN_SIZE) and at most 12 columns × 24 rows (MAX_ROWS). The widget's own frame is that box less the 32 px header Dashboards puts above it.

Size Cells On a dashboard about 1,100 px wide
Small 3×3 about 270 × 140 px
Medium (the default) 4×5 about 360 × 240 px
Large 6×8 about 540 × 390 px
Wide 12×4 the full width × 190 px
Tall 3×8 about 270 × 390 px

People resize widgets, so a widget never knows its size. Start from .op-widget (full height, padding, a column with gaps; .tight for less padding, .center to center everything), let lists take the rest with .op-scroll, use .op-truncate and .op-clamp (two lines) for long text, and set no fixed pixel widths.

In Team Chat a widget shows in a card at most 520 px wide, with 220 px of height for the widget.

On a phone

Dashboards fits the grid to the screen: 12 columns when the dashboard is at least 880 px wide, 6 columns from 480 px, and 1 column below that. Positions and widths scale down; heights stay. On a phone every widget is the full width of the screen at its own height, and the layout can only be changed at 12 columns. (This is the Dashboards extension's behaviour, not part of the frame contract.)

So a widget made at Small or Medium is shown about 350 px wide on a phone, and a Wide one keeps its height but loses most of its width. Check that numbers don't wrap badly and that lists still scroll; an .op-grid of stats drops to fewer columns by itself.

Reduced motion

A few kit pieces animate: .op-progress, .op-meter and .op-bars ease to their new size (in 0.4 s today), .op-switch slides its knob, .op-skeleton pulses and .op-spinner spins. The kit doesn't turn these off when the viewer asks for reduced motion, with one exception: under prefers-reduced-motion: reduce the spinner is slowed to one turn in 2 s, since it still has to show that something is happening. Your own animations should: put them inside @media (prefers-reduced-motion: no-preference) { … } in your <style>, and don't animate what doesn't need it.

Stability

Stability: experimental, as a page. The helpers, classes, modifiers, attribute hooks and variables on this page are the widget frame surface, stable and versioned by WIDGET_FRAME_VERSION; so are the grid constants (GRID_COLS, ROW_HEIGHT, GRID_GAP, MIN_SIZE, MAX_ROWS). What the classes look like (their CSS values, such as the series colors and the 0.4 s transitions) may be tuned within a version.

These are Dashboards and Team Chat behaviour, not frame surface, and may change:

  • The 32 px header above a widget on a dashboard (h-8 in extensions/dashboards/view/Grid.tsx), and so the pixel sizes in the table under The grid and sizing.
  • The phone breakpoints: 12 columns from 880 px, 6 from 480 px, 1 below (extensions/dashboards/view/Grid.tsx).
  • The Team Chat card: at most 520 px wide, 220 px of height for the widget (extensions/chat/view/WidgetCards.tsx).

This page as markdown · All pages as one file