@hadoku/game-ui 0.1.136 → 0.1.138
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.
|
@@ -3,7 +3,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
* A choice of one, drawn as a row of cards: the room's type and mode in the
|
|
4
4
|
* create form, the mode in the room, and each mode's own options.
|
|
5
5
|
*
|
|
6
|
-
* Native radio inputs, one per card, laid over the whole card and transparent
|
|
6
|
+
* Native radio inputs, one per card, laid over the whole card and transparent, choosing on
|
|
7
|
+
* their click (`./choice.ts` has why, not their change):
|
|
7
8
|
* the keyboard (Tab to the group, arrows between cards), `disabled` and
|
|
8
9
|
* `checked` are the browser's own, and a press anywhere on a card lands on its
|
|
9
10
|
* input. The checked card wears the format tabs' look (`.lobby__format-tabs`),
|
|
@@ -20,12 +21,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
20
21
|
* `renderRow`, wave 73 §B's cube picker: a row that needs more than a label —
|
|
21
22
|
* a size, an importer, its own refresh/delete buttons beside the radio, not
|
|
22
23
|
* inside it. `input` is the SAME wired element every other card gets (name,
|
|
23
|
-
* value, checked, disabled,
|
|
24
|
+
* value, checked, disabled, its click, test id); `renderRow` only chooses what
|
|
24
25
|
* markup it sits in, so the input's own behaviour is never duplicated.
|
|
25
26
|
* Every other caller leaves it unset and gets the plain card exactly as
|
|
26
27
|
* before — this is additive, not a second way to draw the same thing.
|
|
27
28
|
*/
|
|
28
29
|
import { Fragment } from 'react';
|
|
30
|
+
import { choiceInput } from "./choice.js";
|
|
29
31
|
import './RadioCards.css';
|
|
30
32
|
export function RadioCards({ name, label, options, value, disabled = false, onChange, testId, size = 'small', className, renderRow, }) {
|
|
31
33
|
const large = size === 'large';
|
|
@@ -33,7 +35,10 @@ export function RadioCards({ name, label, options, value, disabled = false, onCh
|
|
|
33
35
|
const shape = large ? 'radio-cards--large' : renderRow === undefined ? 'radio-cards--segmented' : null;
|
|
34
36
|
const rootClass = ['radio-cards', shape, className].filter((c) => c !== undefined && c !== null && c !== '').join(' ');
|
|
35
37
|
return (_jsx("div", { className: rootClass, role: "radiogroup", "aria-label": label, "aria-disabled": disabled ? 'true' : undefined, "data-testid": testId, children: options.map((option) => {
|
|
36
|
-
const input = (_jsx("input", { className: "radio-cards__input", type: "radio", name: name, value: option.value, "data-testid": `${testId}-${option.value}`, checked: value === option.value, disabled: disabled || option.disabled === true,
|
|
38
|
+
const input = (_jsx("input", { className: "radio-cards__input", type: "radio", name: name, value: option.value, "data-testid": `${testId}-${option.value}`, checked: value === option.value, disabled: disabled || option.disabled === true, ...choiceInput(() => {
|
|
39
|
+
if (value !== option.value)
|
|
40
|
+
onChange(option.value);
|
|
41
|
+
}) }));
|
|
37
42
|
if (renderRow !== undefined)
|
|
38
43
|
return _jsx(Fragment, { children: renderRow(option, input) }, option.value);
|
|
39
44
|
return (_jsxs("label", { className: "radio-cards__card", children: [input, option.art !== undefined && _jsx("img", { className: "radio-cards__art", src: option.art, alt: "", decoding: "async", draggable: false }), _jsx("span", { className: "radio-cards__label", children: option.label })] }, option.value));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MouseEvent } from 'react';
|
|
2
|
+
export interface ChoiceInputProps {
|
|
3
|
+
readOnly: true;
|
|
4
|
+
onClick: (event: MouseEvent<HTMLInputElement>) => void;
|
|
5
|
+
}
|
|
6
|
+
/** Spread on a controlled `<input type="checkbox|radio">`: `choose` runs once per click that chose it. */
|
|
7
|
+
export declare function choiceInput(choose: () => void): ChoiceInputProps;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How a controlled checkbox or radio makes its choice: on the input's own click, never its change.
|
|
3
|
+
*
|
|
4
|
+
* React reads a click on a checkbox or radio as a change only if the input's `checked` differs from
|
|
5
|
+
* the value it last rendered. Anything that renders while the click is still being dispatched (a
|
|
6
|
+
* store updated from a capture listener ahead of React's root renders at once, at the click's
|
|
7
|
+
* discrete priority) puts the controlled input back to its old `checked` first, and React then fires
|
|
8
|
+
* no `onChange`: the click is lost. CI caught it eight times on a room's radios (2026-11-22..24, the
|
|
9
|
+
* click trail: ticked at window capture, unticked by document capture, no write); a headless
|
|
10
|
+
* Chromium page reproduces it with one listener and one store.
|
|
11
|
+
*
|
|
12
|
+
* The click itself always reaches React, and the keyboard's own choices are clicks too (Space on
|
|
13
|
+
* either, an arrow between radios), so choosing there loses nothing. `checked` stays the caller's
|
|
14
|
+
* alone (`readOnly` tells React the input is controlled without a change handler), and a second
|
|
15
|
+
* click of a double click (`detail > 1`) is not a second choice.
|
|
16
|
+
*/
|
|
17
|
+
/** Spread on a controlled `<input type="checkbox|radio">`: `choose` runs once per click that chose it. */
|
|
18
|
+
export function choiceInput(choose) {
|
|
19
|
+
return {
|
|
20
|
+
readOnly: true,
|
|
21
|
+
onClick: (event) => {
|
|
22
|
+
if (event.detail > 1)
|
|
23
|
+
return;
|
|
24
|
+
choose();
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-ui",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.138",
|
|
4
|
+
"gitHead": "ed03503dc76036ff1b7958c7e56174c396f1a80a",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
"react-dom": "^19.2.8"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
58
|
-
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.
|
|
57
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.142",
|
|
58
|
+
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.142",
|
|
59
59
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
|
|
60
|
-
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.
|
|
61
|
-
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.
|
|
60
|
+
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.142",
|
|
61
|
+
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.142",
|
|
62
62
|
"@wolffm/task-ui-components": "npm:@hadoku/task-ui-components@^4.23.49",
|
|
63
63
|
"@wolffm/themes": "npm:@hadoku/themes@^5.14.19",
|
|
64
|
-
"@wolffm/watchparty-ui": "npm:@hadoku/watchparty-ui@^0.45.
|
|
64
|
+
"@wolffm/watchparty-ui": "npm:@hadoku/watchparty-ui@^0.45.142",
|
|
65
65
|
"socket.io-client": "^4.8.3",
|
|
66
66
|
"zod": "4.5.4"
|
|
67
67
|
},
|