@terpjs/react-core 0.17.0 → 0.19.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/package.json +8 -8
- package/src/Authorized.tsx +20 -5
- package/src/Field.tsx +11 -22
- package/src/TerpProvider.tsx +13 -2
- package/src/admin/AccessAdmin.tsx +118 -0
- package/src/admin/AdminHub.tsx +10 -0
- package/src/admin/GroupDetail.tsx +7 -0
- package/src/admin/ModuleAccessPanel.tsx +349 -0
- package/src/admin/UserCreate.tsx +16 -6
- package/src/admin/UserDetail.tsx +23 -16
- package/src/admin/UsersAdmin.tsx +9 -3
- package/src/admin/access.test.tsx +655 -0
- package/src/admin/accessModel.test.ts +210 -0
- package/src/admin/accessModel.ts +165 -0
- package/src/admin/accessTiles.tsx +65 -0
- package/src/admin/admin.test.tsx +95 -3
- package/src/admin/module.tsx +3 -0
- package/src/admin/roles.ts +29 -15
- package/src/admin/useAccessLadder.ts +102 -0
- package/src/bootstrap.tsx +10 -0
- package/src/capabilities.test.ts +20 -0
- package/src/capabilities.ts +13 -3
- package/src/index.ts +2 -0
- package/src/locale.tsx +29 -0
- package/src/markers.test.ts +7 -0
- package/src/styles.test.ts +12 -5
- package/src/styles.ts +116 -38
- package/src/ui/Checkbox.tsx +56 -22
- package/src/ui/Radio.tsx +25 -1
- package/src/ui/Switch.tsx +57 -23
- package/src/ui/TileGroup.test.tsx +185 -0
- package/src/ui/TileGroup.tsx +220 -0
- package/src/ui/controlMessages.test.tsx +136 -0
- package/src/ui/controlMessages.tsx +81 -0
- package/src/uiText.tsx +70 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { useTerpClient } from "../TerpProvider";
|
|
4
|
+
import { unwrap } from "../unwrap";
|
|
5
|
+
import type { TerpStrings } from "../uiText";
|
|
6
|
+
|
|
7
|
+
import { buildModuleRows } from "./accessModel";
|
|
8
|
+
import type { ModuleRow } from "./accessModel";
|
|
9
|
+
|
|
10
|
+
/** One rung of the app's declared ladder, ready to render. */
|
|
11
|
+
export interface AdminRoleOption {
|
|
12
|
+
rank: number;
|
|
13
|
+
/** The name the app declared — `viewer`, `approver`, whatever it chose. */
|
|
14
|
+
name: string;
|
|
15
|
+
/** What to show a person: a framework translation where one exists, else the name. */
|
|
16
|
+
label: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The three rungs `terp-core` ships, by rank. Used only to *translate* a declared rung whose
|
|
21
|
+
* name matches one of them — never to decide which rungs exist. That distinction is the whole
|
|
22
|
+
* point of this file: `roles.ts` used to return these three ranks as literals, so an app with a
|
|
23
|
+
* four-rung ladder got a three-rung admin UI while ADR 0022 promised the role model was the
|
|
24
|
+
* app's. Now the ladder comes from `GET /api/v1/access/model` and this map only supplies copy.
|
|
25
|
+
*/
|
|
26
|
+
function packagedLabel(strings: TerpStrings, name: string): string | null {
|
|
27
|
+
if (name === "viewer") return strings.roleViewer;
|
|
28
|
+
if (name === "editor") return strings.roleEditor;
|
|
29
|
+
if (name === "admin") return strings.roleAdmin;
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AccessLadder {
|
|
34
|
+
/** The declared rungs, rank-ascending. Empty until the first load resolves. */
|
|
35
|
+
rungs: AdminRoleOption[];
|
|
36
|
+
/**
|
|
37
|
+
* Every module the app mounted, in ladder order, with what each rung adds.
|
|
38
|
+
*
|
|
39
|
+
* Carried by the same hook because it comes out of the same payload: the endpoint reports
|
|
40
|
+
* the ladder and the modules together, and a second hook for the second half would fetch
|
|
41
|
+
* `/model` twice to answer one question. The assignment panel filters this to the modules
|
|
42
|
+
* that opted in; the access screen keeps the refusals too, so it can say why.
|
|
43
|
+
*/
|
|
44
|
+
modules: ModuleRow[];
|
|
45
|
+
/** True while the model is in flight. */
|
|
46
|
+
loading: boolean;
|
|
47
|
+
/** The last failure message, or `null`. */
|
|
48
|
+
error: string | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The app's declared role ladder, read from the access model.
|
|
53
|
+
*
|
|
54
|
+
* Admin-only, like the endpoint — every screen that needs a ladder is already behind the
|
|
55
|
+
* `role: "admin"` route guard, so there is no case where this is fetched by a caller the
|
|
56
|
+
* server would refuse.
|
|
57
|
+
*
|
|
58
|
+
* A rung the framework has no translation for renders under its declared name rather than as
|
|
59
|
+
* `rank 25`, which is what the old rank-only fallback produced. The name is the app author's
|
|
60
|
+
* own word for it, so it is a better answer than a number even before anyone translates it.
|
|
61
|
+
*/
|
|
62
|
+
export function useAccessLadder(strings: TerpStrings): AccessLadder {
|
|
63
|
+
const client = useTerpClient();
|
|
64
|
+
const [rungs, setRungs] = useState<AdminRoleOption[]>([]);
|
|
65
|
+
const [modules, setModules] = useState<ModuleRow[]>([]);
|
|
66
|
+
const [loading, setLoading] = useState(true);
|
|
67
|
+
const [error, setError] = useState<string | null>(null);
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
let live = true;
|
|
71
|
+
setLoading(true);
|
|
72
|
+
// `unwrap` is how every hook in here reads a typed response: it throws the `ApiError`
|
|
73
|
+
// whose stable `code` the error-message machinery maps to copy, rather than leaving each
|
|
74
|
+
// caller to branch on `data` versus `error`.
|
|
75
|
+
void (async () => {
|
|
76
|
+
try {
|
|
77
|
+
const model = unwrap(await client.GET("/api/v1/access/model", {}));
|
|
78
|
+
if (!live) return;
|
|
79
|
+
setRungs(
|
|
80
|
+
[...model.roles]
|
|
81
|
+
.sort((a, b) => a.rank - b.rank)
|
|
82
|
+
.map((role) => ({
|
|
83
|
+
rank: role.rank,
|
|
84
|
+
name: role.name,
|
|
85
|
+
label: packagedLabel(strings, role.name) ?? role.name,
|
|
86
|
+
})),
|
|
87
|
+
);
|
|
88
|
+
setModules(buildModuleRows(model));
|
|
89
|
+
setError(null);
|
|
90
|
+
} catch (cause: unknown) {
|
|
91
|
+
if (live) setError(cause instanceof Error ? cause.message : String(cause));
|
|
92
|
+
} finally {
|
|
93
|
+
if (live) setLoading(false);
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
96
|
+
return () => {
|
|
97
|
+
live = false;
|
|
98
|
+
};
|
|
99
|
+
}, [client, strings]);
|
|
100
|
+
|
|
101
|
+
return { rungs, modules, loading, error };
|
|
102
|
+
}
|
package/src/bootstrap.tsx
CHANGED
|
@@ -42,6 +42,14 @@ export interface AdminAreaSections {
|
|
|
42
42
|
groups?: boolean;
|
|
43
43
|
/** The audit-log overview (terp-cap-audit). */
|
|
44
44
|
audit?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The access screen: which roles exist and what each may do per module (terp-cap-access).
|
|
47
|
+
*
|
|
48
|
+
* Gated like the others because it is not decoration — the screen reads
|
|
49
|
+
* `GET /api/v1/access/model`, which only exists where the access capability is mounted, so an
|
|
50
|
+
* app without it would ship a nav entry leading to a 404.
|
|
51
|
+
*/
|
|
52
|
+
access?: boolean;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
/** Route-path prefix per admin section, used to filter the packaged manifest. */
|
|
@@ -49,6 +57,7 @@ const ADMIN_SECTION_PREFIXES: Record<keyof AdminAreaSections, string> = {
|
|
|
49
57
|
users: "/admin/users",
|
|
50
58
|
groups: "/admin/groups",
|
|
51
59
|
audit: "/admin/audit",
|
|
60
|
+
access: "/admin/access",
|
|
52
61
|
};
|
|
53
62
|
|
|
54
63
|
function resolveAdminSections(
|
|
@@ -59,6 +68,7 @@ function resolveAdminSections(
|
|
|
59
68
|
users: sections.users !== false,
|
|
60
69
|
groups: sections.groups !== false,
|
|
61
70
|
audit: sections.audit !== false,
|
|
71
|
+
access: sections.access !== false,
|
|
62
72
|
};
|
|
63
73
|
}
|
|
64
74
|
|
package/src/capabilities.test.ts
CHANGED
|
@@ -22,3 +22,23 @@ describe("canPerform", () => {
|
|
|
22
22
|
expect(DEFAULT_RANK_THRESHOLDS).toEqual({ read: 10, write: 20, admin: 30 });
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
+
|
|
26
|
+
describe("canPerform with a per-module rung", () => {
|
|
27
|
+
it("takes the higher of the global rank and the module rung", () => {
|
|
28
|
+
// What the server's guard computes (ADR 0121). Without the rung the UI refused what the
|
|
29
|
+
// guard would have allowed, so a caller who could reach a module *only* through a rung had
|
|
30
|
+
// every control there hidden — a control living on one side of the wire.
|
|
31
|
+
expect(canPerform(10, "write")).toBe(false);
|
|
32
|
+
expect(canPerform(10, "write", DEFAULT_RANK_THRESHOLDS, 20)).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("never lowers a global rank", () => {
|
|
36
|
+
// The rung is additive at the guard, so a lower one cannot demote anyone here either. This
|
|
37
|
+
// is the case an implementation that *replaced* the rank would break.
|
|
38
|
+
expect(canPerform(30, "write", DEFAULT_RANK_THRESHOLDS, 10)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("ignores a rung for a threshold it still does not reach", () => {
|
|
42
|
+
expect(canPerform(10, "admin", DEFAULT_RANK_THRESHOLDS, 20)).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
package/src/capabilities.ts
CHANGED
|
@@ -14,13 +14,23 @@ export const DEFAULT_RANK_THRESHOLDS: RankThresholds = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Whether a caller
|
|
18
|
-
*
|
|
17
|
+
* Whether a caller may perform `action`, at `roleRank` globally and optionally at
|
|
18
|
+
* `moduleRank` inside the module in question.
|
|
19
|
+
*
|
|
20
|
+
* The effective rank is the **higher** of the two, which is what the server's guard computes
|
|
21
|
+
* (ADR 0121): a per-module rung raises authority inside one module and never lowers it. Passing
|
|
22
|
+
* the rung is what stops the UI disagreeing with the guard — without it a caller who may reach
|
|
23
|
+
* a module *only* through a rung had the button hidden, so the interface refused what the server
|
|
24
|
+
* would have allowed, and the control existed on one side of the wire only.
|
|
25
|
+
*
|
|
26
|
+
* This is the UI gate only; the backend independently enforces authorization on every request.
|
|
19
27
|
*/
|
|
20
28
|
export function canPerform(
|
|
21
29
|
roleRank: number,
|
|
22
30
|
action: Action,
|
|
23
31
|
thresholds: RankThresholds = DEFAULT_RANK_THRESHOLDS,
|
|
32
|
+
moduleRank?: number,
|
|
24
33
|
): boolean {
|
|
25
|
-
|
|
34
|
+
const effective = moduleRank === undefined ? roleRank : Math.max(roleRank, moduleRank);
|
|
35
|
+
return effective >= thresholds[action];
|
|
26
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -138,6 +138,8 @@ export { Checkbox } from "./ui/Checkbox";
|
|
|
138
138
|
export type { CheckboxProps } from "./ui/Checkbox";
|
|
139
139
|
export { Radio, RadioGroup } from "./ui/Radio";
|
|
140
140
|
export type { RadioGroupProps, RadioOption, RadioProps } from "./ui/Radio";
|
|
141
|
+
export { TileGroup } from "./ui/TileGroup";
|
|
142
|
+
export type { Tile, TileGroupProps } from "./ui/TileGroup";
|
|
141
143
|
export { Switch } from "./ui/Switch";
|
|
142
144
|
export type { SwitchProps } from "./ui/Switch";
|
|
143
145
|
export { Tabs } from "./ui/Tabs";
|
package/src/locale.tsx
CHANGED
|
@@ -223,6 +223,35 @@ export const LOCALE_NL: LocaleCatalog = {
|
|
|
223
223
|
adminGroupsDescription: "Bundel permissies; lidmaatschap past ze toe",
|
|
224
224
|
adminAudit: "Auditlog",
|
|
225
225
|
adminAuditDescription: "Elke wijziging: wat, wie, wanneer",
|
|
226
|
+
adminAccess: "Toegang",
|
|
227
|
+
adminAccessDescription: "Welke rollen er zijn, en wat elke rol per module mag",
|
|
228
|
+
accessNoRung: "Geen toegang",
|
|
229
|
+
accessAdds: "Extra ten opzichte van de tier eronder",
|
|
230
|
+
accessKindRead: "Bekijken",
|
|
231
|
+
accessKindWrite: "Wijzigen",
|
|
232
|
+
accessKindDelete: "Verwijderen",
|
|
233
|
+
accessAddsNothing: "Niets extra ten opzichte van de tier eronder",
|
|
234
|
+
accessNeverAssignable: "Nooit per module toe te kennen",
|
|
235
|
+
accessNotAssignable: "Niet per module toe te kennen",
|
|
236
|
+
accessUnexplainedRoutes: "{count} actie(s) in deze module hebben nog geen omschrijving",
|
|
237
|
+
accessDeclaredOnly:
|
|
238
|
+
"Dit is wat de applicatie vastlegt. Het laat niet zien wie welke rol heeft — open een persoon om dat te zien.",
|
|
239
|
+
moduleAccessTitle: "Toegang per module",
|
|
240
|
+
moduleAccessDescription:
|
|
241
|
+
"Een rol hier geldt in die ene module en verhoogt de toegang, nooit omlaag. Modules die dit niet aanbieden staan er niet bij.",
|
|
242
|
+
moduleAccessNoneAssignable:
|
|
243
|
+
"Geen enkele module in deze applicatie accepteert een eigen rol, dus hier is niets in te stellen.",
|
|
244
|
+
moduleAccessVia: "Hier ook {role}, via {name}",
|
|
245
|
+
moduleAccessStale: "Vastgelegd, maar zonder effect: {reason}",
|
|
246
|
+
moduleAccessFloor: "Overal al {role}, dus alles tot hier verandert niets",
|
|
247
|
+
moduleAccessConfirmTitle: "{role} geven in {module}?",
|
|
248
|
+
moduleAccessConfirm:
|
|
249
|
+
"Dit is de meest verstrekkende rol die de module heeft. Alles van de tier eronder, plus wat op de tegel staat.",
|
|
250
|
+
moduleAccessRevokeTitle: "De rol in {module} weghalen?",
|
|
251
|
+
moduleAccessRevoke:
|
|
252
|
+
"De toegang in deze module valt terug op wat de rol van deze persoon overal geeft.",
|
|
253
|
+
moduleAccessOrphaned:
|
|
254
|
+
"Staat nog op {role} in {module}, dat geen eigen rol meer accepteert. Het heeft geen effect; het weghalen is de enige wijziging die nog kan.",
|
|
226
255
|
statusColumn: "Status",
|
|
227
256
|
createdColumn: "Aangemaakt",
|
|
228
257
|
statusActive: "Actief",
|
package/src/markers.test.ts
CHANGED
|
@@ -93,6 +93,7 @@ const MARKERS = [
|
|
|
93
93
|
"combobox-option",
|
|
94
94
|
"combobox-token",
|
|
95
95
|
"combobox-token-remove",
|
|
96
|
+
"control-field",
|
|
96
97
|
"control-label",
|
|
97
98
|
"dataview",
|
|
98
99
|
"dataview-actions-cell",
|
|
@@ -234,6 +235,12 @@ const MARKERS = [
|
|
|
234
235
|
"text",
|
|
235
236
|
"theme-toggle",
|
|
236
237
|
"theme-toggle-label",
|
|
238
|
+
"tile",
|
|
239
|
+
"tile-body",
|
|
240
|
+
"tile-delta",
|
|
241
|
+
"tile-group",
|
|
242
|
+
"tile-label",
|
|
243
|
+
"tile-note",
|
|
237
244
|
"toast",
|
|
238
245
|
"toast-body",
|
|
239
246
|
"toast-icon",
|
package/src/styles.test.ts
CHANGED
|
@@ -1446,12 +1446,18 @@ describe("cascade structure", () => {
|
|
|
1446
1446
|
// and each of the six set cursor inline until it migrated. The day a calendar arrow gains
|
|
1447
1447
|
// a min/max bound, this answer changes back.
|
|
1448
1448
|
'[data-terp="iconbutton"]:disabled',
|
|
1449
|
-
// HubPage was the condition for
|
|
1450
|
-
// form: hubcard-body's border
|
|
1451
|
-
//
|
|
1452
|
-
//
|
|
1449
|
+
// HubPage was the condition for this one, and it was the condition in the strongest
|
|
1450
|
+
// form: hubcard-body's border was declared inline on the very element this selector
|
|
1451
|
+
// matches, so no layered rule could reach it at any specificity. That surface comes from
|
|
1452
|
+
// terp.base now.
|
|
1453
|
+
//
|
|
1454
|
+
// Its twin was here until the hub card's hover state came down to the edge alone. The
|
|
1455
|
+
// title's accent colour faced the same inline declaration and retired the same way, so it
|
|
1456
|
+
// belonged in this list on the same evidence — but the selector itself is gone now, and a
|
|
1457
|
+
// rule that does not exist cannot witness anything. Dropping it costs no coverage: the
|
|
1458
|
+
// escalation it stood for retired for a reason this list still records once, in the entry
|
|
1459
|
+
// above, since both halves faced the same inline consumer in the same file.
|
|
1453
1460
|
'[data-terp="hubcard"]:hover [data-terp="hubcard-body"]',
|
|
1454
|
-
'[data-terp="hubcard"]:hover [data-terp="hubcard-title"]',
|
|
1455
1461
|
// AppShell's, and it blocked these two on its own: toggleStyle declared background and
|
|
1456
1462
|
// colour inline on the shell's two toggles, the last elements wearing the icon-button
|
|
1457
1463
|
// marker able to out-rank a layered rule. Their resting look is a scoped base rule now,
|
|
@@ -1707,6 +1713,7 @@ describe("cascade structure", () => {
|
|
|
1707
1713
|
"input",
|
|
1708
1714
|
"input-password",
|
|
1709
1715
|
"field",
|
|
1716
|
+
"control-field",
|
|
1710
1717
|
"control-label",
|
|
1711
1718
|
"checkbox",
|
|
1712
1719
|
"radio",
|
package/src/styles.ts
CHANGED
|
@@ -957,6 +957,60 @@ textarea[data-terp="input"] {
|
|
|
957
957
|
cursor: pointer;
|
|
958
958
|
transition: background-color var(--motion-duration-fast) var(--motion-easing-standard);
|
|
959
959
|
}
|
|
960
|
+
[data-terp="tile-group"] {
|
|
961
|
+
display: grid;
|
|
962
|
+
grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
|
|
963
|
+
gap: var(--space-2);
|
|
964
|
+
}
|
|
965
|
+
[data-terp="tile"] {
|
|
966
|
+
display: flex;
|
|
967
|
+
flex-direction: column;
|
|
968
|
+
gap: var(--space-1);
|
|
969
|
+
padding: var(--space-3);
|
|
970
|
+
border: 1px solid var(--color-neutral-300);
|
|
971
|
+
border-radius: var(--radius-md);
|
|
972
|
+
background: var(--color-neutral-0);
|
|
973
|
+
cursor: pointer;
|
|
974
|
+
transition: border-color var(--motion-duration-fast) var(--motion-easing-standard);
|
|
975
|
+
}
|
|
976
|
+
[data-terp="tile"]:hover:not([aria-disabled="true"]) {
|
|
977
|
+
border-color: var(--color-neutral-600);
|
|
978
|
+
}
|
|
979
|
+
[data-terp="tile"][data-selected] {
|
|
980
|
+
border-color: var(--color-fg-accent);
|
|
981
|
+
background: var(--color-neutral-100);
|
|
982
|
+
}
|
|
983
|
+
/* The floor: a rung already reached some other way (an inherited rung, say). Marked so the
|
|
984
|
+
reader can see that the tier in force is not the one they picked, without it looking
|
|
985
|
+
selected — those are different facts and a single visual state would conflate them. */
|
|
986
|
+
[data-terp="tile"][data-floor] {
|
|
987
|
+
border-style: dashed;
|
|
988
|
+
border-color: var(--color-fg-accent);
|
|
989
|
+
}
|
|
990
|
+
/* Deliberately not the visual gravity a plan picker gives its top tier. This control exists to
|
|
991
|
+
bias downward, so the most privileged tile reads as a decision rather than a recommendation:
|
|
992
|
+
the danger colour is on the border and the label, and there is no fill to make it inviting. */
|
|
993
|
+
[data-terp="tile"][data-tone="danger"] {
|
|
994
|
+
border-color: var(--color-status-danger);
|
|
995
|
+
}
|
|
996
|
+
[data-terp="tile"][data-tone="danger"] [data-terp="tile-label"] {
|
|
997
|
+
color: var(--color-status-danger);
|
|
998
|
+
}
|
|
999
|
+
[data-terp="tile"][aria-disabled="true"] {
|
|
1000
|
+
cursor: not-allowed;
|
|
1001
|
+
color: var(--color-fg-subtle);
|
|
1002
|
+
background: var(--color-neutral-100);
|
|
1003
|
+
}
|
|
1004
|
+
[data-terp="tile-label"] {
|
|
1005
|
+
font-weight: var(--font-weight-semibold);
|
|
1006
|
+
font-size: var(--font-size-sm);
|
|
1007
|
+
}
|
|
1008
|
+
[data-terp="tile-body"] {
|
|
1009
|
+
font-size: var(--font-size-xs);
|
|
1010
|
+
color: var(--color-fg-subtle);
|
|
1011
|
+
display: grid;
|
|
1012
|
+
gap: var(--space-1);
|
|
1013
|
+
}
|
|
960
1014
|
[data-terp="radio-group"] {
|
|
961
1015
|
display: grid;
|
|
962
1016
|
gap: var(--space-2);
|
|
@@ -2354,17 +2408,16 @@ textarea[data-terp="input"] {
|
|
|
2354
2408
|
through an ancestor. hub-card-bare is what catches this one, and only because its full
|
|
2355
2409
|
card is deliberately long enough to set the row height.
|
|
2356
2410
|
|
|
2357
|
-
The transition
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2411
|
+
The transition is ONE property on ONE element, and it used to be three across three.
|
|
2412
|
+
box-shadow and transform animated on the card and colour on the title, because the hover
|
|
2413
|
+
state lifted the card a pixel, gave it a shadow and took the title to accent alongside the
|
|
2414
|
+
edge. The movement is gone (see the state rules for why), and with it both of the card's
|
|
2415
|
+
transitions and the title's — a transition whose property nothing changes is dead weight
|
|
2416
|
+
that reads as a live intention. What remains is the body's border-color, declared on the
|
|
2417
|
+
element that owns the border. */
|
|
2362
2418
|
[data-terp="hubcard"] {
|
|
2363
2419
|
height: 100%;
|
|
2364
2420
|
min-height: 0;
|
|
2365
|
-
transition:
|
|
2366
|
-
box-shadow var(--motion-duration-fast) var(--motion-easing-standard),
|
|
2367
|
-
transform var(--motion-duration-fast) var(--motion-easing-standard);
|
|
2368
2421
|
}
|
|
2369
2422
|
[data-terp="hubcard-body"] {
|
|
2370
2423
|
display: grid;
|
|
@@ -2407,7 +2460,6 @@ textarea[data-terp="input"] {
|
|
|
2407
2460
|
color: var(--color-neutral-900);
|
|
2408
2461
|
font-size: var(--font-size-base);
|
|
2409
2462
|
font-weight: var(--font-weight-semibold);
|
|
2410
|
-
transition: color var(--motion-duration-fast) var(--motion-easing-standard);
|
|
2411
2463
|
}
|
|
2412
2464
|
/* neutral-600 rather than fg-muted, and it is not the tinted-surface case: this text
|
|
2413
2465
|
sits on the card's own neutral-0 and measures 7.58 / 7.94 / 7.50 / 7.60 / 18.42. */
|
|
@@ -3662,6 +3714,16 @@ button[data-terp="input"][data-placeholder="true"] {
|
|
|
3662
3714
|
font-size: var(--font-size-sm);
|
|
3663
3715
|
color: var(--color-neutral-700);
|
|
3664
3716
|
}
|
|
3717
|
+
/* The envelope for the three self-labelling controls (Switch, Checkbox, RadioGroup),
|
|
3718
|
+
which cannot use [data-terp="field"]: that one is a <label> wrapping its control, and
|
|
3719
|
+
these render their own. The justify-items:start is the load-bearing declaration — the
|
|
3720
|
+
control's own <label> is inline-flex, and a stretched grid item would grow its click
|
|
3721
|
+
target to the full column, so clicking empty space far from the text would toggle it. */
|
|
3722
|
+
[data-terp="control-field"] {
|
|
3723
|
+
display: grid;
|
|
3724
|
+
gap: var(--space-1);
|
|
3725
|
+
justify-items: start;
|
|
3726
|
+
}
|
|
3665
3727
|
[data-terp="field-hint"] {
|
|
3666
3728
|
color: var(--color-fg-subtle);
|
|
3667
3729
|
font-size: var(--font-size-xs);
|
|
@@ -4494,30 +4556,42 @@ button[data-terp="input"][data-placeholder="true"] {
|
|
|
4494
4556
|
}
|
|
4495
4557
|
|
|
4496
4558
|
/* Hub cards --------------------------------------------------------------- */
|
|
4497
|
-
/* The hover
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4559
|
+
/* The hover state is the accent edge, and nothing else.
|
|
4560
|
+
|
|
4561
|
+
It was four declarations over three elements: the card lifted a pixel and took a shadow,
|
|
4562
|
+
the body's border went accent, the title's colour went with it. The lift is what people
|
|
4563
|
+
actually noticed, and not kindly. A hub is a grid of large targets, so a pointer on its way
|
|
4564
|
+
to one card sweeps across every card between here and there, and each one twitched as it
|
|
4565
|
+
passed — motion reporting the cursor's position, which the cursor already reports. Movement
|
|
4566
|
+
in an interface should say something the still frame cannot; this said nothing, on a surface
|
|
4567
|
+
that shows several of itself at once. The shadow went with it rather than separately: a
|
|
4568
|
+
1px rise and a 1px shadow are one effect, elevation, and half of an elevation reads as a
|
|
4569
|
+
rendering fault rather than as restraint.
|
|
4570
|
+
|
|
4571
|
+
That leaves the edge to carry the whole state, and it is enough to: accent against
|
|
4572
|
+
neutral-200 is the same signal the rest of the sheet uses for is-this-one, it lands on the
|
|
4573
|
+
element the pointer is actually over, and it moves no layout. The title's accent came off
|
|
4574
|
+
with it — not because it was objectionable, but because two properties saying one thing is
|
|
4575
|
+
how a hover state grows back into four.
|
|
4576
|
+
|
|
4577
|
+
The edge recolours hubcard-BODY, not the card, and that distinction is the reason this rule
|
|
4578
|
+
was dead for as long as it was. It used to set border-color on [data-terp="hubcard"], the
|
|
4579
|
+
outer <li>, which has no border at all: HubPage puts the visible edge on the inner
|
|
4580
|
+
hubcard-body span. Measured in a browser rather than reasoned about, because no baseline
|
|
4581
|
+
captures a hover — the li computed border 0px none at rest and 0px none in the accent colour
|
|
4582
|
+
on hover, while the shadow and the transform, being on the element that could take them, did
|
|
4583
|
+
apply. So through that whole period the hover was a lift with no edge, the exact inverse of
|
|
4584
|
+
what it is now.
|
|
4585
|
+
|
|
4586
|
+
THE ESCALATION IS GONE, and this file was the condition for it. hubcard-body's border was
|
|
4587
|
+
declared inline in HubPage, on the very element this selector matches, so no layered rule
|
|
4588
|
+
could reach it at any specificity. That surface takes its base from terp.base now, so layer
|
|
4589
|
+
order alone is enough. The title's colour was the same story and retired the same way; its
|
|
4590
|
+
hover half is gone with the rest of the state, so one of the seven is now moot rather than
|
|
4591
|
+
merely retired. */
|
|
4515
4592
|
[data-terp="hubcard"]:hover [data-terp="hubcard-body"] {
|
|
4516
4593
|
border-color: var(--color-fg-accent);
|
|
4517
4594
|
}
|
|
4518
|
-
[data-terp="hubcard"]:hover [data-terp="hubcard-title"] {
|
|
4519
|
-
color: var(--color-fg-accent);
|
|
4520
|
-
}
|
|
4521
4595
|
|
|
4522
4596
|
/* Which layout is active, expressed as more than a wash. terp.state, and keyed on the
|
|
4523
4597
|
real ARIA attribute — the [data-terp="tab"][aria-selected="true"] precedent — and the
|
|
@@ -4781,14 +4855,18 @@ button[data-terp="input"][data-placeholder="true"] {
|
|
|
4781
4855
|
THE LAST ESCALATION IN THE SHEET IS GONE, and it was the widest. Its
|
|
4782
4856
|
consumers were the three inline transitions left in the package: the shell's
|
|
4783
4857
|
nav-link transition (NAV_LINK_STYLE), the hub card title's (titleTextStyle)
|
|
4784
|
-
and the sidebar's own transition: width. The first
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4858
|
+
and the sidebar's own transition: width. The first became a rule; the second
|
|
4859
|
+
became a rule and has since gone entirely, with the title's hover colour that
|
|
4860
|
+
was its only reason to exist; the third was the documented escape — the aside
|
|
4861
|
+
carried no marker, so nothing here matched it and a reduced-motion user
|
|
4862
|
+
watched the rail animate — and it is closed by the sidebar taking a marker and
|
|
4863
|
+
its width becoming a rule. With no style attribute left to out-shout, layer
|
|
4864
|
+
order alone wins: terp.motion sits above terp.base and terp.state, so
|
|
4865
|
+
transition: none needs nothing shouted. Measured, not assumed: under
|
|
4866
|
+
prefers-reduced-motion the sidebar, a nav link and a hub card BODY all compute
|
|
4867
|
+
transition-duration 0s. The body rather than the title, and the swap is the
|
|
4868
|
+
point rather than a tidy-up: the title has no transition to suppress any more,
|
|
4869
|
+
so asserting 0s on it would pass against a default and witness nothing. */
|
|
4792
4870
|
@media (prefers-reduced-motion: reduce) {
|
|
4793
4871
|
[data-terp],
|
|
4794
4872
|
[data-terp="appshell-nav"] a,
|
package/src/ui/Checkbox.tsx
CHANGED
|
@@ -3,40 +3,74 @@ import type { ChangeEvent, InputHTMLAttributes } from "react";
|
|
|
3
3
|
import { injectTerpStyles } from "../styles";
|
|
4
4
|
import { useUiText } from "../uiText";
|
|
5
5
|
import type { UiText } from "../uiText";
|
|
6
|
+
import { mergeDescribedBy, useControlMessages } from "./controlMessages";
|
|
6
7
|
|
|
7
8
|
injectTerpStyles();
|
|
8
9
|
|
|
9
10
|
export interface CheckboxProps
|
|
10
11
|
extends Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "checked" | "defaultChecked" | "onChange"> {
|
|
11
12
|
label: UiText;
|
|
13
|
+
/** Optional helper text under the control (pointed at by `aria-describedby`). */
|
|
14
|
+
hint?: UiText;
|
|
15
|
+
/** A control-level error, shown under the control and announced when it appears. */
|
|
16
|
+
error?: string | null;
|
|
12
17
|
checked?: boolean;
|
|
13
18
|
defaultChecked?: boolean;
|
|
14
19
|
onChange?: (checked: boolean) => void;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Token-styled labelled checkbox — use instead of a raw `<input type="checkbox">`.
|
|
24
|
+
*
|
|
25
|
+
* It carries its own `hint` / `error` rather than going inside a `Field`, because it cannot
|
|
26
|
+
* go inside one: the checkbox renders its own `<label>` around the input, and a `<label>`
|
|
27
|
+
* within `Field`'s `<label>` is invalid HTML — the browser associates the control with the
|
|
28
|
+
* outer one and the field's label text is lost. The wiring is shared with `Field` through
|
|
29
|
+
* `useControlMessages`, so the ids, `aria-describedby`, `aria-invalid` and the error's
|
|
30
|
+
* `role="alert"` behave identically here.
|
|
31
|
+
*/
|
|
32
|
+
export function Checkbox({
|
|
33
|
+
label,
|
|
34
|
+
hint,
|
|
35
|
+
error,
|
|
36
|
+
checked,
|
|
37
|
+
defaultChecked,
|
|
38
|
+
onChange,
|
|
39
|
+
style,
|
|
40
|
+
...rest
|
|
41
|
+
}: CheckboxProps) {
|
|
19
42
|
const resolve = useUiText();
|
|
43
|
+
const { hasError, describedBy, messages } = useControlMessages(hint, error);
|
|
20
44
|
return (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
// The wrapper is unconditional, and that is not cosmetic. Rendering it only when there is
|
|
46
|
+
// a message would change the element type at this position the moment an error arrives,
|
|
47
|
+
// so React would unmount the label and mount a fresh input — an uncontrolled checkbox
|
|
48
|
+
// would silently lose its state exactly when the form told the user something was wrong.
|
|
49
|
+
<div data-terp="control-field" style={style}>
|
|
50
|
+
<label data-terp="control-label">
|
|
51
|
+
<input
|
|
52
|
+
{...rest}
|
|
53
|
+
type="checkbox"
|
|
54
|
+
data-terp="checkbox"
|
|
55
|
+
checked={checked}
|
|
56
|
+
defaultChecked={defaultChecked}
|
|
57
|
+
// A caller who pointed the control at their own description keeps it: the field's
|
|
58
|
+
// ids are added to theirs, never substituted for them.
|
|
59
|
+
aria-describedby={mergeDescribedBy(rest["aria-describedby"], describedBy)}
|
|
60
|
+
aria-invalid={rest["aria-invalid"] ?? (hasError ? true : undefined)}
|
|
61
|
+
// Attached only when there is something to call, exactly as Select does and for the
|
|
62
|
+
// reason stated there: an unconditional handler silences React's own "you provided a
|
|
63
|
+
// `checked` prop to a form field without an `onChange` handler" guard, so a caller who
|
|
64
|
+
// pinned `checked` and forgot the handler gets a control that looks operable, never
|
|
65
|
+
// changes, and says nothing about it. The spread form is what keeps the prop absent
|
|
66
|
+
// rather than present-and-undefined, which React treats as the same mistake.
|
|
67
|
+
{...(onChange !== undefined
|
|
68
|
+
? { onChange: (event: ChangeEvent<HTMLInputElement>) => onChange(event.currentTarget.checked) }
|
|
69
|
+
: {})}
|
|
70
|
+
/>
|
|
71
|
+
<span>{resolve(label)}</span>
|
|
72
|
+
</label>
|
|
73
|
+
{messages}
|
|
74
|
+
</div>
|
|
40
75
|
);
|
|
41
76
|
}
|
|
42
|
-
|