@mccaskie-labs/workbench-ui 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +18 -0
- package/dist/confirm.d.ts +60 -0
- package/dist/confirm.js +85 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -1
- package/dist/style.d.ts +1 -1
- package/dist/style.js +34 -2
- package/dist/styles.js +36 -0
- package/dist/ui-styles.js +33 -27
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-ui
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- A page part for "Are you sure?": `confirm({ endpoint, fields, ask, question, consequence?, yes, no, reason?, type?, extra?, open? })` draws a button (`ask`, with the `wb-ui-button` look) that only opens a question naming the thing, what happens next and whether it can be undone; its "Yes, …" button posts `fields` with `confirm=yes`. It is a `<details>`, so it works with no script. A page's handler checks `confirmed(body)` (or `confirmed(body, word)` where a word must be typed) and refuses, changing nothing, when it is false. `renderConfirm`, `confirmed` and `ConfirmOptions` (the shared block every Workbench tool asks with) and `ConfirmPartOptions` are exported.
|
|
8
|
+
- New classes `wb-ui-confirm`, `-confirm-open`, `-confirm-ask`, `-confirm-keep`, `-confirm-form`, `-confirm-question`, `-confirm-consequence`, `-confirm-field`, `-confirm-label`, `-confirm-input` and `-confirm-yes`, in `UI_STYLES` and so in a project's generated `workbench.css`. They read the existing variables (the box is `--wb-ui-background`, the yes button `--wb-ui-bad` with `--wb-ui-accent-text`) and one new one, `--wb-ui-corner` (6px). `wb-ui-button` on a `<summary>` sits inline, and `wb-ui-actions` no longer makes the question's own form inline (its rule is now ` form:not(.wb-ui-confirm-form)`).
|
|
9
|
+
|
|
10
|
+
## 0.8.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- Every tool follows the project's look (docs/theming.md step 2, Robert, 24 November 2026). Each tool's colour, font and corner variables now default to the shared theme tokens with a Clean, light fallback (`--wb-booking-accent: var(--wb-accent, #2563eb)`), and tool colours with no token of their own (a recessed panel, a status mark, a tinted pill) are worked out from the tokens with `color-mix()`. So a page drawn with these tools takes the look in the project's workbench.css: light (Clean) by default, or whatever brand.json and project.css say. Breaking for a project page that relied on the old dark defaults: give brand.json the look you want, or set the tokens in project.css. Variable and class names are unchanged, so existing project.css overrides still win. workbench-ui: `styleProblems` refuses a tool's text, muted, surface, line, background, accent, focus, danger, success, warning, font or radius variable whose default doesn't read its token (email, PDF and image follow in step 3); the `wb-ui` class no longer forces dark, and Workbench's own pages (`STYLE`, `UI_CSS`) keep their dark values; `shell` with `stylesheets` (a project page) no longer says dark in its meta tag.
|
|
15
|
+
|
|
3
16
|
## 0.7.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ What goes inside a card. Each draws a `wb-ui-*` class with a default look, so a
|
|
|
46
46
|
| `small(html)` | Small print (`wb-ui-small`) |
|
|
47
47
|
| `button(text, { kind?, type?, attrs? })` | A button: `primary`, `secondary` or `link` (`wb-ui-button`) |
|
|
48
48
|
| `actions(html)` | A row of buttons and their forms (`wb-ui-actions`) |
|
|
49
|
+
| `confirm({ endpoint, fields, ask, question, consequence?, yes, no, reason?, type?, extra?, open? })` | "Are you sure?" before something that removes, cancels or can't be undone: the `ask` button only opens the question, and its `yes` button posts `fields` with `confirm=yes` (`wb-ui-confirm`). The page's handler refuses a post where `confirmed(body)` is false, changing nothing. `reason: { label }` adds a reason box; `type: { label, word }` makes the person type a word first (check it with `confirmed(body, word)`) |
|
|
49
50
|
| `input(attrs)`, `select(attrs, options, selected?)`, `textarea(attrs, text?)` | A control (`wb-ui-input`). Attributes are escaped; `class` and `on…` are refused |
|
|
50
51
|
| `field(label, id, control, { hint? })` | A label over its control, then a hint with the id `<id>-hint` (`wb-ui-field`) |
|
|
51
52
|
| `check(label, attrs)` | A tick box with its words (`wb-ui-check`) |
|
|
@@ -54,6 +55,23 @@ What goes inside a card. Each draws a `wb-ui-*` class with a default look, so a
|
|
|
54
55
|
| `more(label, html)` | More detail, folded until asked for (`wb-ui-more`) |
|
|
55
56
|
| `code(text)` | Exact text kept as it is (`wb-ui-code`) |
|
|
56
57
|
|
|
58
|
+
```ts
|
|
59
|
+
import { confirm, confirmed } from '@mccaskie-labs/workbench-ui'
|
|
60
|
+
|
|
61
|
+
confirm({
|
|
62
|
+
endpoint: '/admin/admins',
|
|
63
|
+
fields: { action: 'remove_admin', email: admin.email },
|
|
64
|
+
ask: 'Remove',
|
|
65
|
+
question: `Remove ${admin.email} as an admin?`,
|
|
66
|
+
consequence: 'They can no longer open the admin page. You can add them again later.',
|
|
67
|
+
yes: 'Yes, remove this admin',
|
|
68
|
+
no: 'No, keep them',
|
|
69
|
+
})
|
|
70
|
+
// In the handler: if (!confirmed(body)) refuse with "Please confirm first. Nothing has changed."
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`renderConfirm`, `confirmed` and `ConfirmOptions` are the shared block every Workbench tool asks with; `confirm` is it with workbench-ui's own classes.
|
|
74
|
+
|
|
57
75
|
For a form whose answers are checked, use workbench-forms' `renderForm` instead of `field` and `input`.
|
|
58
76
|
|
|
59
77
|
Pages are always dark, whatever the computer is set to. A page with its own rules adds them after the shared ones and uses the colour variables (`--wb-ui-surface`, `--wb-ui-line`, `--wb-ui-pass` and so on), never its own colours.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface ConfirmOptions {
|
|
2
|
+
/** The tool's class prefix, without the trailing dash: "wb-booking". */
|
|
3
|
+
prefix: string;
|
|
4
|
+
/** Where the form posts. */
|
|
5
|
+
endpoint: string;
|
|
6
|
+
/** The hidden fields that say what to do: action, the thing's id or token. */
|
|
7
|
+
fields: Readonly<Record<string, string>>;
|
|
8
|
+
/** The first button's words: "Cancel". */
|
|
9
|
+
ask: string;
|
|
10
|
+
/** The first button's class, so it keeps the look it has in the tool's styles. */
|
|
11
|
+
askClass: string;
|
|
12
|
+
/** The question, naming the thing: "Cancel Sam's booking for Yoga on Monday 7 December at 6:00 pm?" */
|
|
13
|
+
question: string;
|
|
14
|
+
/** What happens next and who is told: "We'll email Sam to say it's cancelled." */
|
|
15
|
+
consequence?: string;
|
|
16
|
+
/** The button that does it, in its own words: "Yes, cancel this booking". */
|
|
17
|
+
yes: string;
|
|
18
|
+
/** The words that close the question again: "No, keep it". */
|
|
19
|
+
no: string;
|
|
20
|
+
/** A reason to send with it, when the action takes one. */
|
|
21
|
+
reason?: {
|
|
22
|
+
label: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
maxlength?: number;
|
|
25
|
+
required?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** For deleting a lot at once: a word the person must type before the button works. */
|
|
28
|
+
type?: {
|
|
29
|
+
label: string;
|
|
30
|
+
word: string;
|
|
31
|
+
};
|
|
32
|
+
/** More fields for the question's form, as HTML the tool has already escaped (a second box, a choice). Drawn above the button. */
|
|
33
|
+
extra?: string;
|
|
34
|
+
/** Draw the question already showing: the page was drawn again to ask it. */
|
|
35
|
+
open?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** The button and its question. */
|
|
38
|
+
export declare function renderConfirm(o: ConfirmOptions): string;
|
|
39
|
+
/** Whether a post answered the question: confirm=yes and, where a word had to be typed, that word. */
|
|
40
|
+
export declare function confirmed(body: Readonly<Record<string, unknown>>, word?: string): boolean;
|
|
41
|
+
interface ConfirmStyle {
|
|
42
|
+
name: string;
|
|
43
|
+
element: string;
|
|
44
|
+
about: string;
|
|
45
|
+
css: string;
|
|
46
|
+
states?: readonly {
|
|
47
|
+
selector: string;
|
|
48
|
+
about: string;
|
|
49
|
+
css: string;
|
|
50
|
+
}[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The question's classes with their default rules, for the tool's styles.
|
|
54
|
+
* `v` reads one of the tool's own variables (text, muted, line, sunk, surface,
|
|
55
|
+
* radius, danger, on-danger, focus).
|
|
56
|
+
*/
|
|
57
|
+
export declare function confirmStyles(prefix: string, v: (name: string) => string, o?: {
|
|
58
|
+
reason?: boolean;
|
|
59
|
+
}): ConfirmStyle[];
|
|
60
|
+
export {};
|
package/dist/confirm.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// "Are you sure?" for the actions that cancel, decline or delete
|
|
2
|
+
// (docs/critical-actions-audit.md, "The standard"). The button a person presses first only opens
|
|
3
|
+
// the question: what is about to happen, named in full, and who will be told.
|
|
4
|
+
// The second button does it. It is a <details>, so it works with no script,
|
|
5
|
+
// and the post carries confirm=yes, which the action helpers insist on: a page
|
|
6
|
+
// that draws its own one-click button is refused with `confirm_needed`.
|
|
7
|
+
//
|
|
8
|
+
// This file is the same in every tool that asks (only the prefix differs), so
|
|
9
|
+
// a project restyles each tool's question by that tool's own class names.
|
|
10
|
+
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
11
|
+
const pattern = (word) => word.replace(/[.*+?^${}()|[\]\\\/-]/g, "\\$&");
|
|
12
|
+
/** The button and its question. */
|
|
13
|
+
export function renderConfirm(o) {
|
|
14
|
+
const p = o.prefix;
|
|
15
|
+
const hidden = Object.entries({ ...o.fields, confirm: "yes" })
|
|
16
|
+
.map(([k, v]) => `<input type="hidden" name="${esc(k)}" value="${esc(v)}">`)
|
|
17
|
+
.join("");
|
|
18
|
+
const reason = o.reason
|
|
19
|
+
? `<label class="${p}-confirm-field"><span class="${p}-confirm-label">${esc(o.reason.label)}</span><input class="${p}-confirm-input" type="text" name="${esc(o.reason.name ?? "reason")}" maxlength="${o.reason.maxlength ?? 200}"${o.reason.required ? " required" : ""}></label>`
|
|
20
|
+
: "";
|
|
21
|
+
const type = o.type
|
|
22
|
+
? `<label class="${p}-confirm-field"><span class="${p}-confirm-label">${esc(o.type.label)}</span><input class="${p}-confirm-input" type="text" name="confirm_word" required pattern="${esc(pattern(o.type.word))}" autocomplete="off" autocapitalize="off" spellcheck="false"></label>`
|
|
23
|
+
: "";
|
|
24
|
+
return `<details class="${p}-confirm"${o.open ? " open" : ""}><summary class="${p}-confirm-open ${esc(o.askClass)}"><span class="${p}-confirm-ask">${esc(o.ask)}</span><span class="${p}-confirm-keep">${esc(o.no)}</span></summary><form class="${p}-confirm-form" method="post" action="${esc(o.endpoint)}">${hidden}<p class="${p}-confirm-question">${esc(o.question)}</p>${o.consequence ? `<p class="${p}-confirm-consequence">${esc(o.consequence)}</p>` : ""}${reason}${o.extra ?? ""}${type}<button class="${p}-confirm-yes" type="submit">${esc(o.yes)}</button></form></details>`;
|
|
25
|
+
}
|
|
26
|
+
/** Whether a post answered the question: confirm=yes and, where a word had to be typed, that word. */
|
|
27
|
+
export function confirmed(body, word) {
|
|
28
|
+
if (body.confirm !== "yes" && body.confirm !== true)
|
|
29
|
+
return false;
|
|
30
|
+
return word === undefined || (typeof body.confirm_word === "string" && body.confirm_word.trim() === word);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The question's classes with their default rules, for the tool's styles.
|
|
34
|
+
* `v` reads one of the tool's own variables (text, muted, line, sunk, surface,
|
|
35
|
+
* radius, danger, on-danger, focus).
|
|
36
|
+
*/
|
|
37
|
+
export function confirmStyles(prefix, v, o = {}) {
|
|
38
|
+
const focus = { selector: ":focus-visible", about: "Has focus", css: `outline:none;box-shadow:0 0 0 3px ${v("focus")}` };
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
name: `${prefix}-confirm`,
|
|
42
|
+
element: "details",
|
|
43
|
+
about: "A button that asks \"Are you sure?\" before it cancels, declines or deletes",
|
|
44
|
+
css: "display:block",
|
|
45
|
+
states: [
|
|
46
|
+
{ selector: `[open]`, about: "The question is showing", css: `display:flex;flex-direction:column;align-items:flex-start;gap:.75rem;box-sizing:border-box;width:100%;padding:1rem;background:${v("sunk")};border:1px solid ${v("line")};border-radius:${v("radius")}` },
|
|
47
|
+
{ selector: `[open] > summary`, about: "\"No, keep it\" sits under the button that does it", css: "order:2" },
|
|
48
|
+
{ selector: `[open] .${prefix}-confirm-ask`, about: "The first button's words, hidden while the question shows", css: "display:none" },
|
|
49
|
+
{ selector: `[open] .${prefix}-confirm-keep`, about: "\"No, keep it\", shown while the question shows", css: "display:inline" },
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: `${prefix}-confirm-open`,
|
|
54
|
+
element: "summary",
|
|
55
|
+
about: "The first button: it only opens the question",
|
|
56
|
+
css: "list-style:none",
|
|
57
|
+
states: [{ selector: "::-webkit-details-marker", about: "No arrow beside the button", css: "display:none" }],
|
|
58
|
+
},
|
|
59
|
+
{ name: `${prefix}-confirm-ask`, element: "span", about: "The first button's words", css: "display:inline" },
|
|
60
|
+
{ name: `${prefix}-confirm-keep`, element: "span", about: "\"No, keep it\": closes the question", css: `display:none;color:${v("text")}` },
|
|
61
|
+
{ name: `${prefix}-confirm-form`, element: "form", about: "The question and the button that does it", css: "display:grid;gap:.75rem;justify-items:start;width:100%" },
|
|
62
|
+
{ name: `${prefix}-confirm-question`, element: "p", about: "What is about to happen, naming the thing", css: `margin:0;font-weight:600;color:${v("text")}` },
|
|
63
|
+
{ name: `${prefix}-confirm-consequence`, element: "p", about: "What happens next and who is told", css: `margin:0;color:${v("muted")}` },
|
|
64
|
+
...(o.reason
|
|
65
|
+
? [
|
|
66
|
+
{ name: `${prefix}-confirm-field`, element: "label", about: "The reason, or the word to type", css: "display:grid;gap:.25rem;width:100%" },
|
|
67
|
+
{ name: `${prefix}-confirm-label`, element: "span", about: "What to type there", css: `color:${v("muted")}` },
|
|
68
|
+
{
|
|
69
|
+
name: `${prefix}-confirm-input`,
|
|
70
|
+
element: "input",
|
|
71
|
+
about: "Where it is typed",
|
|
72
|
+
css: `box-sizing:border-box;width:100%;min-height:2.75rem;padding:.5rem .75rem;font:inherit;color:${v("text")};background:${v("surface")};border:1px solid ${v("line")};border-radius:${v("radius")}`,
|
|
73
|
+
states: [focus],
|
|
74
|
+
},
|
|
75
|
+
]
|
|
76
|
+
: []),
|
|
77
|
+
{
|
|
78
|
+
name: `${prefix}-confirm-yes`,
|
|
79
|
+
element: "button",
|
|
80
|
+
about: "The button that does it",
|
|
81
|
+
css: `display:inline-flex;align-items:center;justify-content:center;min-height:2.75rem;padding:0 1rem;font:inherit;font-weight:600;border-radius:${v("radius")};cursor:pointer;color:${v("on-danger")};background:${v("danger")};border:1px solid ${v("danger")}`,
|
|
82
|
+
states: [focus],
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type ConfirmOptions } from "./confirm.ts";
|
|
2
|
+
export { confirmed, renderConfirm, type ConfirmOptions } from "./confirm.ts";
|
|
1
3
|
export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.ts";
|
|
2
4
|
export { UI_STYLES } from "./ui-styles.ts";
|
|
3
5
|
export { FORM_SCRIPT } from "./form-script.ts";
|
|
@@ -94,6 +96,16 @@ export interface ButtonOptions {
|
|
|
94
96
|
export declare function button(text: string, opts?: ButtonOptions): string;
|
|
95
97
|
/** A row of buttons, and of the small forms around them. `inner` is HTML. */
|
|
96
98
|
export declare function actions(inner: string): string;
|
|
99
|
+
/** What `confirm` takes: renderConfirm's options without the prefix and the first button's class, which are workbench-ui's own. */
|
|
100
|
+
export type ConfirmPartOptions = Omit<ConfirmOptions, "prefix" | "askClass">;
|
|
101
|
+
/**
|
|
102
|
+
* "Are you sure?" before something that removes, cancels or can't be undone.
|
|
103
|
+
* The first button (`ask`, drawn like `button`) only opens the question; the
|
|
104
|
+
* second (`yes`) posts `fields` with confirm=yes to `endpoint`, so the page's
|
|
105
|
+
* handler checks `confirmed(body)` before it acts. A `<details>`, so it works
|
|
106
|
+
* with no script. Every text option is plain text; `extra` is HTML.
|
|
107
|
+
*/
|
|
108
|
+
export declare function confirm(opts: ConfirmPartOptions): string;
|
|
97
109
|
/** A one-line control. `a` holds its attributes (id, name, type, value, required and so on). */
|
|
98
110
|
export declare function input(a: Attrs): string;
|
|
99
111
|
/** A text area holding `text`, which is plain text. */
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// (Control, the Gateway, the probe console and each project's starter page).
|
|
3
3
|
// Everything here returns HTML text; every value given as plain text is
|
|
4
4
|
// escaped here, and arguments documented as HTML are trusted as they are.
|
|
5
|
+
import { renderConfirm } from "./confirm.js";
|
|
5
6
|
import { STYLE } from "./style.js";
|
|
7
|
+
export { confirmed, renderConfirm } from "./confirm.js";
|
|
6
8
|
export { BASE_CSS, CSS, STYLE, UI_CSS } from "./style.js";
|
|
7
9
|
export { UI_STYLES } from "./ui-styles.js";
|
|
8
10
|
export { FORM_SCRIPT } from "./form-script.js";
|
|
@@ -115,6 +117,16 @@ export function button(text, opts = {}) {
|
|
|
115
117
|
export function actions(inner) {
|
|
116
118
|
return `<div class="wb-ui-actions">${inner}</div>`;
|
|
117
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* "Are you sure?" before something that removes, cancels or can't be undone.
|
|
122
|
+
* The first button (`ask`, drawn like `button`) only opens the question; the
|
|
123
|
+
* second (`yes`) posts `fields` with confirm=yes to `endpoint`, so the page's
|
|
124
|
+
* handler checks `confirmed(body)` before it acts. A `<details>`, so it works
|
|
125
|
+
* with no script. Every text option is plain text; `extra` is HTML.
|
|
126
|
+
*/
|
|
127
|
+
export function confirm(opts) {
|
|
128
|
+
return renderConfirm({ ...opts, prefix: "wb-ui", askClass: "wb-ui-button" });
|
|
129
|
+
}
|
|
118
130
|
/** A one-line control. `a` holds its attributes (id, name, type, value, required and so on). */
|
|
119
131
|
export function input(a) {
|
|
120
132
|
return `<input class="wb-ui-input"${attrs(a)}>`;
|
|
@@ -241,7 +253,7 @@ export function topBar(opts) {
|
|
|
241
253
|
}
|
|
242
254
|
/** A whole page: the shared look, the top bar, the heading, then `body`. */
|
|
243
255
|
export function shell(opts) {
|
|
244
|
-
return `<!doctype html><html lang="en-AU" class="wb-ui${opts.admin ? " wb-ui-admin" : ""}"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"
|
|
256
|
+
return `<!doctype html><html lang="en-AU" class="wb-ui${opts.admin ? " wb-ui-admin" : ""}"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">${opts.stylesheets ? (opts.admin ? '<meta name="color-scheme" content="light">' : "") : '<meta name="color-scheme" content="dark">'}
|
|
245
257
|
<title>${escape(opts.title)} · ${escape(opts.site)}</title>${opts.stylesheets ? opts.stylesheets.map((href) => `<link rel="stylesheet" href="${escape(href)}">`).join("") : STYLE}${opts.head ?? ""}
|
|
246
258
|
${opts.top}
|
|
247
259
|
<main class="wb-ui-main"><h1 class="wb-ui-title">${escape(opts.title)}</h1>${opts.body}</main>${opts.tail ?? ""}</html>`;
|
package/dist/style.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const CSS: string;
|
|
|
8
8
|
* weight and never touches a page of the project's own.
|
|
9
9
|
*/
|
|
10
10
|
export declare const BASE_CSS: string;
|
|
11
|
-
/** UI_STYLES as plain rules: the variables on :root, then each class and its states. */
|
|
11
|
+
/** UI_STYLES as plain rules for Workbench's own pages: always dark, the variables on :root, then each class and its states. */
|
|
12
12
|
export declare const UI_CSS: string;
|
|
13
13
|
/** The whole look as a <style> tag: the page conventions, then the helpers' classes, which win. */
|
|
14
14
|
export declare const STYLE: string;
|
package/dist/style.js
CHANGED
|
@@ -125,9 +125,41 @@ export const BASE_CSS = `:where(.wb-ui),:where(.wb-ui) *,:where(.wb-ui) ::before
|
|
|
125
125
|
@keyframes wb-ui-spin{to{transform:rotate(360deg)}}
|
|
126
126
|
@media (prefers-reduced-motion:reduce){:where(.wb-ui) *{animation:none!important;transition:none!important}}
|
|
127
127
|
`;
|
|
128
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Workbench's own pages (Control, the Gateway, the setup site, wb-probe) are
|
|
130
|
+
* always dark, whatever a project's look: these are the values UI_STYLES'
|
|
131
|
+
* variables take there, in place of the shared theme tokens a project's
|
|
132
|
+
* workbench.css works out from its brand.json.
|
|
133
|
+
*/
|
|
134
|
+
const WORKBENCH_DARK = {
|
|
135
|
+
"--wb-ui-background": "#121214",
|
|
136
|
+
"--wb-ui-surface": "#1b1b1f",
|
|
137
|
+
"--wb-ui-raised": "#25252b",
|
|
138
|
+
"--wb-ui-text": "#e8e8ec",
|
|
139
|
+
"--wb-ui-muted": "#9a9aa6",
|
|
140
|
+
"--wb-ui-line": "#33333b",
|
|
141
|
+
"--wb-ui-bar": "rgba(18,18,20,.92)",
|
|
142
|
+
"--wb-ui-accent": "#4c8dff",
|
|
143
|
+
"--wb-ui-accent-hover": "#6aa1ff",
|
|
144
|
+
"--wb-ui-accent-text": "#0b0b0d",
|
|
145
|
+
"--wb-ui-ok": "#5cc87a",
|
|
146
|
+
"--wb-ui-bad": "#ff6b66",
|
|
147
|
+
"--wb-ui-warn": "#f0a43a",
|
|
148
|
+
"--wb-ui-focus": "rgba(76,141,255,.4)",
|
|
149
|
+
"--wb-ui-pass": "#5cc87a",
|
|
150
|
+
"--wb-ui-fail": "#ff6b66",
|
|
151
|
+
"--wb-ui-skip": "#f0a43a",
|
|
152
|
+
"--wb-ui-run": "#4c8dff",
|
|
153
|
+
"--wb-ui-pass-bg": "rgba(92,200,122,.1)",
|
|
154
|
+
"--wb-ui-fail-bg": "rgba(255,107,102,.12)",
|
|
155
|
+
"--wb-ui-skip-bg": "rgba(240,164,58,.1)",
|
|
156
|
+
"--wb-ui-run-bg": "rgba(76,141,255,.12)",
|
|
157
|
+
"--wb-ui-font": "system-ui,-apple-system,\"Segoe UI\",sans-serif",
|
|
158
|
+
"--wb-ui-mono": "ui-monospace,\"Cascadia Code\",Consolas,monospace"
|
|
159
|
+
};
|
|
160
|
+
/** UI_STYLES as plain rules for Workbench's own pages: always dark, the variables on :root, then each class and its states. */
|
|
129
161
|
export const UI_CSS = [
|
|
130
|
-
`:root{
|
|
162
|
+
`:root{color-scheme:dark;${UI_STYLES.variables.map((x) => `${x.name}:${WORKBENCH_DARK[x.name] ?? x.value}`).join(";")}}`,
|
|
131
163
|
...UI_STYLES.classes.flatMap((c) => [`.${c.name}{${c.css}}`, ...(c.states ?? []).map((st) => `.${c.name}${st.selector}{${st.css}}`)]),
|
|
132
164
|
].join("\n");
|
|
133
165
|
/** The whole look as a <style> tag: the page conventions, then the helpers' classes, which win. */
|
package/dist/styles.js
CHANGED
|
@@ -19,6 +19,36 @@ export const STYLESHEETS = ["/styles/workbench.css", "/styles/project.css"];
|
|
|
19
19
|
*/
|
|
20
20
|
export const STYLED_SCOPE = "@mccaskie-labs/workbench-";
|
|
21
21
|
const NAME = /^[a-z][a-z0-9-]*$/;
|
|
22
|
+
/**
|
|
23
|
+
* A tool variable's last part and the shared theme token its default must read
|
|
24
|
+
* (docs/theming.md, step 2): the colours, fonts and corners every look sets.
|
|
25
|
+
*/
|
|
26
|
+
const TOKEN_FOR = {
|
|
27
|
+
text: "--wb-text",
|
|
28
|
+
muted: "--wb-muted",
|
|
29
|
+
surface: "--wb-surface",
|
|
30
|
+
line: "--wb-line",
|
|
31
|
+
background: "--wb-background",
|
|
32
|
+
accent: "--wb-accent",
|
|
33
|
+
"accent-hover": "--wb-accent-hover",
|
|
34
|
+
"on-accent": "--wb-on-accent",
|
|
35
|
+
"accent-text": "--wb-on-accent",
|
|
36
|
+
focus: "--wb-focus",
|
|
37
|
+
danger: "--wb-danger",
|
|
38
|
+
error: "--wb-danger",
|
|
39
|
+
bad: "--wb-danger",
|
|
40
|
+
"error-bg": "--wb-danger-bg",
|
|
41
|
+
good: "--wb-success",
|
|
42
|
+
ok: "--wb-success",
|
|
43
|
+
warn: "--wb-warning",
|
|
44
|
+
font: "--wb-font",
|
|
45
|
+
"heading-font": "--wb-font-heading",
|
|
46
|
+
"body-font": "--wb-font",
|
|
47
|
+
mono: "--wb-font-mono",
|
|
48
|
+
radius: "--wb-radius",
|
|
49
|
+
};
|
|
50
|
+
/** Tools whose output isn't a page (email is inlined, a PDF and an image are drawn apart) and so read brand.json directly for now (docs/theming.md, step 3). */
|
|
51
|
+
const TOKENS_LATER = new Set(["email", "pdf", "image"]);
|
|
22
52
|
/** What is wrong with a tool's styles: a name off its prefix, a class with no default rule, a variable used but not listed. */
|
|
23
53
|
export function styleProblems(s) {
|
|
24
54
|
const out = [];
|
|
@@ -35,6 +65,12 @@ export function styleProblems(s) {
|
|
|
35
65
|
out.push(`${s.tool}: variable ${v.name} is listed twice`);
|
|
36
66
|
if (!v.value.trim() || !v.about.trim())
|
|
37
67
|
out.push(`${s.tool}: variable ${v.name} needs a value and what it is for`);
|
|
68
|
+
const last = v.name.slice(2 + s.prefix.length);
|
|
69
|
+
const token = TOKEN_FOR[last];
|
|
70
|
+
// A radius may read the small one (controls); a font may be "inherit" (the page's).
|
|
71
|
+
const reads = token === "--wb-radius" ? /var\(--wb-radius(-small)?\b/ : token ? new RegExp(`var\\(${token}\\b`) : null;
|
|
72
|
+
if (reads && !TOKENS_LATER.has(s.tool) && !reads.test(v.value) && !(token?.startsWith("--wb-font") && v.value === "inherit"))
|
|
73
|
+
out.push(`${s.tool}: variable ${v.name} must default to the theme token ${token} (var(${token}, <fallback>))`);
|
|
38
74
|
vars.add(v.name);
|
|
39
75
|
}
|
|
40
76
|
const classes = new Set();
|
package/dist/ui-styles.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The look of what workbench-ui's helpers draw: shell, topBar, card, pill,
|
|
2
2
|
// chip and jumpNav, and the page parts (body, note, message, small, button,
|
|
3
|
-
// actions, field, input, check, table, facts, more and code), so a page needs
|
|
3
|
+
// actions, confirm, field, input, check, table, facts, more and code), so a page needs
|
|
4
4
|
// no markup of its own to look finished (docs/capabilities-manifest.md §10). Every element they put
|
|
5
5
|
// on a page carries one of these classes with a default rule, and the colours
|
|
6
6
|
// and sizes are `--wb-ui-*` variables, so a project restyles a Workbench page
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// a breaking change. The older page conventions for markup a page writes
|
|
9
9
|
// itself (.note, .body, bare tables and buttons) stay in CSS (style.ts) for
|
|
10
10
|
// Workbench's own pages; a project's generated workbench.css leaves them out.
|
|
11
|
+
import { confirmStyles } from "./confirm.js";
|
|
11
12
|
const v = (name) => `var(--wb-ui-${name})`;
|
|
12
13
|
const TONES = ["pass", "refused", "fail", "skip", "running"];
|
|
13
14
|
const RUN = (t) => (t === "running" ? "run" : t);
|
|
@@ -17,6 +18,8 @@ const SAYS = [
|
|
|
17
18
|
["warn", "warn"],
|
|
18
19
|
["fail", "fail"],
|
|
19
20
|
];
|
|
21
|
+
/** The variables the shared "Are you sure?" rules read, as workbench-ui's own. */
|
|
22
|
+
const CONFIRM_VARS = { radius: "corner", sunk: "background", danger: "bad", "on-danger": "accent-text" };
|
|
20
23
|
const FOCUS = `outline:none;box-shadow:0 0 0 3px ${v("focus")}`;
|
|
21
24
|
/** The style hooks of a Workbench page. */
|
|
22
25
|
export const UI_STYLES = {
|
|
@@ -26,38 +29,39 @@ export const UI_STYLES = {
|
|
|
26
29
|
title: "Workbench pages",
|
|
27
30
|
prefix: "wb-ui-",
|
|
28
31
|
variables: [
|
|
29
|
-
{ name: "--wb-ui-background", value: "#
|
|
30
|
-
{ name: "--wb-ui-surface", value: "#
|
|
31
|
-
{ name: "--wb-ui-raised", value: "#
|
|
32
|
-
{ name: "--wb-ui-text", value: "#
|
|
33
|
-
{ name: "--wb-ui-muted", value: "#
|
|
34
|
-
{ name: "--wb-ui-line", value: "#
|
|
35
|
-
{ name: "--wb-ui-bar", value: "
|
|
36
|
-
{ name: "--wb-ui-accent", value: "#
|
|
37
|
-
{ name: "--wb-ui-accent-hover", value: "#
|
|
38
|
-
{ name: "--wb-ui-accent-text", value: "#
|
|
39
|
-
{ name: "--wb-ui-ok", value: "#
|
|
40
|
-
{ name: "--wb-ui-bad", value: "#
|
|
41
|
-
{ name: "--wb-ui-warn", value: "#
|
|
42
|
-
{ name: "--wb-ui-focus", value: "rgba(
|
|
43
|
-
{ name: "--wb-ui-pass", value: "#
|
|
32
|
+
{ name: "--wb-ui-background", value: "var(--wb-background, #ffffff)", about: "Behind the page" },
|
|
33
|
+
{ name: "--wb-ui-surface", value: "var(--wb-surface, #f7f8f8)", about: "Cards, inputs and code blocks" },
|
|
34
|
+
{ name: "--wb-ui-raised", value: "color-mix(in srgb, var(--wb-surface, #f7f8f8), var(--wb-text, #1f2937) 7%)", about: "Table heads, chips and a row under the pointer" },
|
|
35
|
+
{ name: "--wb-ui-text", value: "var(--wb-text, #1f2937)", about: "Body text" },
|
|
36
|
+
{ name: "--wb-ui-muted", value: "var(--wb-muted, #5b6472)", about: "Quieter text: a card's sentence, labels, small print" },
|
|
37
|
+
{ name: "--wb-ui-line", value: "var(--wb-line, #d7d8db)", about: "Borders and rules" },
|
|
38
|
+
{ name: "--wb-ui-bar", value: "color-mix(in srgb, var(--wb-background, #ffffff), transparent 8%)", about: "The top bar, over the page as it scrolls" },
|
|
39
|
+
{ name: "--wb-ui-accent", value: "var(--wb-accent, #2563eb)", about: "Links, buttons and the current page" },
|
|
40
|
+
{ name: "--wb-ui-accent-hover", value: "var(--wb-accent-hover, #1f54c8)", about: "A link or button under the pointer" },
|
|
41
|
+
{ name: "--wb-ui-accent-text", value: "var(--wb-on-accent, #ffffff)", about: "Text on a filled button" },
|
|
42
|
+
{ name: "--wb-ui-ok", value: "var(--wb-success, #15803d)", about: "Words that say something worked" },
|
|
43
|
+
{ name: "--wb-ui-bad", value: "var(--wb-danger, #b42318)", about: "Words that say something failed, and the production tag" },
|
|
44
|
+
{ name: "--wb-ui-warn", value: "var(--wb-warning, #a15c07)", about: "Warnings, and the tag of any environment but production" },
|
|
45
|
+
{ name: "--wb-ui-focus", value: "var(--wb-focus, rgba(37,99,235,0.4))", about: "The ring around whatever has the keyboard" },
|
|
46
|
+
{ name: "--wb-ui-pass", value: "var(--wb-success, #15803d)", about: "A pill or chip that passed" },
|
|
44
47
|
{ name: "--wb-ui-refused", value: "#b48cff", about: "A pill or chip for a call that was refused" },
|
|
45
|
-
{ name: "--wb-ui-fail", value: "#
|
|
46
|
-
{ name: "--wb-ui-skip", value: "#
|
|
47
|
-
{ name: "--wb-ui-run", value: "#
|
|
48
|
-
{ name: "--wb-ui-pass-bg", value: "
|
|
48
|
+
{ name: "--wb-ui-fail", value: "var(--wb-danger, #b42318)", about: "A pill or chip that failed, and a field with a problem" },
|
|
49
|
+
{ name: "--wb-ui-skip", value: "var(--wb-warning, #a15c07)", about: "A pill or chip that was skipped or waits" },
|
|
50
|
+
{ name: "--wb-ui-run", value: "var(--wb-accent, #2563eb)", about: "A pill or chip still running" },
|
|
51
|
+
{ name: "--wb-ui-pass-bg", value: "color-mix(in srgb, var(--wb-success, #15803d) 10%, transparent)", about: "Behind a passed pill" },
|
|
49
52
|
{ name: "--wb-ui-refused-bg", value: "rgba(180,140,255,.1)", about: "Behind a refused pill" },
|
|
50
|
-
{ name: "--wb-ui-fail-bg", value: "
|
|
51
|
-
{ name: "--wb-ui-skip-bg", value: "
|
|
52
|
-
{ name: "--wb-ui-run-bg", value: "
|
|
53
|
+
{ name: "--wb-ui-fail-bg", value: "color-mix(in srgb, var(--wb-danger, #b42318) 12%, transparent)", about: "Behind a failed pill, and a failed table row" },
|
|
54
|
+
{ name: "--wb-ui-skip-bg", value: "color-mix(in srgb, var(--wb-warning, #a15c07) 10%, transparent)", about: "Behind a skipped pill" },
|
|
55
|
+
{ name: "--wb-ui-run-bg", value: "color-mix(in srgb, var(--wb-accent, #2563eb) 12%, transparent)", about: "Behind a running pill" },
|
|
53
56
|
{ name: "--wb-ui-edge", value: "transparent", about: "The coloured edge on a table row's first cell (set per row by o-pass, o-fail and the rest)" },
|
|
54
|
-
{ name: "--wb-ui-font", value:
|
|
55
|
-
{ name: "--wb-ui-mono", value:
|
|
57
|
+
{ name: "--wb-ui-font", value: "var(--wb-font, system-ui, sans-serif)", about: "The page's font" },
|
|
58
|
+
{ name: "--wb-ui-mono", value: "var(--wb-font-mono, ui-monospace, monospace)", about: "Code's font" },
|
|
56
59
|
{ name: "--wb-ui-width", value: "max(64rem,80vw)", about: "Widest the page's column grows" },
|
|
57
60
|
{ name: "--wb-ui-input-width", value: "24rem", about: "Widest a one-line control grows" },
|
|
61
|
+
{ name: "--wb-ui-corner", value: "6px", about: "Corners of the \"Are you sure?\" box, its typed box and its button" },
|
|
58
62
|
],
|
|
59
63
|
classes: [
|
|
60
|
-
{ name: "wb-ui", element: "html", about: "The whole page
|
|
64
|
+
{ name: "wb-ui", element: "html", about: "The whole page, in the project's look (Workbench's own pages are always dark)", css: `background:${v("background")};color:${v("text")};font:15px/1.55 ${v("font")}` },
|
|
61
65
|
{ name: "wb-ui-admin", element: "html", about: "A project's own admin page (with wb-ui): its accent and fonts on light neutrals, from the theme tokens", css: "color-scheme:light" },
|
|
62
66
|
{ name: "wb-ui-main", element: "main", about: "The page's column under the top bar", css: `display:block;max-width:${v("width")};margin:0 auto;padding:1.75rem 1rem 3rem` },
|
|
63
67
|
{ name: "wb-ui-title", element: "h1", about: "The page's heading", css: "font-size:1.6rem;line-height:1.2;margin:0 0 .6rem" },
|
|
@@ -216,6 +220,7 @@ export const UI_STYLES = {
|
|
|
216
220
|
{ selector: "[data-kind=link]:hover", about: "A link button under the pointer", css: `background:none;color:${v("accent-hover")}` },
|
|
217
221
|
{ selector: ":disabled", about: "A button that can't be pressed yet", css: "opacity:.45;cursor:not-allowed" },
|
|
218
222
|
{ selector: ":focus-visible", about: "With the keyboard", css: FOCUS },
|
|
223
|
+
{ selector: ":where(summary)", about: "The button that opens \"Are you sure?\", from confirm()", css: "display:inline-flex;align-items:center;width:max-content;max-width:100%" },
|
|
219
224
|
],
|
|
220
225
|
},
|
|
221
226
|
{
|
|
@@ -223,7 +228,7 @@ export const UI_STYLES = {
|
|
|
223
228
|
element: "div",
|
|
224
229
|
about: "A row of buttons and the forms around them, from actions()",
|
|
225
230
|
css: "display:flex;flex-wrap:wrap;align-items:center;gap:.6rem;margin:1rem 0",
|
|
226
|
-
states: [{ selector: " form", about: "A form in the row sits inline", css: "display:inline;margin:0" }],
|
|
231
|
+
states: [{ selector: " form:not(.wb-ui-confirm-form)", about: "A form in the row sits inline (not the form inside \"Are you sure?\")", css: "display:inline;margin:0" }],
|
|
227
232
|
},
|
|
228
233
|
{ name: "wb-ui-option", element: "option", about: "One choice in a drop-down list", css: `background:${v("surface")};color:${v("text")}` },
|
|
229
234
|
{ name: "wb-ui-field", element: "p", about: "One labelled control, from field(): the label over the control, then any hint", css: "display:flex;flex-direction:column;align-items:flex-start;gap:.3rem;margin:0 0 1rem" },
|
|
@@ -293,5 +298,6 @@ export const UI_STYLES = {
|
|
|
293
298
|
about: "Exact text kept as it is, such as a reply or a log line, from code()",
|
|
294
299
|
css: `font:.85rem/1.5 ${v("mono")};white-space:pre-wrap;overflow-wrap:anywhere;padding:.75rem 1rem;margin:.75rem 0;background:${v("surface")};border:1px solid ${v("line")};border-radius:8px;max-height:28rem;overflow:auto`,
|
|
295
300
|
},
|
|
301
|
+
...confirmStyles("wb-ui", (n) => v(CONFIRM_VARS[n] ?? n), { reason: true }),
|
|
296
302
|
],
|
|
297
303
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Workbench pages: one dark look, a top bar with the environment tag, cards, outcome pills, and one format for times, money and durations.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|