staffa 0.14.0 → 0.16.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/README.md +99 -271
- package/dist/components/autocomplete.js +4 -5
- package/dist/components/box.js +11 -21
- package/dist/components/button.d.ts +20 -5
- package/dist/components/button.js +55 -47
- package/dist/components/buttonChooser.js +1 -3
- package/dist/components/checkbox.js +1 -2
- package/dist/components/dialog.d.ts +9 -2
- package/dist/components/dialog.js +29 -35
- package/dist/components/field.d.ts +5 -8
- package/dist/components/field.js +4 -6
- package/dist/components/form.d.ts +5 -7
- package/dist/components/form.js +6 -9
- package/dist/components/keyhelp.d.ts +22 -0
- package/dist/components/keyhelp.js +91 -0
- package/dist/components/main.js +190 -318
- package/dist/components/menu.d.ts +36 -9
- package/dist/components/menu.js +193 -144
- package/dist/components/panels.d.ts +152 -232
- package/dist/components/panels.js +341 -556
- package/dist/components/select.js +1 -3
- package/dist/components/tabs.d.ts +10 -13
- package/dist/components/tabs.js +40 -63
- package/dist/components/textline.d.ts +3 -5
- package/dist/components/textline.js +3 -5
- package/dist/components/toast.d.ts +1 -3
- package/dist/components/toast.js +3 -6
- package/dist/components/tooltip.d.ts +4 -5
- package/dist/components/tooltip.js +13 -22
- package/dist/core.d.ts +17 -39
- package/dist/core.js +13 -35
- package/dist/icons-helpers.d.ts +3 -3
- package/dist/icons-helpers.js +6 -11
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -4
- package/dist/keys.d.ts +92 -0
- package/dist/keys.js +279 -0
- package/dist/staffa.esm.js +1 -1
- package/dist/theme.d.ts +4 -10
- package/dist/theme.js +58 -123
- package/package.json +2 -2
- package/skill/ButtonOptions.md +12 -0
- package/skill/DialogOptions.md +11 -2
- package/skill/FieldOptions.md +3 -5
- package/skill/IconButtonOptions.md +8 -0
- package/skill/MenuItem.md +22 -3
- package/skill/Panel.md +8 -0
- package/skill/SKILL.md +161 -294
- package/skill/addTooltip.md +4 -5
- package/skill/bindKey.md +51 -0
- package/skill/box.md +1 -1
- package/skill/form.md +5 -7
- package/skill/formatKey.md +21 -0
- package/skill/iconButton.md +4 -5
- package/skill/scrollStrip.md +7 -9
- package/skill/showFloatingMenu.md +2 -2
- package/skill/showKeyHelp.md +17 -0
- package/skill/tabs.md +3 -4
- package/skill/textline.md +3 -5
- package/src/components/autocomplete.ts +4 -5
- package/src/components/box.ts +11 -21
- package/src/components/button.ts +70 -47
- package/src/components/buttonChooser.ts +1 -3
- package/src/components/checkbox.ts +1 -2
- package/src/components/dialog.ts +39 -37
- package/src/components/field.ts +7 -11
- package/src/components/form.ts +6 -9
- package/src/components/keyhelp.ts +96 -0
- package/src/components/main.ts +194 -318
- package/src/components/menu.ts +209 -146
- package/src/components/panels.ts +389 -618
- package/src/components/select.ts +1 -3
- package/src/components/tabs.ts +40 -63
- package/src/components/textline.ts +3 -5
- package/src/components/toast.ts +4 -9
- package/src/components/tooltip.ts +13 -22
- package/src/core.ts +17 -43
- package/src/icons-helpers.ts +6 -11
- package/src/index.ts +5 -4
- package/src/keys.ts +300 -0
- package/src/theme.ts +58 -123
- package/skill/Attributes.md +0 -10
package/README.md
CHANGED
|
@@ -8,29 +8,20 @@ import * as S from "staffa";
|
|
|
8
8
|
|
|
9
9
|
const $user = A.proxy({ name: "", email: "" });
|
|
10
10
|
|
|
11
|
-
S.main({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
S.textline({ label: "Name", required: true, bind: A.ref($user, "name") });
|
|
22
|
-
S.textline({ label: "Email", type: "email", bind: A.ref($user, "email") });
|
|
23
|
-
},
|
|
24
|
-
actions: () => S.button({ content: "Create account", type: "submit" }),
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
});
|
|
11
|
+
S.main({ title: "Sign up", maxWidth: "40rem", content: () => {
|
|
12
|
+
S.form({
|
|
13
|
+
submit: () => S.dialog({ header: "Submitted", content: () => A.dump($user) }),
|
|
14
|
+
content: () => {
|
|
15
|
+
S.textline({ label: "Name", required: true, bind: A.ref($user, "name") });
|
|
16
|
+
S.textline({ label: "Email", type: "email", bind: A.ref($user, "email") });
|
|
17
|
+
},
|
|
18
|
+
actions: () => S.button({ content: "Create account", type: "submit" }),
|
|
19
|
+
});
|
|
20
|
+
}});
|
|
28
21
|
```
|
|
29
22
|
|
|
30
23
|
Staffa is made to look decent out of the box, but easily customizable at runtime.
|
|
31
24
|
|
|
32
|
-
## Screenshot
|
|
33
|
-
|
|
34
25
|

|
|
35
26
|
|
|
36
27
|
## Install
|
|
@@ -41,32 +32,25 @@ npm install staffa aberdeen
|
|
|
41
32
|
|
|
42
33
|
Aberdeen is a peer dependency. Staffa is published as ESM with TypeScript types.
|
|
43
34
|
|
|
35
|
+
**Every option of every component is documented in TSDoc**, on its `…Options` interface in `src/` — and, for AI agents, in the generated API reference that ships in `skill/`. This README only covers what those can't tell you.
|
|
36
|
+
|
|
44
37
|
## How it works
|
|
45
38
|
|
|
46
39
|
### Components are functions
|
|
47
40
|
|
|
48
|
-
Every component
|
|
41
|
+
Every component is a plain function taking a single typed options object and drawing DOM via Aberdeen. No classes, no web components. The `S` object collects them all. The options object may be an Aberdeen proxy, in which case mutating it updates the component in place:
|
|
49
42
|
|
|
50
43
|
```ts
|
|
51
|
-
S.button({ content: "Save", disabled: false });
|
|
52
44
|
S.box({ header: "Settings", content: () => { ... } });
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Options objects are typed and can be reactive
|
|
56
45
|
|
|
57
|
-
All components get their options in a typed object. The object may be an Aberdeen proxy, if you want to update the component in-place.
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
46
|
const $btn = A.proxy({ content: "Save", disabled: false });
|
|
61
47
|
S.button($btn);
|
|
62
|
-
setTimeout(() => //
|
|
63
|
-
$btn.disabled = true; // button updates instantly
|
|
64
|
-
}, 3000);
|
|
48
|
+
setTimeout(() => { $btn.disabled = true; }, 3000); // button updates instantly
|
|
65
49
|
```
|
|
66
50
|
|
|
67
51
|
### Rich text slots
|
|
68
52
|
|
|
69
|
-
Anywhere a component takes content
|
|
53
|
+
Anywhere a component takes content — a `label`, a `header`, a button's text, a dialog body — you can pass either a string or a `() => void` draw function. Strings render as **rich text**: `*italic*`, `**bold**`, `` `code` ``, `[link](/path)`. All text is safely escaped.
|
|
70
54
|
|
|
71
55
|
```ts
|
|
72
56
|
S.button({ content: "Save **now**" });
|
|
@@ -75,12 +59,12 @@ S.box({ header: "See the [docs](/docs)", content: () => { ... } });
|
|
|
75
59
|
|
|
76
60
|
### Surfaces
|
|
77
61
|
|
|
78
|
-
Staffa builds on **surfaces**: elements marked
|
|
62
|
+
Staffa builds on **surfaces**: elements marked `.s-s` that have their own background and derived text/border tokens. There are two families:
|
|
79
63
|
|
|
80
|
-
- **Neutral surfaces** — `.neutral` (and the implicit page at `:root`). A calm neutral whose shade steps automatically with nesting depth
|
|
81
|
-
- **Accent surfaces** — `.primary`, `.danger`, `.success`, `.warning`, `.link` (a bare `.s-s` defaults to primary). A bright fill with white ink, painted as a subtle single-colour gradient. They take a **variant**: `.filled` (default), `.tonal
|
|
64
|
+
- **Neutral surfaces** — `.neutral` (and the implicit page at `:root`). A calm neutral whose shade steps automatically with nesting depth, up to a cap. For cards, bars, popovers — anything that just holds content. No variants.
|
|
65
|
+
- **Accent surfaces** — `.primary`, `.danger`, `.success`, `.warning`, `.link` (a bare `.s-s` defaults to primary). A bright fill with white ink, painted as a subtle single-colour gradient. They take a **variant**: `.filled` (default), `.tonal` or `.outlined`. A surface nested *inside* an accent surface is always rendered filled, so it can't bleed into the vivid parent.
|
|
82
66
|
|
|
83
|
-
Components are built from these (`S.button` is a `.s-s.primary`, `S.box` a `.s-s.neutral
|
|
67
|
+
Components are built from these (`S.button` is a `.s-s.primary`, `S.box` a `.s-s.neutral`). Every component's `attrs` option is an Aberdeen `A()` string, so overriding is easy:
|
|
84
68
|
|
|
85
69
|
```ts
|
|
86
70
|
S.button({ content: "Delete", attrs: ".danger" });
|
|
@@ -88,20 +72,20 @@ S.button({ content: "Cancel", attrs: ".neutral" }); // neutral button
|
|
|
88
72
|
S.box({ attrs: ".primary", content: () => { ... } });
|
|
89
73
|
```
|
|
90
74
|
|
|
91
|
-
Inside any surface (including `:root`), CSS variables
|
|
75
|
+
Inside any surface (including `:root`), CSS variables hold the background and a set of safe foreground colours: `$s-bg`, `$s-text` (also applied as `color`), `$s-muted`, `$s-accent` (the surface's "pop" — the brand primary on neutral surfaces, the ink on accent ones) and `$s-faint` (hairlines). Use these and components adapt to wherever they're nested.
|
|
92
76
|
|
|
93
|
-
The colour tokens are mode-independent and settable: `$s-primary` (the one brand colour — it tints the neutrals and defines `.s-s.primary`), `$s-danger`, `$s-success`, `$s-warning
|
|
77
|
+
The colour tokens themselves are mode-independent and settable: `$s-primary` (the one brand colour — it tints the neutrals and defines `.s-s.primary`), `$s-danger`, `$s-success`, `$s-warning` and `$s-link` (also the fill of the `.s-s.link` surface). Links render in `$s-link` on neutral surfaces, in the ink on accent ones.
|
|
94
78
|
|
|
95
|
-
**Borders & shadows.** Neutral surfaces carry a subtle hairline border on their own
|
|
79
|
+
**Borders & shadows.** Neutral surfaces carry a subtle hairline border on their own, so a card looks like a card without any component help. Any surface can be lifted with `.shadow` or `.extra-shadow` — a neutral drop shadow on a neutral surface, a self-coloured glow on an accent one, ignored on `.tonal`/`.outlined`. `.no-shadow` removes a component's built-in shadow:
|
|
96
80
|
|
|
97
81
|
```ts
|
|
98
82
|
S.box({ attrs: ".extra-shadow", content: () => { ... } }); // a more raised card
|
|
99
|
-
S.button({ content: "Quiet", attrs: ".no-shadow" });
|
|
83
|
+
S.button({ content: "Quiet", attrs: ".no-shadow" }); // drop the button glow
|
|
100
84
|
```
|
|
101
85
|
|
|
102
86
|
### Dark and light modes
|
|
103
87
|
|
|
104
|
-
Dark/light mode
|
|
88
|
+
Dark/light mode follows the OS preference by default. Override it (and persist the choice) with:
|
|
105
89
|
|
|
106
90
|
```ts
|
|
107
91
|
S.setDarkMode(true); // force dark
|
|
@@ -109,13 +93,43 @@ S.setDarkMode(false); // force light
|
|
|
109
93
|
S.setDarkMode(undefined); // follow OS
|
|
110
94
|
```
|
|
111
95
|
|
|
112
|
-
|
|
96
|
+
`S.getDarkMode()` reads it back, reactively. A `buttonChooser` is probably the right component for a colour scheme selector.
|
|
113
97
|
|
|
114
|
-
###
|
|
98
|
+
### CSS reset
|
|
99
|
+
|
|
100
|
+
Staffa includes a lightweight CSS reset that makes bare semantic HTML look a bit better, but unsurprising without additional styling.
|
|
101
|
+
|
|
102
|
+
### Theming
|
|
103
|
+
|
|
104
|
+
Theming usually starts and ends with setting some CSS variables. Everything derives from the single brand colour `s-primary` (the neutral surface shades are tinted toward it too). Set them through CSS directly, or through Aberdeen:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
A.cssVars["s-primary"] = "#fdda58";
|
|
108
|
+
A.cssVars["s-danger"] = "#ee4422";
|
|
109
|
+
A.cssVars["s-radius"] = "4px";
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
See `src/theme.ts` for the other variables in use.
|
|
113
|
+
|
|
114
|
+
Beyond that, add CSS to override the default styling. To add your own accent surface, set its background (and, if needed, its ink) — the gradient and the rest of the tokens follow automatically:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
A.insertGlobalCss({".s-s.my-surface": "--s-bg:#ef6b00 --s-text:#fff"});
|
|
118
|
+
|
|
119
|
+
S.button({
|
|
120
|
+
content: "You'll want to click me",
|
|
121
|
+
attrs: ".my-surface",
|
|
122
|
+
click: () => S.alert("Good work!", {attrs: ".my-surface"})
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Custom surface class names may be anything other than the built-in modifiers (`.tonal`, `.outlined`, `.small`, `.large`). The `.tonal` and `.outlined` variants work on your surface for free.
|
|
127
|
+
|
|
128
|
+
For styling that differs per mode, wrap the above in `A(() => { if (S.getDarkMode()) ... })`: `getDarkMode()` is reactive, so the scope re-runs when the mode changes.
|
|
115
129
|
|
|
116
|
-
|
|
130
|
+
### Panel-stack navigation
|
|
117
131
|
|
|
118
|
-
|
|
132
|
+
Give `S.main()` a `routes` table instead of a `content` slot and it takes over navigation. Each route draws one screen of your app — a **panel** — and the shell shows as many panels as comfortably fit, each in its own **column**: one at a time on a phone, several side by side on a wider screen. The open panels form a **stack**, whose last member is the **current** panel — the one the URL names, and the rightmost column. Your code doesn't know the difference.
|
|
119
133
|
|
|
120
134
|
```ts
|
|
121
135
|
const shell = S.main({
|
|
@@ -134,76 +148,25 @@ function drawProject($panel: S.Panel<{ projectId: string }>) {
|
|
|
134
148
|
$panel.title = `Project ${projectId}`; // the shell puts it wherever it fits
|
|
135
149
|
A(`a href=/projects/${projectId}/tasks/1 #Open the first task`);
|
|
136
150
|
}
|
|
137
|
-
|
|
138
|
-
// Etc..
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
Each handler gets a `$panel` object holding the params from its route, along with the things Staffa needs to know about the panel: what it's called, what it can do, how much room it wants, whether it's still loading. It's an Aberdeen proxy, so you can set those later (when your data arrives, say) and the shell keeps up.
|
|
142
|
-
|
|
143
|
-
**Route keys.** A segment wrapped in brackets is a param:
|
|
144
|
-
|
|
145
|
-
- `[name]` matches one segment, as a string.
|
|
146
|
-
- `[name=integer]` matches one segment, as a number.
|
|
147
|
-
- `[...name]` matches the rest of the path, as a string. It has to be the last thing in the key, and it needs at least one segment to match.
|
|
148
|
-
|
|
149
|
-
The first key that matches wins, and a segment a param refuses simply doesn't match, so it falls through to a later route, or to `notFound`. TypeScript reads each key and types that handler's `$panel.params` from it, so `params.taskId` above really is a `number`.
|
|
150
|
-
|
|
151
|
-
`integer` only accepts spellings that survive a round trip back to the same URL: `42` and `-7` and `0`, but not `007`, `1.5`, `0x10`, `-0` or anything past `Number.MAX_SAFE_INTEGER`. Otherwise `/tasks/42` and `/tasks/0042` would be two different paths for one record, and could sit open in two columns at once. For ids that aren't safe integers, such as snowflakes, use a plain `[id]` and keep them as strings.
|
|
152
|
-
|
|
153
|
-
`[...name]` hands you the remaining path exactly as it appears in the URL, still percent-encoded. Decoding it for you would be lossy: an encoded slash inside a segment would come back looking just like a separator. When you want the pieces, `name.split("/").map(decodeURIComponent)` gives them to you. (Single-segment params have no such ambiguity, so those *are* decoded.)
|
|
154
|
-
|
|
155
|
-
**Navigating is just links.** Write ordinary `<a href="/...">` links; Staffa handles the clicks (so don't also call Aberdeen's `interceptLinks()`).
|
|
156
|
-
|
|
157
|
-
The open panels form a **stack**, and its last panel is the **current** one: the panel the URL names, and the rightmost column on screen. Whatever you navigate to lands there.
|
|
158
|
-
|
|
159
|
-
- A link inside a panel opens its target on top of that panel, closing everything after it first. That's why clicking a second project replaces the open project instead of adding a third column.
|
|
160
|
-
- A `data-panel` attribute on the link picks a different one of the three navigations, which differ only in how much of the link's own context the target keeps: `push` (the default just described) keeps the link's panel and builds on it; `replace` keeps everything under that panel but not the panel itself — what prev/next buttons want; and `open` keeps none of it, giving the target its own stack exactly as a nav item would — for a search hit or a mention, where the panel you clicked from is coincidence, not context.
|
|
161
|
-
- A plain link to something that's already open goes back to it instead of opening it twice, closing whatever was stacked on top of it; a `replace` or `open` applies its usual shape instead, the open panel moving into place with its state intact. Either way the same path is never in the stack twice.
|
|
162
|
-
- A link that isn't inside a panel (a nav item, or one in a dialog) has no panel to build on, so it replaces the stack as a whole: the panel you asked for, with its ancestor panels opened beneath it (see [below](#ancestors)). Panels that the new stack also contains stay as they are, so clicking the nav item for the section you're already in won't reset it. Clicking a nav item and opening that same URL in a fresh tab therefore give you the same columns.
|
|
163
|
-
|
|
164
|
-
**The stack is an object, not a global.** In routed mode `S.main()` hands back the panel stack, and every panel gets the same object as `$panel.stack` — which is what a route handler uses, since it runs while the `S.main()` call is still going and can't see its return value yet.
|
|
165
|
-
|
|
166
|
-
```ts
|
|
167
|
-
shell.pushPanel(path); // on top of the current panel
|
|
168
|
-
shell.replacePanel(path); // in its place
|
|
169
|
-
shell.openPanelStack(path, beneath?); // a whole arrangement, the way a nav item does
|
|
170
|
-
shell.closePanel(path?); // the current panel, or a named one
|
|
171
|
-
|
|
172
|
-
shell.panels; // the open panels, oldest first — the Panel objects themselves
|
|
173
|
-
shell.currentPanelIndex; // which of them the URL is on
|
|
174
|
-
shell.currentPanel; // shorthand for panels[currentPanelIndex]
|
|
175
151
|
```
|
|
176
152
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
`panels` is a live view rather than a copy, so writing through it works — `shell.panels[0].pinned = true` is the only way to pin a panel from outside its own handler. All three are reactive on the stack's shape: read one in a scope and it re-runs when panels open, close or the cursor moves. Don't hold a `Panel` across a navigation; read it fresh.
|
|
180
|
-
|
|
181
|
-
Navigating faster than the shell can settle is fine: closing travels through the browser's history, so it takes a moment to land, and anything asked for in the meantime waits for it rather than being dropped. Two quick Escapes (or back gestures) peel two panels, each aimed at the stack the one before it was heading for.
|
|
182
|
-
|
|
183
|
-
**The content area is the window**, minus the nav sidebar — or, when `S.main({ maxWidth })` says so, that much of it, centred. Either way it is the same width whatever is open, so the sidebar, the top bar and the footer never move.
|
|
184
|
-
|
|
185
|
-
The shell divides that area into columns: the narrowest whole number of them that keeps each one at least **360px** wide, and no column ever wider than **540**. A 1080px content area is three columns of 360; a 1520px one is four of 380; below 720px there is a single column — of at most 540, centred. `$panel.maxWidth` counts in those columns:
|
|
186
|
-
|
|
187
|
-
| `maxWidth` | How wide the panel gets | Good for |
|
|
188
|
-
| --- | --- | --- |
|
|
189
|
-
| `"small"` | One column — never above 540px. | lists, detail forms — anything that reads well at phone width |
|
|
190
|
-
| `"medium"` (default) | Two columns — never above 1080px. | ordinary screens; the safe default |
|
|
191
|
-
| `"large"` | Three columns — never above 1620px. | wide tables, dense forms |
|
|
192
|
-
| `"none"` | The whole content area, unbounded. | boards, dashboards |
|
|
153
|
+
Each handler gets a `$panel` proxy: the params from its route, plus what the shell needs to know about the panel — `title`, `actions`, `maxWidth`, `loading`, `pinned`, `unsaved`, `width`, `visible`, `close()`, `open()`, `stack`. Set them whenever you like — long after the handler ran, when your data arrives — and the shell keeps up. Each field is documented in the API reference.
|
|
193
154
|
|
|
194
|
-
|
|
155
|
+
**Route keys.** `[name]` matches one segment as a string, `[name=integer]` one segment as a number, and a trailing `[...name]` the rest of the path as one raw (still percent-encoded) string. The first key that matches wins; a segment a param refuses falls through to a later route, or to `notFound`. TypeScript types each handler's `params` from its own key. `integer` accepts only spellings that survive a round trip back to the same URL, so one record can never have two paths — use a plain `[id]` for ids that aren't safe integers.
|
|
195
156
|
|
|
196
|
-
|
|
157
|
+
**Navigating is just links.** Write ordinary `<a href="/...">` links; the shell handles the clicks (so don't also call Aberdeen's `interceptLinks()`). The three navigations differ only in how much of the link's own context the target keeps:
|
|
197
158
|
|
|
198
|
-
|
|
159
|
+
- **push** (the default) opens on top of the panel the link sits in, closing everything after it — which is why clicking a second project replaces the open project instead of adding a third column.
|
|
160
|
+
- **replace** keeps everything under that panel but not the panel itself; what prev/next buttons want.
|
|
161
|
+
- **open** keeps none of it, giving the target its own stack, as a nav item does; for a search hit or a mention, where the panel you clicked from is coincidence, not context.
|
|
199
162
|
|
|
200
|
-
|
|
163
|
+
`data-panel` on the link picks one; `linkNavigation` sets the default for links without it. A link outside any panel (a nav item, one in a dialog) has nothing to build on, so it replaces the stack as a whole, exactly as a cold link to that URL would — panels the new stack also contains staying as they are. A link to a path that's already open returns to it, closing what was stacked on top, rather than opening it twice; the same path is never in the stack twice.
|
|
201
164
|
|
|
202
|
-
The
|
|
165
|
+
**The stack is an object, not a global.** `S.main()` hands back the `PanelStack` — `pushPanel`, `replacePanel`, `openPanelStack`, `closePanel`, and the live, reactive `panels` / `currentPanel` / `currentPanelIndex` — and every panel gets that same object as `$panel.stack`, which is what a route handler uses, since it runs while the `S.main()` call is still going. Every navigation settles asynchronously (closes travel through the browser's history), so each method returns a `Promise<boolean>`. Don't hold a `Panel` across a navigation; read it fresh. To navigate on behalf of one particular screen — a row's click handler — use that panel's own `$panel.open(href, how?)`, which does exactly what a link inside it does; `pushPanel` builds on the *current* panel instead.
|
|
203
166
|
|
|
204
|
-
|
|
167
|
+
**Columns and widths.** The content area is the window minus the nav sidebar, or `S.main({ maxWidth })` of it, centred — the same width whatever is open, so the sidebar, top bar and footer never move. It divides into the narrowest whole number of columns of at least **360px**, capped at **540px** each; `$panel.maxWidth` asks for one, two (the default), three of them or the lot. A column's width depends only on the window, never on what else is open, so opening or closing a panel never resizes another. Its ask is a ceiling, never a floor: aim your layout at 360px and let it degrade gracefully below that. `$panel.width` is the resolved figure in pixels, correct before your handler draws.
|
|
205
168
|
|
|
206
|
-
**A panel declares its chrome; the shell places it.** A screen says what it is called and what it can do; everything else in its column — headings, cards, boxes — is the screen's own content, drawn like any other.
|
|
169
|
+
**A panel declares its chrome; the shell places it.** A screen says what it is called and what it can do; everything else in its column — headings, cards, boxes — is the screen's own content, drawn like any other.
|
|
207
170
|
|
|
208
171
|
```ts
|
|
209
172
|
function drawTask($panel: S.Panel<{ taskId: number }>) {
|
|
@@ -213,33 +176,11 @@ function drawTask($panel: S.Panel<{ taskId: number }>) {
|
|
|
213
176
|
}
|
|
214
177
|
```
|
|
215
178
|
|
|
216
|
-
On a wide screen the title becomes the stack's last crumb and
|
|
179
|
+
On a wide screen the title becomes the stack's last crumb and Save sits in a quiet strip at the top of the column; on a phone the crumb is still there and Save moves into the top bar, where the app menu was. Nothing in your code measures the viewport. Two deliberate rules: `actions` are the screen's *verbs* — Save, Delete, a menu — not a second way out, since going back is the crumbs' job at every width and there is no back button even on a phone (a link among the actions builds on this panel at both widths); and **`title` names the screen, it does not draw a heading** — a screen that wants its name in its own body writes it there, where it owns the typography. A column's body keeps a comfortable `$3` of padding; write `A("p:0")` for edge-to-edge rows, since the draw function's current element *is* the body.
|
|
217
180
|
|
|
218
|
-
**The breadcrumbs are the navigation.** The top bar's second line writes the open panels out as breadcrumbs — `Projects / Trackle / Task 42
|
|
181
|
+
**The breadcrumbs are the navigation.** The top bar's second line writes the open panels out as breadcrumbs — `Projects / Trackle / Task 42`, the ones currently on screen in bold — leaving that line to the app's `subtitle` only while the stack has nothing to add. Each crumb is an ordinary link back to its panel, closing what was stacked on top; the app's name and logo link to `home` (`/` by default, `null` links neither). Right-clicking a crumb offers **Close** and **Pin**: a pinned panel (`$panel.pinned`) survives navigation elsewhere, riding along beneath the new panel or parking out of sight, but not an explicit close. Escape closes the current panel, or steps left when it can't, and at the stack's start jumps to the navigation.
|
|
219
182
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
Right-click (or long-press) a crumb for **Close** — which takes just that panel out, wherever it sits in the stack — and **Pin**. A pinned panel — its crumb wears a pin — never closes as a side effect of navigation elsewhere: where a navigation would prune it, it rides along beneath the new panel instead (or parks out of sight, when the panel you went back to was already beneath it), one crumb click away. Pin the reference you keep coming back to, then navigate freely. An *explicit* close (Escape, `close()`, the crumb menu, `data-panel=replace`) still closes it, and it's yours from code as `$panel.pinned`. Because a crumb is a real link whose right-click the menu takes over, the menu also offers **Open in new tab** and **Copy link**.
|
|
223
|
-
|
|
224
|
-
A crumb can also wear a **●**: the panel holds unsaved work, and nothing will close it (see `$panel.unsaved` below).
|
|
225
|
-
|
|
226
|
-
| `$panel` | what it does |
|
|
227
|
-
| --- | --- |
|
|
228
|
-
| `title` | Names the screen: its breadcrumb, and `document.title` while it's the current panel. A panel that sets none borrows the first line of text in its own body — good enough for a crumb, but say it yourself. |
|
|
229
|
-
| `actions` | The screen's buttons or menu. In the column's chrome while several columns fit; in the top bar (taking the app `menu`'s place) once the shell is narrow. A link among them builds on this panel at both widths. |
|
|
230
|
-
|
|
231
|
-
Two deliberate rules there. `actions` are the screen's *verbs* — Save, Delete, Share, a menu — not a second way out: going back is the crumbs' job, at every width, and there is no back button even on a phone. And **`title` names the screen; it does not draw a heading** — a screen that wants its name in its own body writes it there, where it owns the typography.
|
|
232
|
-
|
|
233
|
-
A column's body keeps a comfortable `$3` of padding; a screen that wants edge-to-edge rows just writes `A("p:0")`, since the draw function's current element *is* the body.
|
|
234
|
-
|
|
235
|
-
**The rest of `$panel`:**
|
|
236
|
-
|
|
237
|
-
- `params` and `path`: read-only.
|
|
238
|
-
- `maxWidth`: as above, and live — set it whenever you like and the panel reflows.
|
|
239
|
-
- `loading`: set it while you're fetching. A new panel waits a moment before sliding in, so it can arrive with real content instead of empty, and shows a loading indicator if the wait drags on.
|
|
240
|
-
- `width` and `visible`: read-only and reactive. `width` is this column's width in pixels, for the rare content that genuinely differs by width. `visible` says whether this panel is on screen — not crowded out, not parked, not closing — which is the right question for per-panel floating UI like a FAB, since "am I the current panel?" answers wrongly when two columns are up.
|
|
241
|
-
- `pinned`: the crumb menu's Pin, from code.
|
|
242
|
-
- `unsaved`: set it while the panel holds work that must not be lost — a dirty form, an upload in flight. An unsaved panel **cannot be closed, by anything**: navigation and the back button park it instead (wearing a ● in its crumb), `close()` and the crumb menu's Close refuse, Escape steps left, and closing the browser tab runs into the browser's own are-you-sure. The tab title carries a leading `•` while *any* open panel is unsaved. Only the app clears the flag, which is its explicit "this is now discardable":
|
|
183
|
+
**Unsaved work.** `$panel.unsaved` marks a panel holding work that must not be lost — a dirty form, an upload in flight. It then **cannot be closed, by anything**: navigation and the back button park it instead (its crumb wearing a ●), `close()` and the crumb menu's Close refuse, Escape steps left, and closing the browser tab runs into the browser's own are-you-sure. The tab title carries a leading `•` while *any* open panel is unsaved. Only the app clears the flag:
|
|
243
184
|
|
|
244
185
|
```ts
|
|
245
186
|
A(() => { $panel.unsaved = $form.dirty || undefined; }); // the whole dirty check
|
|
@@ -252,27 +193,9 @@ S.button({ content: "Discard", attrs: ".neutral", click: () => {
|
|
|
252
193
|
|
|
253
194
|
So a panel that can *be* unsaved needs its own way out — a Save or Discard among its `actions`. There is no "discard changes?" dialog anywhere: leaving is never blocked, the work just waits, parked, one crumb away.
|
|
254
195
|
|
|
255
|
-
|
|
196
|
+
**Cold URLs.** The URL holds the current panel; the rest of the stack — the panels before it, any parked after it, and which are pinned — rides in the browser's history entry, so back and forward step through whole arrangements of columns and a reload brings the same ones back. A URL arriving without any of that (a shared link, a bookmark, a new tab) has nothing to restore, so Staffa builds the stack from the path: it walks the parent paths and opens each one you have a route for, so `/projects/7/tasks/42` opens as three columns. A parent path you have no route for is skipped — so if you don't want one screen appearing under another, just don't give it a route.
|
|
256
197
|
|
|
257
|
-
|
|
258
|
-
S.button({ content: "Cancel", attrs: ".neutral", click: () => $panel.close() });
|
|
259
|
-
$panel.stack.closePanel(); // the current panel
|
|
260
|
-
$panel.stack.closePanel("/projects/7"); // that panel, wherever it is
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
Closing the current panel hands the focus to the panel on its left. Closing one that *isn't* current takes just that one away: the columns around it stay where they are and keep their state, and the URL doesn't change, because the current panel didn't move. Either way it becomes a history entry, so the browser's back button brings the panel back.
|
|
264
|
-
|
|
265
|
-
A closed panel is torn down at once: its `A.clean()` hooks run the moment it closes, so subscriptions, timers and requests stop there and then. Only its element hangs around, inert and frozen, for the length of the exit animation.
|
|
266
|
-
|
|
267
|
-
Escape closes the current panel — or just steps left, when it holds unsaved work or panels sit parked beyond it — and at the stack's start it jumps to the navigation. The browser's back button replays whole arrangements, re-opening what a navigation closed.
|
|
268
|
-
|
|
269
|
-
<a id="ancestors"></a>
|
|
270
|
-
|
|
271
|
-
**The back button, and links from elsewhere.** The URL holds the current panel; the rest of the stack — the panels before it, any parked after it, and which are pinned — is stored beside it in the browser's history entry. So back and forward step through whole arrangements of columns, and a reload brings the same columns back.
|
|
272
|
-
|
|
273
|
-
A URL that arrives without any of that (a shared link, a bookmark, a new tab) has nothing to restore, so Staffa builds the stack from the path: it walks the parent paths and opens each one you have a route for. With the routes above, `/projects/7/tasks/42` opens as three columns: the project list, project 7, and task 42. A parent path you have no route for is skipped, so if you don't want one screen appearing under another, just don't give it a route.
|
|
274
|
-
|
|
275
|
-
That only works for URLs that spell their own context out. A flat one — `/thread/[id]`, where a push notification lands — has no parent path to walk, so it would open as a lone column with nothing beneath it and nothing for Escape to do. `ancestors` is where you say what belongs under it. It's keyed by the same path templates as `routes`, so each entry gets that key's params, matched and typed:
|
|
198
|
+
That only works for URLs that spell their own context out. A flat one — `/thread/[id]`, where a push notification lands — has no parent path to walk, so `ancestors` is where you say what belongs underneath. It's keyed by the same path templates as `routes`, so each entry gets that key's params, matched and typed:
|
|
276
199
|
|
|
277
200
|
```ts
|
|
278
201
|
S.main({
|
|
@@ -286,107 +209,35 @@ S.main({
|
|
|
286
209
|
});
|
|
287
210
|
```
|
|
288
211
|
|
|
289
|
-
Return the paths shallowest first, or nothing to
|
|
290
|
-
|
|
291
|
-
It has to answer without drawing anything, which is why it lives here rather than on `$panel`: it's consulted while the navigation is still being worked out, before any route handler has run.
|
|
292
|
-
|
|
293
|
-
From code, `openPanelStack(path, beneath?)` opens the same kind of arrangement, either asking `ancestors` for the panels beneath or taking the ones you hand it.
|
|
294
|
-
|
|
295
|
-
Search params and the `#hash` belong to the current panel only. Anything another panel in the stack needs in order to redraw itself has to live in its path. (A panel you browse away from does get its search and hash back when a crumb makes it current again.)
|
|
212
|
+
Return the paths shallowest first, or nothing to fall back to the parent-path walk — which is also what an unlisted route gets. It's asked for every navigation that has no panel to build on, so a nav item and a fresh tab agree, and it is consulted before any handler has run, so it must answer without drawing anything. From code, `openPanelStack(path, beneath?)` opens the same kind of arrangement.
|
|
296
213
|
|
|
297
214
|
**A few more things.**
|
|
298
215
|
|
|
299
|
-
-
|
|
300
|
-
-
|
|
301
|
-
-
|
|
302
|
-
- Only one routed `S.main()` can be mounted at a time; a second one throws
|
|
303
|
-
-
|
|
304
|
-
- Deep links need your static server to serve the app for unknown paths (the usual SPA fallback
|
|
305
|
-
|
|
306
|
-
### CSS reset
|
|
307
|
-
|
|
308
|
-
Staffa includes a lightweight CSS reset that makes bare semantic HTML look a bit better but unsurprising without additional styling.
|
|
309
|
-
|
|
310
|
-
### Theming
|
|
311
|
-
|
|
312
|
-
The first step in theming is just setting some CSS variables. Everything derives from a single brand colour, `s-primary` (the neutral surface shades are tinted toward it too), so often that's all you need. This can be done through CSS directly, or using Aberdeen:
|
|
313
|
-
|
|
314
|
-
```ts
|
|
315
|
-
A.cssVars["s-primary"] = "#fdda58";
|
|
316
|
-
A.cssVars["s-danger"] = "#ee4422";
|
|
317
|
-
A.cssVars["s-radius"] = "4px";
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
See `src/theme.ts` for what other CSS variables are being used.
|
|
321
|
-
|
|
322
|
-
If you need further customization, just add some CSS to override the default styling. For instance, to add your own accent surface, set its background (and, if needed, its ink) — the subtle gradient and the rest of the tokens follow automatically:
|
|
323
|
-
|
|
324
|
-
```ts
|
|
325
|
-
A.insertGlobalCss({".s-s.my-surface": "--s-bg:#ef6b00 --s-text:#fff"});
|
|
326
|
-
|
|
327
|
-
S.button({
|
|
328
|
-
content: "You'll want to click me",
|
|
329
|
-
attrs: ".my-surface",
|
|
330
|
-
click: () => S.alert("Good work!", {attrs: ".my-surface"})
|
|
331
|
-
});
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
Custom surface class names may be anything (other than the built-in modifiers `.tonal`, `.outlined`, `.small`, `.large`). The `.tonal` and `.outlined` variants work on your surface for free.
|
|
335
|
-
|
|
336
|
-
Note that when changing CSS like this, things *may* break if you upgrade Staffa. The recommended update strategy is therefore: don't!
|
|
337
|
-
|
|
338
|
-
If you want to make changes that are dependent upon the current light/dark mode setting, rely on Aberdeen reactivity:
|
|
339
|
-
|
|
340
|
-
```ts
|
|
341
|
-
A(() => {
|
|
342
|
-
if (S.getDarkMode()) {
|
|
343
|
-
A.cssVars["s-primary"] = "#aa9944";
|
|
344
|
-
A.insertGlobalCss({".s-s.my-surface": "--s-bg:#444444 --s-text:#fff"});
|
|
345
|
-
} else {
|
|
346
|
-
A.cssVars["s-primary"] = "#fdda58";
|
|
347
|
-
A.insertGlobalCss({".s-s.my-surface": "--s-bg:#cccccc --s-text:#000"});
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
```
|
|
216
|
+
- Search params and the `#hash` belong to the current panel only; anything another panel needs in order to redraw itself has to live in its path. (A panel you browse away from does get its search and hash back when a crumb makes it current again.)
|
|
217
|
+
- A closed panel is torn down at once: its `A.clean()` hooks run the moment it closes, so subscriptions, timers and requests stop there and then.
|
|
218
|
+
- `columns: "single"` shows only the current panel however wide the screen — only the display changes. It, `linkNavigation` and `maxWidth` are live: pass a proxied options object and a change is adopted in place, every panel keeping its state.
|
|
219
|
+
- Only one routed `S.main()` can be mounted at a time; a second one throws, since the URL is global. Nothing else is.
|
|
220
|
+
- Aberdeen's own `route.go()` works, but builds the whole stack from the path; prefer the stack's methods. A guard your app registered with `route.setGuard` keeps working — Staffa registers none of its own.
|
|
221
|
+
- Deep links need your static server to serve the app for unknown paths (the usual SPA fallback; `-P` for `http-server`, as in the demo command below).
|
|
351
222
|
|
|
352
223
|
## Components
|
|
353
224
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
### Layout & containers
|
|
357
|
-
|
|
358
|
-
- **`S.main(opts)`**: app shell, a sticky header with `logo`, `title`, `subtitle`, `menu` — plus, in routed mode, the breadcrumbs of the open panels; scrollable content area; footer. Set `maxWidth` to center the content. Give it a `nav` for a sidebar that collapses to a hamburger below 640 px — where the nav becomes a full page sliding in from the left, handing over to the chosen screen with a matching slide in from the right. Its `items` may be a reactive array; adding or removing one redraws just the sidebar, never the content beside it. An item with `items` of its own becomes a collapsible submenu: only the branch holding the current page stays unfolded, and clicking a branch selects its first leaf (expanding a branch doesn't dismiss the phone's full-page nav — only picking a leaf does). A page the menu holds nowhere leaves every fold as it was. An item can also `match` pages beyond its own `href` — a path prefix, or a `(path) => boolean` — claiming the detail screens that have no row of their own: it is then highlighted, and the branches above it stay unfolded, cold deep links included. A sidebar taller than the window scrolls, and follows the highlighted item: navigating to a page whose item sits past the fold scrolls it back into view. A navigation dismisses the collapsed nav by itself, links in your own custom rows included; `S.closeNav()` does it for the rows that *don't* navigate. Instead of a single `content` slot it can take a `routes` table — see [Panel-stack navigation](#panel-stack-navigation).
|
|
359
|
-
- **`S.box(opts | content)`**: surface with optional `header`/`footer` and padded body. Pass a function for shorthand `{ content }`. `close: fn` adds a ✕ that runs your dismissal — in the header row, or floating over the body when there is no header. (It is plain furniture: a routed screen gets its own way out from the shell, see [Panel-declared chrome](#chrome).)
|
|
360
|
-
- **`S.tabs(opts)`**: tablist with live tab panels and keyboard navigation. More tabs than fit make the strip scroll (see `S.scrollStrip`); selecting a tab any other way (the arrow keys, a `bind` written from elsewhere) scrolls it into view.
|
|
361
|
-
- **`S.scrollStrip(opts)`**: a horizontal row that scrolls once its content outgrows it, with a ‹ / › button appearing over whichever end still has something to reach — so it isn't just a swipe target. Its own scrollbar is hidden. `S.tabs` and the routed shell's breadcrumbs are built on it; reach for it for any row of chrome that can outgrow its space. `S.revealInStrip(el)` scrolls one of its children into view.
|
|
362
|
-
- **`S.form(opts | content)`**: form aligning fields in a column or responsive grid, with an `actions` bar. Prevents the default page reload.
|
|
363
|
-
|
|
364
|
-
### Form fields
|
|
365
|
-
|
|
366
|
-
- **`S.textline(opts)`**: single-line input (`text`, `password`, `email`, `number`, `tel`, `url`, `search`, dates, ...).
|
|
367
|
-
- **`S.textarea(opts)`**: multi-line input.
|
|
368
|
-
- **`S.checkbox(opts)`**: labelled checkbox.
|
|
369
|
-
- **`S.select(opts)`**: single-select dropdown backed by native `<select>` (styled control, OS dropdown).
|
|
370
|
-
- **`S.autocomplete(opts)`**: type-ahead combobox with `multi` (chips), `allowCustom` (free text), `required`, and dynamic `options`.
|
|
371
|
-
|
|
372
|
-
### Dialogs
|
|
225
|
+
Every option of every component is documented in TSDoc on its `…Options` interface. Options share naming conventions: `attrs` (outermost element), `contentAttrs` (the children-holding element), `inputAttrs` (the form control) and `<region>Attrs` (`headerAttrs`, `footerAttrs`, …) — all Aberdeen attr/style strings, applied last so they can override. Form components consistently support `label`, `help`, `error`, `disabled`, `required` and `name`, and two-way binding through `bind: A.ref($obj, "key")`.
|
|
373
226
|
|
|
374
|
-
-
|
|
375
|
-
-
|
|
227
|
+
- **Layout & containers**: `main` (the app shell: sticky header, optional nav sidebar that collapses to a hamburger on narrow screens, scrollable content area or [panel routes](#panel-stack-navigation), footer; `closeNav` dismisses the collapsed nav), `box`, `form`, `tabs`, `scrollStrip` (+ `revealInStrip`).
|
|
228
|
+
- **Form fields**: `textline`, `textarea`, `checkbox`, `select`, `autocomplete`.
|
|
229
|
+
- **Actions**: `button`, `iconButton`, `buttonGroup`, `buttonChooser`.
|
|
230
|
+
- **Overlays & feedback**: `dialog` (+ `alert`, `confirm`, `prompt`), `menu`, `menuButton`, `showFloatingMenu`, `addContextMenu`, `toast`, `addTooltip`.
|
|
376
231
|
|
|
377
|
-
|
|
232
|
+
`src/index.ts` is the authoritative list of exports.
|
|
378
233
|
|
|
379
|
-
|
|
380
|
-
- **`S.iconButton(opts)`**: a bare glyph in a square hit area — no fill, no border, ink that lifts on hover. For chrome that mustn't compete with what it sits beside: the app shell's ✕ and ☰ are made of it, and it's usually what a page's `actions` want.
|
|
381
|
-
- **`S.buttonGroup(opts)`**: groups buttons, `attached` (segmented) or `spaced`.
|
|
382
|
-
- **`S.buttonChooser(opts)`**: single-select segmented control bound to a value.
|
|
234
|
+
### Keyboard shortcuts
|
|
383
235
|
|
|
236
|
+
Menu items and buttons take a `key` option, and `S.bindKey(key, description, press)` binds a shortcut with no button to carry it, for as long as the calling scope lives. A key is spelled `"mod+k"` (⌘ on a Mac, Ctrl elsewhere), `"shift+f2"`, `"mod+shift+b"`, or a bare `"?"` — case doesn't matter, and no modifiers besides `mod` and `shift` are offered. Component shortcuts are announced to screen readers, and keystrokes a focused field or link owns are left to it. While a modal dialog is open only its own shortcuts fire, and binding a taken combination shadows the earlier binding until the new scope dies; `bindKey`'s docs describe the `"global"` and `"local"` modes that bend these rules. `?` pops an overview of exactly what a keypress could do right now, given where focus is — a cheat-sheet, not a modal: any keypress closes it and still lands, and Esc merely dismisses it; `S.setKeyHelp(false)` turns it off. Omit `press` to merely list a key your app handles by other means.
|
|
384
237
|
|
|
385
238
|
### Icons
|
|
386
239
|
|
|
387
|
-
Staffa ships the full [Lucide icon set](https://lucide.dev/icons/) as named exports
|
|
388
|
-
|
|
389
|
-
Each icon is a draw function usable anywhere a slot is accepted (e.g. a button `icon`), or called directly. Customize per call, or globally via `setDefaults()`:
|
|
240
|
+
Staffa ships the full [Lucide icon set](https://lucide.dev/icons/) as named exports from `staffa/icons`. Import only the ones you use, so a bundler tree-shakes the rest (the whole set is ~82 kB gzipped). Each icon is a draw function usable anywhere a slot is accepted, or called directly:
|
|
390
241
|
|
|
391
242
|
```ts
|
|
392
243
|
import * as S from "staffa";
|
|
@@ -395,21 +246,11 @@ S.button({ content: "Save", icon: bell });
|
|
|
395
246
|
sparkles({ size: "1.5em", color: "var(--s-primary)", strokeWidth: 1.5 });
|
|
396
247
|
```
|
|
397
248
|
|
|
398
|
-
Options: `size`, `color` (defaults to `currentColor`), `strokeWidth`, `cap`, `join`, `attrs`.
|
|
399
|
-
|
|
400
|
-
### Other
|
|
401
|
-
|
|
402
|
-
- **`S.menuButton(opts)` / `S.addContextMenu(opts)` / `S.showFloatingMenu(opts)`**: dropdown menus from a button, right-click/long-press context menus, and the underlying floating menu primitive — with keyboard navigation. A menu closes itself when the page navigates.
|
|
403
|
-
- **`S.menu(opts)`**: the same menu rows drawn in place — for a nav or settings column of your own. Items with nested `items` form a collapsible tree; `onLeafSelect` fires only when a leaf is picked, never for a branch unfolding.
|
|
404
|
-
- **`S.closeNav()`**: dismisses `S.main`'s navigation when it's showing as an overlay (the full page on a phone, the dropdown on a wider screen). For custom nav rows that act without navigating.
|
|
405
|
-
- **`S.toast(opts)`**: transient notification at the bottom of the viewport.
|
|
406
|
-
- **`S.addTooltip(el, opts)`**: tooltip on hover, attached to an existing element.
|
|
407
|
-
|
|
408
|
-
Two-way binding uses Aberdeen proxies: pass `bind: A.ref($obj, "key")` to form fields.
|
|
249
|
+
Options: `size`, `color` (defaults to `currentColor`), `strokeWidth`, `cap`, `join`, `attrs` — per call, or globally via `setDefaults()` from `staffa/icons`.
|
|
409
250
|
|
|
410
251
|
## Browser (no bundler)
|
|
411
252
|
|
|
412
|
-
`staffa/all.js` is a pre-built ESM bundle. Use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap):
|
|
253
|
+
`staffa/all.js` is a pre-built ESM bundle with all components, but not the icons. Use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap):
|
|
413
254
|
|
|
414
255
|
```html
|
|
415
256
|
<script type="importmap">
|
|
@@ -429,40 +270,29 @@ Two-way binding uses Aberdeen proxies: pass `bind: A.ref($obj, "key")` to form f
|
|
|
429
270
|
</script>
|
|
430
271
|
```
|
|
431
272
|
|
|
432
|
-
It includes all components, but not the icons.
|
|
433
|
-
|
|
434
273
|
## Extending Staffa
|
|
435
274
|
|
|
436
|
-
Staffa is designed for extension
|
|
275
|
+
Staffa is designed for extension: a component is simply a plain function taking a typed options object and drawing Aberdeen DOM. These principles are how the built-in ones are written, and how yours should be too.
|
|
437
276
|
|
|
438
277
|
### Design principles
|
|
439
278
|
|
|
440
279
|
1. **Components are functions**. They take one typed options object, emit Aberdeen DOM, and *usually* return nothing.
|
|
441
|
-
|
|
442
280
|
2. **Reuse option types.** Define options by extending `ContentOptions` (for layout components) or `FieldOptions` (for form controls) from `src/core.ts` and `src/components/field.ts`. Don't reinvent fields like `attrs`, `label`, `help`, etc.
|
|
443
|
-
|
|
444
281
|
3. **Reach for reactivity deliberately.** Pass option strings straight to `A` as positional args (the caller's scope). Only wrap a dedicated `A(() => ...)` scope where it matters: input elements (recreation loses focus), or large subtrees you don't want to redraw. Use `A.peek(() => ...)` when you need a value but must not subscribe.
|
|
445
|
-
|
|
446
|
-
4. **Build on surfaces.** Mark elements `.s-s` and add `.neutral` or an accent role (`.primary`, `.danger`, …) plus an optional variant. Inside them, use the contextual CSS variables (`$s-text`, `$s-bg`, `$s-muted`, `$s-accent`, `$s-faint`, ...) so components adapt to wherever they're nested. Hard-coding colors in components shouldn't be needed, but if you must, make sure you set *both* foreground and background.
|
|
447
|
-
|
|
282
|
+
4. **Build on surfaces.** Mark elements `.s-s` and add `.neutral` or an accent role (`.primary`, `.danger`, …) plus an optional variant. Inside them, use the contextual CSS variables (`$s-text`, `$s-bg`, `$s-muted`, `$s-accent`, `$s-faint`, ...) so components adapt to wherever they're nested. Hard-coding colours shouldn't be needed, but if you must, set *both* foreground and background.
|
|
448
283
|
5. **No outer margins.** Components don't margin themselves; spacing is the parent's job. Content components set default `padding` on the content element; `contentAttrs` overrides it.
|
|
449
|
-
|
|
450
|
-
6. **Make everything styleable.** Provide `attrs`, `contentAttrs`, `inputAttrs`, and `<region>Attrs` hooks so callers can customize. Apply `attrs` last so it can override component classes.
|
|
451
|
-
|
|
284
|
+
6. **Make everything styleable.** Provide `attrs`, `contentAttrs`, `inputAttrs` and `<region>Attrs` hooks so callers can customize. Apply `attrs` last so it can override component classes.
|
|
452
285
|
7. **Use semantic HTML and ARIA.** Prefer native elements (`<button>`, `<label>`, `<form>`, `<section>`) and native behaviour. Add ARIA only where semantics fall short (e.g. tabs, combobox).
|
|
453
|
-
|
|
454
|
-
8. **Use CSS.** Use `A.insertGlobalCss({...})` at module top level to provide (nested) CSS styling for your component. Give your top-level element the `s-<component-name>` class. Avoid inventing further classes; lean on nesting (`&` for the element, bare key for descendants) and element/structural selectors.
|
|
455
|
-
|
|
286
|
+
8. **Use CSS.** Use `A.insertGlobalCss({...})` at module top level to provide (nested) CSS styling for your component. Give your top-level element the `s-<component-name>` class. Avoid inventing further classes; lean on nesting (`&` for the element, bare key for descendants) and element/structural selectors.
|
|
456
287
|
9. **Reuse form controls.** Use `drawField()` and call `applyControlAttrs()`.
|
|
457
|
-
|
|
458
288
|
10. **Function over form.** Provide enough contrast. Stick to UI conventions to help users; buttons have a rounded border, links are underlined, text input background is white, etc.
|
|
459
289
|
|
|
460
290
|
### Adding a component to Staffa
|
|
461
291
|
|
|
462
|
-
The
|
|
292
|
+
The principles above are good advice for any project-specific component, but must be followed for one to be included in Staffa. In addition:
|
|
463
293
|
|
|
464
294
|
1. Create `src/components/<name>.ts`.
|
|
465
|
-
2. Define `<Name>Options` extending `ContentOptions`, `FieldOptions`, or a plain interface. Add TSDoc on every option.
|
|
295
|
+
2. Define `<Name>Options` extending `ContentOptions`, `FieldOptions`, or a plain interface. Add TSDoc on every option — that TSDoc *is* the API documentation.
|
|
466
296
|
3. Add a TSDoc `@example` on the function.
|
|
467
297
|
4. Register in `src/index.ts` (the `S` object + type re-export).
|
|
468
298
|
5. Add it to the demo, cover it in the visual tests (`tests/*.spec.ts`), and run `npm run build` and `npm run typecheck`.
|
|
@@ -484,9 +314,7 @@ The visual tests (`tests/*.spec.ts`) need a build first (`npm run build`); they
|
|
|
484
314
|
|
|
485
315
|
## AI skill
|
|
486
316
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
To use this, it is recommended to symlink the skill into your project's `.claude/skills` directory:
|
|
317
|
+
For Claude Code, GitHub Copilot or any other agent that supports Skills, Staffa ships a `skill/` directory holding this README plus the generated API reference. Symlink it into your project:
|
|
490
318
|
|
|
491
319
|
```sh
|
|
492
320
|
mkdir -p .claude/skills
|
|
@@ -497,4 +325,4 @@ ln -s ../../node_modules/staffa/skill .claude/skills/staffa
|
|
|
497
325
|
|
|
498
326
|
What changed in each release, and what to do about the breaking ones, is in [CHANGELOG.md](CHANGELOG.md).
|
|
499
327
|
|
|
500
|
-
*Hint:* the recommended update strategy for a library this young is: don't. Pin it, and read the changelog before you move.
|
|
328
|
+
*Hint:* the recommended update strategy for a library this young is: don't. Pin it, and read the changelog before you move. This goes double if you've overridden Staffa's CSS.
|