@hadoku/game-ui 0.1.109 → 0.1.111
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.
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* `RoomSettings.tsx`: the Room settings button, and its popover's rows, a label beside its control.
|
|
3
|
+
* The rows are TWO direct children of the grid each (the component's header says why), so
|
|
4
|
+
* `max-content` on column 1 sizes it to the widest label and every control's left edge sits at
|
|
5
|
+
* that one x.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* The button's size; its colour and hover are `.ct-action` (`Button.css`) unless a game passes its own. */
|
|
9
|
+
.room-settings__trigger {
|
|
10
|
+
display: inline-flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
gap: 0.35rem;
|
|
13
|
+
flex: none;
|
|
14
|
+
align-self: flex-start;
|
|
15
|
+
padding: 0.2rem 0.6rem;
|
|
16
|
+
font: inherit;
|
|
17
|
+
font-size: 0.85em;
|
|
18
|
+
line-height: 1.2;
|
|
19
|
+
border-radius: var(--hdk-radius);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.room-settings__list {
|
|
23
|
+
display: grid;
|
|
24
|
+
grid-template-columns: max-content 1fr;
|
|
25
|
+
align-items: center;
|
|
26
|
+
column-gap: 16px;
|
|
27
|
+
row-gap: 10px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.room-settings__label {
|
|
31
|
+
display: inline-flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
gap: 0.3rem;
|
|
34
|
+
color: var(--color-text-secondary);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.room-settings__lock {
|
|
38
|
+
opacity: 0.8;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.room-settings__switch {
|
|
42
|
+
justify-self: start;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* A switch with its own choices beside it (Magic's pick timer and its speed), in one cell. */
|
|
46
|
+
.room-settings__pair {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-wrap: wrap;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: 8px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* An on/off switch: the radio cards' own pill (`RadioCards.css`), one width, so "On" and "Off" are not two sizes. */
|
|
54
|
+
.room-settings__toggle {
|
|
55
|
+
min-width: 3rem;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
padding: 0.35rem 0.75rem;
|
|
58
|
+
background: var(--color-bg-alt);
|
|
59
|
+
color: var(--color-text-secondary);
|
|
60
|
+
border: 1px solid var(--color-border-light);
|
|
61
|
+
border-radius: var(--hdk-radius);
|
|
62
|
+
font: inherit;
|
|
63
|
+
font-size: 12px;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.room-settings__toggle[aria-pressed='true'] {
|
|
68
|
+
background: var(--color-primary);
|
|
69
|
+
color: var(--color-on-primary);
|
|
70
|
+
border-color: var(--color-primary);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.room-settings__toggle:disabled,
|
|
74
|
+
.room-settings__number:disabled {
|
|
75
|
+
cursor: default;
|
|
76
|
+
opacity: 0.6;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.room-settings__number {
|
|
80
|
+
width: 5rem;
|
|
81
|
+
padding: 0.3rem 0.5rem;
|
|
82
|
+
background: var(--color-bg-alt);
|
|
83
|
+
color: var(--color-text);
|
|
84
|
+
border: 1px solid var(--color-border-light);
|
|
85
|
+
border-radius: var(--hdk-radius);
|
|
86
|
+
font: inherit;
|
|
87
|
+
font-size: 12px;
|
|
88
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type AnyRoomSettings, type SettingField } from '@wolffm/platform-wire/room-settings';
|
|
3
|
+
import './Button.css';
|
|
4
|
+
import './RoomSettings.css';
|
|
5
|
+
/** The Room settings button and its popover, holding `children` as its rows. */
|
|
6
|
+
export declare function RoomSettingsPopover({ testId, title, triggerClassName, children, }: {
|
|
7
|
+
/** The button's test id; the popover's is `<testId>-popover`. */
|
|
8
|
+
testId?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
/** The button's look, for a game whose bar draws its buttons its own way. */
|
|
11
|
+
triggerClassName?: string;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
/** One row's two grid cells: the setting's name (with the lock while it holds), then its control. */
|
|
15
|
+
export declare function SettingRow({ label, locked, children }: {
|
|
16
|
+
label: string;
|
|
17
|
+
locked?: boolean;
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}): import("react").JSX.Element;
|
|
20
|
+
/**
|
|
21
|
+
* An on/off switch. Its press counts in the usage as `<testId>-on` or `<testId>-off`, or as
|
|
22
|
+
* `actions` names them (what turning it on, and off, is called). `className` adds to its own.
|
|
23
|
+
*/
|
|
24
|
+
export declare function SettingToggle({ on, onPress, disabled, testId, className, actions, }: {
|
|
25
|
+
on: boolean;
|
|
26
|
+
onPress: () => void;
|
|
27
|
+
disabled: boolean;
|
|
28
|
+
testId: string;
|
|
29
|
+
className?: string;
|
|
30
|
+
actions?: {
|
|
31
|
+
on: string;
|
|
32
|
+
off: string;
|
|
33
|
+
};
|
|
34
|
+
}): import("react").JSX.Element;
|
|
35
|
+
/**
|
|
36
|
+
* A declared field's control: a toggle, a row of cards for a choice, a number input for a bounded
|
|
37
|
+
* number. Null for a `custom` field, which its game draws itself. `toggleClassName` adds to a
|
|
38
|
+
* toggle's classes.
|
|
39
|
+
*/
|
|
40
|
+
export declare function SettingControl({ field, name, value, disabled, onChange, testId, toggleClassName, }: {
|
|
41
|
+
field: SettingField;
|
|
42
|
+
/** The field's key: the radio group's name. */
|
|
43
|
+
name: string;
|
|
44
|
+
value: unknown;
|
|
45
|
+
disabled: boolean;
|
|
46
|
+
onChange: (next: unknown) => void;
|
|
47
|
+
testId: string;
|
|
48
|
+
toggleClassName?: string;
|
|
49
|
+
}): import("react").JSX.Element | null;
|
|
50
|
+
/** A key as a test id: `pickTimer` → `pick-timer`. */
|
|
51
|
+
export declare const settingTestId: (key: string) => string;
|
|
52
|
+
/**
|
|
53
|
+
* Every field the declaration can draw, in its order, behind the Room settings button. Null when it
|
|
54
|
+
* has none to draw.
|
|
55
|
+
*/
|
|
56
|
+
export declare function RoomSettingsPanel({ spec, value, leader, live, busy, locked, onChange, only, testId, }: {
|
|
57
|
+
spec: AnyRoomSettings;
|
|
58
|
+
/** The room body's `settings`. */
|
|
59
|
+
value: Readonly<Record<string, unknown>>;
|
|
60
|
+
/** Only the leader moves a setting; everybody else reads them. */
|
|
61
|
+
leader: boolean;
|
|
62
|
+
/** A match is live: every `LIVE` field is locked. */
|
|
63
|
+
live?: boolean;
|
|
64
|
+
/** A change is on its way: nothing moves until it lands. */
|
|
65
|
+
busy?: boolean;
|
|
66
|
+
/** Whether a lock of the game's own (any but `LIVE`) holds now. Default: none ever does. */
|
|
67
|
+
locked?: (lock: string) => boolean;
|
|
68
|
+
/** The leader's change: one field at a time, as `PATCH /:id { settings }` takes it. */
|
|
69
|
+
onChange: (patch: Record<string, unknown>) => void;
|
|
70
|
+
/** The fields to draw, in this order; default every field the declaration can draw. */
|
|
71
|
+
only?: readonly string[];
|
|
72
|
+
testId?: string;
|
|
73
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from '@wolffm/themes';
|
|
3
|
+
import { LIVE } from '@wolffm/platform-wire/room-settings';
|
|
4
|
+
import { uiLength } from '@wolffm/ui-shell/settings';
|
|
5
|
+
import { ActionButton } from "./ActionButton.js";
|
|
6
|
+
import { Popover, usePopover } from "./Popover.js";
|
|
7
|
+
import { RadioCards } from "./RadioCards.js";
|
|
8
|
+
import './Button.css';
|
|
9
|
+
import './RoomSettings.css';
|
|
10
|
+
/** The Room settings button and its popover, holding `children` as its rows. */
|
|
11
|
+
export function RoomSettingsPopover({ testId = 'room-settings', title = 'Room settings', triggerClassName = 'room-settings__trigger ct-action', children, }) {
|
|
12
|
+
const { trigger, toggle, close } = usePopover();
|
|
13
|
+
return (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", className: triggerClassName, "aria-expanded": trigger !== null, "data-testid": testId, onClick: (event) => toggle(event.currentTarget), children: [_jsx(Icon, { name: "gear", size: uiLength('0.9rem') }), title] }), trigger !== null && (_jsx(Popover, { trigger: trigger, onClose: close, title: title, testId: `${testId}-popover`, wide: true, children: _jsx("div", { className: "room-settings__list", children: children }) }))] }));
|
|
14
|
+
}
|
|
15
|
+
/** One row's two grid cells: the setting's name (with the lock while it holds), then its control. */
|
|
16
|
+
export function SettingRow({ label, locked = false, children }) {
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsxs("span", { className: "room-settings__label", "data-locked": locked ? 'true' : undefined, children: [label, locked && _jsx(Icon, { name: "lock", size: uiLength('0.75rem'), className: "room-settings__lock" })] }), children] }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* An on/off switch. Its press counts in the usage as `<testId>-on` or `<testId>-off`, or as
|
|
21
|
+
* `actions` names them (what turning it on, and off, is called). `className` adds to its own.
|
|
22
|
+
*/
|
|
23
|
+
export function SettingToggle({ on, onPress, disabled, testId, className, actions, }) {
|
|
24
|
+
return (_jsx(ActionButton, { action: on ? (actions?.off ?? `${testId}-off`) : (actions?.on ?? `${testId}-on`), className: ['room-settings__toggle room-settings__switch', className].filter(Boolean).join(' '), "aria-pressed": on, "data-testid": testId, disabled: disabled, onPress: onPress, children: on ? 'On' : 'Off' }));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A declared field's control: a toggle, a row of cards for a choice, a number input for a bounded
|
|
28
|
+
* number. Null for a `custom` field, which its game draws itself. `toggleClassName` adds to a
|
|
29
|
+
* toggle's classes.
|
|
30
|
+
*/
|
|
31
|
+
export function SettingControl({ field, name, value, disabled, onChange, testId, toggleClassName, }) {
|
|
32
|
+
if (field.kind === 'toggle') {
|
|
33
|
+
const on = value === true;
|
|
34
|
+
return _jsx(SettingToggle, { on: on, onPress: () => onChange(!on), disabled: disabled, testId: testId, ...(toggleClassName === undefined ? {} : { className: toggleClassName }) });
|
|
35
|
+
}
|
|
36
|
+
if (field.kind === 'choice') {
|
|
37
|
+
return (_jsx(RadioCards, { name: name, label: field.label, options: field.choices, value: typeof value === 'string' ? value : null, disabled: disabled, onChange: onChange, testId: testId, className: "room-settings__switch" }));
|
|
38
|
+
}
|
|
39
|
+
if (field.kind === 'number') {
|
|
40
|
+
return (_jsx("input", { type: "number", className: "room-settings__number room-settings__switch", "aria-label": field.label, "data-testid": testId, min: field.min, max: field.max, step: field.step, value: typeof value === 'number' ? value : field.default, disabled: disabled, onChange: (event) => {
|
|
41
|
+
const next = event.currentTarget.valueAsNumber;
|
|
42
|
+
if (Number.isFinite(next) && next >= field.min && next <= field.max)
|
|
43
|
+
onChange(next);
|
|
44
|
+
} }));
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** A key as a test id: `pickTimer` → `pick-timer`. */
|
|
49
|
+
export const settingTestId = (key) => key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
50
|
+
/**
|
|
51
|
+
* Every field the declaration can draw, in its order, behind the Room settings button. Null when it
|
|
52
|
+
* has none to draw.
|
|
53
|
+
*/
|
|
54
|
+
export function RoomSettingsPanel({ spec, value, leader, live = false, busy = false, locked, onChange, only, testId, }) {
|
|
55
|
+
const keys = (only ?? spec.keys).filter((key) => Object.hasOwn(spec.fields, key) && spec.fields[key].kind !== 'custom');
|
|
56
|
+
if (keys.length === 0)
|
|
57
|
+
return null;
|
|
58
|
+
const holds = (lock) => lock !== undefined && (lock === LIVE ? live : (locked?.(lock) ?? false));
|
|
59
|
+
return (_jsx(RoomSettingsPopover, { ...(testId === undefined ? {} : { testId }), children: keys.map((key) => {
|
|
60
|
+
const field = spec.fields[key];
|
|
61
|
+
const isLocked = holds(field.lock);
|
|
62
|
+
return (_jsx(SettingRow, { label: field.label, locked: isLocked, children: _jsx(SettingControl, { field: field, name: key, value: value[key], disabled: !leader || busy || isLocked, onChange: (next) => onChange({ [key]: next }), testId: settingTestId(key) }) }, key));
|
|
63
|
+
}) }));
|
|
64
|
+
}
|
|
@@ -55,6 +55,8 @@ export interface RoomCoreClient<R> {
|
|
|
55
55
|
makeLeader(roomId: string, memberId: string): Promise<RoomOutcome<R>>;
|
|
56
56
|
/** The room a host's room (watchparty's game slot) plays in, made on first use and joined after: the server derives it from `hostRoom`. */
|
|
57
57
|
bindWatchparty(hostRoom: string): Promise<RoomOutcome<R>>;
|
|
58
|
+
/** The leader changes some of the room's settings (`PATCH /:id { settings }`); a locked or bad one is refused in the server's words. */
|
|
59
|
+
setSettings(roomId: string, patch: Record<string, unknown>): Promise<RoomOutcome<R>>;
|
|
58
60
|
/** Any other write that answers with the room, under `/api/rooms`: `path` starts with `/` or is `''`. */
|
|
59
61
|
write(path: string, payload: unknown, whatFailed: string, method?: 'POST' | 'PATCH' | 'PUT'): Promise<RoomOutcome<R>>;
|
|
60
62
|
/** Any other read of one room under `/api/rooms`, as `get` reads one. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The browser's client for game-server's generic room routes (`@hadoku/game-server/http/room-core`):
|
|
3
3
|
* the room list, a room, create, join, leave, ready, close, reset, the seat ops (sit, stand, the
|
|
4
|
-
* leader's close/open, bot in and out, remove, fewer seats, a new leader) and an embed's binding to
|
|
4
|
+
* leader's close/open, bot in and out, remove, fewer seats, a new leader), the room's settings and an embed's binding to
|
|
5
5
|
* its host's room. One copy, so every game
|
|
6
6
|
* reads the same refusals the same way; a game supplies only how its room body parses
|
|
7
7
|
* (`parse`), and adds its own routes with `write`/`read`.
|
|
@@ -122,6 +122,7 @@ export function roomCoreClient({ parse, fetch: fetchImpl = pageFetch, base = api
|
|
|
122
122
|
lowerSeatCapacity: (roomId, count) => seat(roomId, 'seats/capacity', { count }),
|
|
123
123
|
makeLeader: (roomId, memberId) => seat(roomId, 'leader', { memberId }),
|
|
124
124
|
bindWatchparty: (hostRoom) => send('/watchparty', { room: hostRoom }, 'Could not open this room’s table'),
|
|
125
|
+
setSettings: (roomId, patch) => send(id(roomId), { settings: patch }, 'Could not change the settings', 'PATCH'),
|
|
125
126
|
write: (path, payload, whatFailed, method = 'POST') => send(path, payload, whatFailed, method),
|
|
126
127
|
read,
|
|
127
128
|
};
|
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.111",
|
|
4
|
+
"gitHead": "d9abd787456c0d6e2ca5a8fbd799bfa09948553c",
|
|
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,8 +54,8 @@
|
|
|
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.115",
|
|
58
|
+
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.115",
|
|
59
59
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.32",
|
|
60
60
|
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.131",
|
|
61
61
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.131",
|