@cosmicdrift/kumiko-renderer-web 0.243.4 → 0.245.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-renderer-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.245.0",
|
|
4
4
|
"description": "Web-platform bindings for @cosmicdrift/kumiko-renderer. HTML default-primitives, browser history-based navigation, EventSource-backed live events, and a one-call createKumikoApp that mounts the whole stack via react-dom.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"./styles.css": "./src/styles.css"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@cosmicdrift/kumiko-dispatcher-live": "0.
|
|
20
|
-
"@cosmicdrift/kumiko-headless": "0.
|
|
21
|
-
"@cosmicdrift/kumiko-renderer": "0.
|
|
19
|
+
"@cosmicdrift/kumiko-dispatcher-live": "0.245.0",
|
|
20
|
+
"@cosmicdrift/kumiko-headless": "0.245.0",
|
|
21
|
+
"@cosmicdrift/kumiko-renderer": "0.245.0",
|
|
22
22
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
23
23
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
24
24
|
"@radix-ui/react-label": "^2.1.8",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@types/react-dom": "^19.2.3",
|
|
65
65
|
"jsdom": "^29.1.1",
|
|
66
66
|
"tailwindcss": "^4.3.0",
|
|
67
|
-
"@cosmicdrift/kumiko-locale-de": "0.
|
|
67
|
+
"@cosmicdrift/kumiko-locale-de": "0.245.0"
|
|
68
68
|
},
|
|
69
69
|
"repository": {
|
|
70
70
|
"type": "git",
|
|
@@ -1743,10 +1743,27 @@ describe("PageSection", () => {
|
|
|
1743
1743
|
<span data-testid="child">x</span>
|
|
1744
1744
|
</PageSection>,
|
|
1745
1745
|
);
|
|
1746
|
-
expect(screen.getByTestId("p").className).toContain("
|
|
1746
|
+
expect(screen.getByTestId("p").className).toContain("px-6");
|
|
1747
1747
|
expect(screen.getByTestId("child")).toBeDefined();
|
|
1748
1748
|
});
|
|
1749
1749
|
|
|
1750
|
+
test("renders the same padding classes as FormScreenShell (fw#2640)", () => {
|
|
1751
|
+
render(
|
|
1752
|
+
<>
|
|
1753
|
+
<PageSection testId="page-pad">x</PageSection>
|
|
1754
|
+
<FormScreenShell testId="shell-pad">x</FormScreenShell>
|
|
1755
|
+
</>,
|
|
1756
|
+
);
|
|
1757
|
+
const paddingOf = (testId: string): string[] =>
|
|
1758
|
+
screen
|
|
1759
|
+
.getByTestId(testId)
|
|
1760
|
+
.className.split(" ")
|
|
1761
|
+
.filter((c) => /^p[xytblr]?-/.test(c))
|
|
1762
|
+
.sort();
|
|
1763
|
+
expect(paddingOf("page-pad")).toEqual(["pb-12", "pt-6", "px-6"]);
|
|
1764
|
+
expect(paddingOf("page-pad")).toEqual(paddingOf("shell-pad"));
|
|
1765
|
+
});
|
|
1766
|
+
|
|
1750
1767
|
test("maxWidth=4xl sets the same width class as FormScreenShell maxWidth=4xl (fw#2640)", () => {
|
|
1751
1768
|
render(
|
|
1752
1769
|
<>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// `kind: "select"` with an explicit `display` (#2711). The short-option-set
|
|
2
|
+
// heuristic covered by select-segmented.test.tsx stays the default; these
|
|
3
|
+
// tests only cover the case where the caller states a presentation and the
|
|
4
|
+
// heuristic would have decided the other way.
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from "bun:test";
|
|
7
|
+
import { fireEvent } from "@testing-library/react";
|
|
8
|
+
import { render, screen } from "../../__tests__/test-utils";
|
|
9
|
+
import { defaultPrimitives } from "../index";
|
|
10
|
+
|
|
11
|
+
const { Field, Input } = defaultPrimitives;
|
|
12
|
+
|
|
13
|
+
// Six options, every label past the 14-char threshold — the heuristic would
|
|
14
|
+
// render a dropdown for these.
|
|
15
|
+
const HEURISTIC_REJECTS = [
|
|
16
|
+
"Background Jobs Queue",
|
|
17
|
+
"Inbound Mail Processing",
|
|
18
|
+
"Realtime Event Stream",
|
|
19
|
+
"Scheduled Reporting",
|
|
20
|
+
"Tenant Provisioning",
|
|
21
|
+
"Search Index Rebuild",
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
// Three short labels — the heuristic would render the radio group for these.
|
|
25
|
+
const HEURISTIC_ACCEPTS = ["Draft", "Review", "Done"];
|
|
26
|
+
|
|
27
|
+
function renderSelect(
|
|
28
|
+
options: readonly string[],
|
|
29
|
+
overrides: {
|
|
30
|
+
readonly display?: "radio" | "dropdown";
|
|
31
|
+
readonly value?: string;
|
|
32
|
+
} = {},
|
|
33
|
+
): string[] {
|
|
34
|
+
const changes: string[] = [];
|
|
35
|
+
render(
|
|
36
|
+
<Field id="area" label="Area" testId="field-area">
|
|
37
|
+
<Input
|
|
38
|
+
kind="select"
|
|
39
|
+
id="area"
|
|
40
|
+
name="area"
|
|
41
|
+
value={overrides.value ?? options[0] ?? ""}
|
|
42
|
+
onChange={(v) => changes.push(v)}
|
|
43
|
+
options={options}
|
|
44
|
+
{...(overrides.display !== undefined && { display: overrides.display })}
|
|
45
|
+
/>
|
|
46
|
+
</Field>,
|
|
47
|
+
);
|
|
48
|
+
return changes;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe("DefaultInput select — explicit display request", () => {
|
|
52
|
+
test('display: "radio" renders the radio group even where the heuristic says dropdown', () => {
|
|
53
|
+
renderSelect(HEURISTIC_REJECTS, { display: "radio" });
|
|
54
|
+
expect(screen.queryByTestId("combobox-area")).toBeNull();
|
|
55
|
+
expect(screen.getAllByRole("radio")).toHaveLength(6);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("the forced radio group keeps the accessible group name and checked state", () => {
|
|
59
|
+
renderSelect(HEURISTIC_REJECTS, {
|
|
60
|
+
display: "radio",
|
|
61
|
+
value: "Realtime Event Stream",
|
|
62
|
+
});
|
|
63
|
+
expect(screen.getByRole("radiogroup", { name: "Area" })).toBeTruthy();
|
|
64
|
+
expect(
|
|
65
|
+
screen.getByRole("radio", { name: "Realtime Event Stream" }).getAttribute("aria-checked"),
|
|
66
|
+
).toBe("true");
|
|
67
|
+
expect(
|
|
68
|
+
screen.getByRole("radio", { name: "Background Jobs Queue" }).getAttribute("aria-checked"),
|
|
69
|
+
).toBe("false");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("the forced radio group reports the raw option value on click", () => {
|
|
73
|
+
const changes = renderSelect(HEURISTIC_REJECTS, {
|
|
74
|
+
display: "radio",
|
|
75
|
+
value: "Background Jobs Queue",
|
|
76
|
+
});
|
|
77
|
+
fireEvent.click(screen.getByRole("radio", { name: "Search Index Rebuild" }));
|
|
78
|
+
expect(changes).toEqual(["Search Index Rebuild"]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('display: "dropdown" keeps the dropdown where the heuristic says radio group', () => {
|
|
82
|
+
renderSelect(HEURISTIC_ACCEPTS, { display: "dropdown" });
|
|
83
|
+
expect(screen.queryByRole("radiogroup")).toBeNull();
|
|
84
|
+
expect(screen.getByTestId("combobox-area")).toBeTruthy();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("no display stated: the heuristic still decides", () => {
|
|
88
|
+
renderSelect(HEURISTIC_REJECTS);
|
|
89
|
+
expect(screen.getByTestId("combobox-area")).toBeTruthy();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('display: "radio" without options falls back to the dropdown, not an empty group', () => {
|
|
93
|
+
renderSelect([], { display: "radio" });
|
|
94
|
+
expect(screen.queryByRole("radiogroup")).toBeNull();
|
|
95
|
+
expect(screen.getByTestId("combobox-area")).toBeTruthy();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("labelled options render their label and report their value", () => {
|
|
99
|
+
const changes: string[] = [];
|
|
100
|
+
render(
|
|
101
|
+
<Field id="area" label="Area" testId="field-area">
|
|
102
|
+
<Input
|
|
103
|
+
kind="select"
|
|
104
|
+
id="area"
|
|
105
|
+
name="area"
|
|
106
|
+
value="jobs"
|
|
107
|
+
onChange={(v) => changes.push(v)}
|
|
108
|
+
display="radio"
|
|
109
|
+
options={[
|
|
110
|
+
{ value: "jobs", label: "Background Jobs Queue" },
|
|
111
|
+
{ value: "mail", label: "Inbound Mail Processing" },
|
|
112
|
+
{ value: "search", label: "Search Index Rebuild" },
|
|
113
|
+
{ value: "events", label: "Realtime Event Stream" },
|
|
114
|
+
{ value: "tenants", label: "Tenant Provisioning" },
|
|
115
|
+
]}
|
|
116
|
+
/>
|
|
117
|
+
</Field>,
|
|
118
|
+
);
|
|
119
|
+
fireEvent.click(screen.getByRole("radio", { name: "Inbound Mail Processing" }));
|
|
120
|
+
expect(changes).toEqual(["mail"]);
|
|
121
|
+
});
|
|
122
|
+
});
|
package/src/primitives/index.tsx
CHANGED
|
@@ -110,7 +110,7 @@ import {
|
|
|
110
110
|
import { EmbeddedListInput } from "./embedded-list-input";
|
|
111
111
|
import { FileUploadInput } from "./file-upload";
|
|
112
112
|
import { DefaultJsonView } from "./json-view";
|
|
113
|
-
import { screenWidthClassName } from "./layout";
|
|
113
|
+
import { screenPaddingClassName, screenWidthClassName } from "./layout";
|
|
114
114
|
import { DefaultLightbox } from "./lightbox";
|
|
115
115
|
import { LocatedTimestampInput } from "./located-timestamp-input";
|
|
116
116
|
import { DefaultMetric } from "./metric";
|
|
@@ -422,11 +422,10 @@ function withUnitSuffix(unit: string | undefined, input: ReactNode): ReactNode {
|
|
|
422
422
|
);
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
//
|
|
425
|
+
// Default presentation for `kind: "select"` with a small closed option set —
|
|
426
426
|
// a 4-value Status field looked wrong stretched into a full-width dropdown
|
|
427
|
-
// (edit-existing screenshot feedback).
|
|
428
|
-
//
|
|
429
|
-
// `options` + string value/onChange).
|
|
427
|
+
// (edit-existing screenshot feedback). Only consulted when the caller states
|
|
428
|
+
// no `display` of its own; an explicit `display` wins (#2711).
|
|
430
429
|
const SEGMENTED_SELECT_MAX_OPTIONS = 4;
|
|
431
430
|
const SEGMENTED_SELECT_MAX_LABEL_LENGTH = 14;
|
|
432
431
|
|
|
@@ -699,7 +698,13 @@ function DefaultInput(props: InputProps): ReactNode {
|
|
|
699
698
|
const comboOptions = props.options.map((o) =>
|
|
700
699
|
typeof o === "string" ? { value: o, label: o } : o,
|
|
701
700
|
);
|
|
702
|
-
|
|
701
|
+
// An explicit `display` is an author decision and outranks the
|
|
702
|
+
// heuristic in both directions — a requested radio group renders as
|
|
703
|
+
// one even when the labels are long or numerous (#2711).
|
|
704
|
+
const wantsRadioGroup =
|
|
705
|
+
props.display === "radio" ||
|
|
706
|
+
(props.display === undefined && isSegmentedSelectEligible(comboOptions));
|
|
707
|
+
if (wantsRadioGroup && comboOptions.length > 0) {
|
|
703
708
|
return (
|
|
704
709
|
<SegmentedSelect
|
|
705
710
|
id={props.id}
|
|
@@ -2261,7 +2266,7 @@ export function FormScreenShell({
|
|
|
2261
2266
|
return (
|
|
2262
2267
|
<div
|
|
2263
2268
|
data-testid={testId}
|
|
2264
|
-
className={cn("
|
|
2269
|
+
className={cn(screenPaddingClassName, "w-full", screenWidthClassName[width], className)}
|
|
2265
2270
|
>
|
|
2266
2271
|
{children}
|
|
2267
2272
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Layout primitives for custom screens: one place for vertical spacing and
|
|
2
|
-
// screen padding, so consumers don't hand-roll `flex flex-col gap-*` /
|
|
2
|
+
// screen padding, so consumers don't hand-roll `flex flex-col gap-*` / screen insets.
|
|
3
3
|
// Deliberately thin — not a generic box-with-20-props system.
|
|
4
4
|
|
|
5
5
|
import type { FormWidth } from "@cosmicdrift/kumiko-renderer";
|
|
@@ -17,6 +17,12 @@ export const screenWidthClassName: Record<ScreenWidth, string> = {
|
|
|
17
17
|
full: "max-w-full",
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
// Shared screen padding for both screen containers (PageSection and
|
|
21
|
+
// FormScreenShell). The wider bottom inset keeps the last field or table row
|
|
22
|
+
// off the viewport edge; applying it everywhere makes footer spacing
|
|
23
|
+
// independent of the screen type (fw#2640).
|
|
24
|
+
export const screenPaddingClassName = "px-6 pt-6 pb-12";
|
|
25
|
+
|
|
20
26
|
const STACK_GAP = { sm: "gap-2", md: "gap-4", lg: "gap-6" } as const;
|
|
21
27
|
|
|
22
28
|
type StackGap = keyof typeof STACK_GAP;
|
|
@@ -50,7 +56,10 @@ export function PageSection({
|
|
|
50
56
|
maxWidth = "full",
|
|
51
57
|
}: PageSectionProps): ReactNode {
|
|
52
58
|
return (
|
|
53
|
-
<div
|
|
59
|
+
<div
|
|
60
|
+
data-testid={testId}
|
|
61
|
+
className={cn(screenPaddingClassName, screenWidthClassName[maxWidth], className)}
|
|
62
|
+
>
|
|
54
63
|
{children}
|
|
55
64
|
</div>
|
|
56
65
|
);
|