@hadoku/game-ui 0.0.0-stage → 0.1.6
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/LICENSE +21 -0
- package/dist/chrome/HeaderLinks.d.ts +16 -0
- package/dist/chrome/HeaderLinks.js +24 -0
- package/dist/components/ActionButton.d.ts +9 -0
- package/dist/components/ActionButton.js +49 -0
- package/dist/components/Avatar.d.ts +43 -0
- package/dist/components/Avatar.js +53 -0
- package/dist/components/ConnectionBanner.css +77 -0
- package/dist/components/ConnectionBanner.d.ts +33 -0
- package/dist/components/ConnectionBanner.js +33 -0
- package/dist/components/Modal.css +69 -0
- package/dist/components/Modal.d.ts +12 -0
- package/dist/components/Modal.js +31 -0
- package/dist/components/OverPage.d.ts +4 -0
- package/dist/components/OverPage.js +21 -0
- package/dist/components/Popover.css +58 -0
- package/dist/components/Popover.d.ts +20 -0
- package/dist/components/Popover.js +63 -0
- package/dist/components/RadioCards.css +178 -0
- package/dist/components/RadioCards.d.ts +33 -0
- package/dist/components/RadioCards.js +41 -0
- package/dist/components/StatusPill.d.ts +16 -0
- package/dist/components/StatusPill.js +17 -0
- package/dist/components/connection-state.d.ts +32 -0
- package/dist/components/connection-state.js +5 -0
- package/dist/dom.d.ts +17 -0
- package/dist/dom.js +57 -0
- package/dist/front/Gallery.d.ts +22 -0
- package/dist/front/Gallery.js +48 -0
- package/dist/front/PatchNotesCard.d.ts +1 -0
- package/dist/front/PatchNotesCard.js +59 -0
- package/dist/front/camera.d.ts +80 -0
- package/dist/front/camera.js +120 -0
- package/dist/front/countdown.d.ts +2 -0
- package/dist/front/countdown.js +16 -0
- package/dist/front/discordChat.d.ts +22 -0
- package/dist/front/discordChat.js +52 -0
- package/dist/front/gallery.d.ts +13 -0
- package/dist/front/gallery.js +32 -0
- package/dist/front/gate.d.ts +23 -0
- package/dist/front/gate.js +55 -0
- package/dist/front/icons.d.ts +43 -0
- package/dist/front/icons.js +99 -0
- package/dist/front/patchNotes.d.ts +37 -0
- package/dist/front/patchNotes.js +95 -0
- package/dist/front/polls.d.ts +24 -0
- package/dist/front/polls.js +95 -0
- package/dist/front/shape.d.ts +11 -0
- package/dist/front/shape.js +52 -0
- package/dist/http.d.ts +28 -0
- package/dist/http.js +83 -0
- package/dist/idle.d.ts +2 -0
- package/dist/idle.js +7 -0
- package/dist/lazy.d.ts +9 -0
- package/dist/lazy.js +63 -0
- package/dist/popover.d.ts +13 -0
- package/dist/popover.js +39 -0
- package/dist/registered.d.ts +5 -0
- package/dist/registered.js +6 -0
- package/dist/restart-notice.d.ts +20 -0
- package/dist/restart-notice.js +54 -0
- package/dist/room/RoomShell.d.ts +116 -0
- package/dist/room/RoomShell.js +222 -0
- package/dist/room/SessionPrompt.d.ts +12 -0
- package/dist/room/SessionPrompt.js +54 -0
- package/dist/room/avatar.d.ts +31 -0
- package/dist/room/avatar.js +60 -0
- package/dist/room/look.css +13 -0
- package/dist/room/look.d.ts +35 -0
- package/dist/room/look.js +189 -0
- package/dist/room/seatsOpen.d.ts +7 -0
- package/dist/room/seatsOpen.js +37 -0
- package/dist/room/session.d.ts +26 -0
- package/dist/room/session.js +108 -0
- package/dist/room/socket-options.d.ts +33 -0
- package/dist/room/socket-options.js +40 -0
- package/dist/room/tab-id.d.ts +6 -0
- package/dist/room/tab-id.js +90 -0
- package/dist/room/whoami.d.ts +15 -0
- package/dist/room/whoami.js +48 -0
- package/dist/rooms/bundle-slot.fixture.d.ts +11 -0
- package/dist/rooms/bundle-slot.fixture.js +21 -0
- package/dist/rooms/game-clients.d.ts +12 -0
- package/dist/rooms/game-clients.js +30 -0
- package/dist/rooms/game-setup.d.ts +63 -0
- package/dist/rooms/game-setup.js +33 -0
- package/dist/rooms/relay-channel.d.ts +29 -0
- package/dist/rooms/relay-channel.js +123 -0
- package/dist/rooms/screen/RoomShell.d.ts +33 -0
- package/dist/rooms/screen/RoomShell.js +7 -0
- package/dist/screens/route.d.ts +143 -0
- package/dist/screens/route.js +359 -0
- package/dist/settings/Settings.d.ts +39 -0
- package/dist/settings/Settings.js +131 -0
- package/dist/settings/TrimScreen.d.ts +2 -0
- package/dist/settings/TrimScreen.js +29 -0
- package/dist/settings/settings.css +116 -0
- package/dist/settings/siteTrim.d.ts +3 -0
- package/dist/settings/siteTrim.js +9 -0
- package/dist/settings/trim-screen.css +30 -0
- package/dist/sound/index.d.ts +12 -0
- package/dist/sound/index.js +34 -0
- package/dist/stale-build.d.ts +16 -0
- package/dist/stale-build.js +59 -0
- package/dist/top-layer.css +22 -0
- package/dist/topLayer.d.ts +19 -0
- package/dist/topLayer.js +44 -0
- package/dist/usage.d.ts +5 -0
- package/dist/usage.js +17 -0
- package/dist/visible.d.ts +14 -0
- package/dist/visible.js +35 -0
- package/package.json +41 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hadoku-cardtable contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The header's outbound links: the Discord server (patch notes, scheduled tournaments,
|
|
3
|
+
* looking-for-game), then the source on GitHub.
|
|
4
|
+
*
|
|
5
|
+
* Rides `AppHeader`'s `status` slot, which renders first in the actions row, so they sit just left of
|
|
6
|
+
* the theme picker. The operator asked for Discord between the theme and settings icons; that needs the
|
|
7
|
+
* header's `links` slot (docs/requests/HADOKU_SITE_HEADER_LINKS.md, with hadoku-task), and these move
|
|
8
|
+
* there when it ships. `.app-header__icon-btn` is the fleet's round button and is made for an <a>.
|
|
9
|
+
*
|
|
10
|
+
* The invite is permanent. ArchiveBot's original (`/setup cardtable`) stopped accepting joins once the
|
|
11
|
+
* server became a Community server (2026-11-05); this one is the operator's.
|
|
12
|
+
* Both glyphs are Simple Icons' marks (CC0-1.0).
|
|
13
|
+
*/
|
|
14
|
+
export declare const DISCORD_INVITE_URL = "https://discord.gg/tfRddmWkDv";
|
|
15
|
+
export declare const GITHUB_REPO_URL = "https://github.com/WolffM/hadoku-cardtable";
|
|
16
|
+
export declare function HeaderLinks(): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The header's outbound links: the Discord server (patch notes, scheduled tournaments,
|
|
4
|
+
* looking-for-game), then the source on GitHub.
|
|
5
|
+
*
|
|
6
|
+
* Rides `AppHeader`'s `status` slot, which renders first in the actions row, so they sit just left of
|
|
7
|
+
* the theme picker. The operator asked for Discord between the theme and settings icons; that needs the
|
|
8
|
+
* header's `links` slot (docs/requests/HADOKU_SITE_HEADER_LINKS.md, with hadoku-task), and these move
|
|
9
|
+
* there when it ships. `.app-header__icon-btn` is the fleet's round button and is made for an <a>.
|
|
10
|
+
*
|
|
11
|
+
* The invite is permanent. ArchiveBot's original (`/setup cardtable`) stopped accepting joins once the
|
|
12
|
+
* server became a Community server (2026-11-05); this one is the operator's.
|
|
13
|
+
* Both glyphs are Simple Icons' marks (CC0-1.0).
|
|
14
|
+
*/
|
|
15
|
+
export const DISCORD_INVITE_URL = 'https://discord.gg/tfRddmWkDv';
|
|
16
|
+
export const GITHUB_REPO_URL = 'https://github.com/WolffM/hadoku-cardtable';
|
|
17
|
+
const DISCORD_PATH = 'M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z';
|
|
18
|
+
const GITHUB_PATH = 'M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12';
|
|
19
|
+
function HeaderLink({ href, label, path }) {
|
|
20
|
+
return (_jsx("a", { className: "app-header__icon-btn", href: href, target: "_blank", rel: "noopener noreferrer", "aria-label": label, title: label, "data-testid": `header-${label.toLowerCase()}`, children: _jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "currentColor", "aria-hidden": "true", children: _jsx("path", { d: path }) }) }));
|
|
21
|
+
}
|
|
22
|
+
export function HeaderLinks() {
|
|
23
|
+
return (_jsxs(_Fragment, { children: [_jsx(HeaderLink, { href: DISCORD_INVITE_URL, label: "Discord", path: DISCORD_PATH }), _jsx(HeaderLink, { href: GITHUB_REPO_URL, label: "GitHub", path: GITHUB_PATH })] }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type MouseEvent } from 'react';
|
|
2
|
+
/** Whether this click is a press of the element it landed on (see the header). */
|
|
3
|
+
export declare function pressLandsOn(event: MouseEvent<Element>): boolean;
|
|
4
|
+
export type ActionButtonProps = Omit<ComponentPropsWithoutRef<'button'>, 'onClick' | 'type' | 'ref'> & {
|
|
5
|
+
/** What a press does; two actions are two elements, never one morphed into the other. */
|
|
6
|
+
action: string;
|
|
7
|
+
onPress: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function ActionButton({ action, onPress, ...button }: ActionButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* A button that does one thing, and stays the element of that one thing.
|
|
4
|
+
*
|
|
5
|
+
* The class this exists for: a control replaced in place by its inverse. A
|
|
6
|
+
* pod seat's "AI" and the "Remove" the room draws once the AI sits are the
|
|
7
|
+
* same position in the same row, so React reused the one `<button>` and only
|
|
8
|
+
* swapped its label and handler — a press aimed at "AI" that landed after the
|
|
9
|
+
* room's update removed the AI it had just seated (forge.yml 39844107553:
|
|
10
|
+
* AI seat 2, seat 2 given back, AI seat 3, from a driver that only ever
|
|
11
|
+
* pressed AI). A person's double click does the same thing by hand.
|
|
12
|
+
*
|
|
13
|
+
* Two rules, both here so no screen re-derives them:
|
|
14
|
+
*
|
|
15
|
+
* - `action` names what a press does, and is the button's key: a different
|
|
16
|
+
* action is a different element, so anything that resolved the old one (a
|
|
17
|
+
* test driver's handle, a press already on its way) finds it detached
|
|
18
|
+
* instead of firing the new one. Keyboard focus moves to the replacement.
|
|
19
|
+
* - The second click of a double click (`detail` ≥ 2) fires only on the
|
|
20
|
+
* element that took the first: a control drawn because of the first click
|
|
21
|
+
* never catches the second.
|
|
22
|
+
*/
|
|
23
|
+
import { useCallback, useRef } from 'react';
|
|
24
|
+
/** The element that took the first click of the current click sequence. */
|
|
25
|
+
let sequenceStart = null;
|
|
26
|
+
/** Whether this click is a press of the element it landed on (see the header). */
|
|
27
|
+
export function pressLandsOn(event) {
|
|
28
|
+
if (event.detail <= 1) {
|
|
29
|
+
sequenceStart = event.currentTarget;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return event.currentTarget === sequenceStart;
|
|
33
|
+
}
|
|
34
|
+
export function ActionButton({ action, onPress, ...button }) {
|
|
35
|
+
const carryFocus = useRef(false);
|
|
36
|
+
const ref = useCallback((node) => {
|
|
37
|
+
if (carryFocus.current) {
|
|
38
|
+
carryFocus.current = false;
|
|
39
|
+
node.focus();
|
|
40
|
+
}
|
|
41
|
+
return () => {
|
|
42
|
+
carryFocus.current = node.ownerDocument.activeElement === node;
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
return (_jsx("button", { ref: ref, type: "button", "data-action": action, ...button, onClick: (e) => {
|
|
46
|
+
if (pressLandsOn(e))
|
|
47
|
+
onPress();
|
|
48
|
+
} }, action));
|
|
49
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ComponentType, type ImgHTMLAttributes } from 'react';
|
|
2
|
+
import type { Look } from '@wolffm/platform-wire/look';
|
|
3
|
+
export declare const registerPlayerMark: (value: ComponentType<{
|
|
4
|
+
className?: string | undefined;
|
|
5
|
+
}>) => void;
|
|
6
|
+
/** Everything a face is drawn from: spread it into `<Avatar>` (`<Avatar {...face} … />`). */
|
|
7
|
+
export interface Face {
|
|
8
|
+
id: string | null | undefined;
|
|
9
|
+
look?: Look | undefined;
|
|
10
|
+
}
|
|
11
|
+
/** Nobody's face: the fallback. */
|
|
12
|
+
export declare const NO_FACE: Face;
|
|
13
|
+
/**
|
|
14
|
+
* Every room member's face, by member id, for a screen that names people by id
|
|
15
|
+
* and was not handed their faces: the draft's seat bar, under the pod screen.
|
|
16
|
+
*/
|
|
17
|
+
export declare const MemberFaces: import("react").Context<Readonly<Record<string, Face>>>;
|
|
18
|
+
/** A room member's face: their character and their look. */
|
|
19
|
+
export declare function faceOf(member: {
|
|
20
|
+
avatarId?: unknown;
|
|
21
|
+
look?: Look | undefined;
|
|
22
|
+
} | undefined): Face;
|
|
23
|
+
type AvatarProps = Omit<ImgHTMLAttributes<HTMLImageElement>, 'id' | 'src' | 'alt' | 'onError'> & {
|
|
24
|
+
/** The watchparty character id; absent, blank or unreadable draws the fallback. */
|
|
25
|
+
id: string | null | undefined;
|
|
26
|
+
/** Their picture and what they wear. A picture is drawn instead of the character. */
|
|
27
|
+
look?: Look | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Without an image: `mark` is our own silhouette (`PlayerMark`), `initial` the
|
|
30
|
+
* first letter of `name`, `none` nothing at all.
|
|
31
|
+
*/
|
|
32
|
+
fallback: 'mark' | 'initial' | 'none';
|
|
33
|
+
/** The fallback's own class: `PlayerMark`'s, or the initial's box. A mark with none stands in the image's place, with its class. */
|
|
34
|
+
fallbackClassName?: string;
|
|
35
|
+
/** Whose face: the initial's letter. */
|
|
36
|
+
name?: string;
|
|
37
|
+
'data-testid'?: string;
|
|
38
|
+
};
|
|
39
|
+
/** The images a face may draw, in the order it tries them: their picture first, then their character. */
|
|
40
|
+
export declare function facePictures({ id, look }: Face): string[];
|
|
41
|
+
/** `alt=""` always: every face sits beside the name that says who it is. */
|
|
42
|
+
export declare function Avatar({ id, look, fallback, fallbackClassName, name, ...img }: AvatarProps): import("react").JSX.Element | null;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* A player's avatar, or what stands in for it.
|
|
4
|
+
*
|
|
5
|
+
* One avatar per person, everywhere (the operator, 2026-11-05): the picture they
|
|
6
|
+
* chose (Discord, Steam or an upload) when they have one, else their watchparty
|
|
7
|
+
* character, with the overlay they wear on it (`room/look.tsx`). This is the one
|
|
8
|
+
* place a face is drawn, so every face falls back the same way: when there is
|
|
9
|
+
* nothing to draw, and when the image will not load.
|
|
10
|
+
*/
|
|
11
|
+
import { createContext, useState } from 'react';
|
|
12
|
+
import { avatarSquareUrl } from "../room/avatar.js";
|
|
13
|
+
import { FaceDecor } from "../room/look.js";
|
|
14
|
+
import { registered } from "../registered.js";
|
|
15
|
+
/** The game's own silhouette for a face with no image (`fallback="mark"`). */
|
|
16
|
+
const playerMark = registered('player mark');
|
|
17
|
+
export const registerPlayerMark = playerMark.set;
|
|
18
|
+
/** Nobody's face: the fallback. */
|
|
19
|
+
export const NO_FACE = { id: null };
|
|
20
|
+
/**
|
|
21
|
+
* Every room member's face, by member id, for a screen that names people by id
|
|
22
|
+
* and was not handed their faces: the draft's seat bar, under the pod screen.
|
|
23
|
+
*/
|
|
24
|
+
export const MemberFaces = createContext({});
|
|
25
|
+
/** A room member's face: their character and their look. */
|
|
26
|
+
export function faceOf(member) {
|
|
27
|
+
if (member === undefined)
|
|
28
|
+
return NO_FACE;
|
|
29
|
+
return { id: typeof member.avatarId === 'string' ? member.avatarId : null, ...(member.look === undefined ? {} : { look: member.look }) };
|
|
30
|
+
}
|
|
31
|
+
/** The images a face may draw, in the order it tries them: their picture first, then their character. */
|
|
32
|
+
export function facePictures({ id, look }) {
|
|
33
|
+
return [look?.picture ?? null, avatarSquareUrl(id)].filter((u) => u !== null);
|
|
34
|
+
}
|
|
35
|
+
/** `alt=""` always: every face sits beside the name that says who it is. */
|
|
36
|
+
export function Avatar({ id, look, fallback, fallbackClassName, name = '', ...img }) {
|
|
37
|
+
const avatarId = id ?? undefined;
|
|
38
|
+
const [failed, setFailed] = useState([]);
|
|
39
|
+
// The picture first; a picture that will not load falls back to the character.
|
|
40
|
+
const url = facePictures({ id, look }).find((u) => !failed.includes(u)) ?? null;
|
|
41
|
+
const decor = _jsx(FaceDecor, { avatarId: avatarId, look: look });
|
|
42
|
+
if (url !== null) {
|
|
43
|
+
return (_jsxs(_Fragment, { children: [_jsx("img", { ...img, src: url, alt: "", "data-picture": url === look?.picture || undefined, onError: () => setFailed((f) => [...f, url]) }), decor] }));
|
|
44
|
+
}
|
|
45
|
+
if (fallback === 'mark') {
|
|
46
|
+
const PlayerMark = playerMark.get();
|
|
47
|
+
return (_jsxs(_Fragment, { children: [_jsx(PlayerMark, { className: fallbackClassName ?? img.className }), decor] }));
|
|
48
|
+
}
|
|
49
|
+
if (fallback === 'initial') {
|
|
50
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { className: fallbackClassName, "aria-hidden": "true", children: name.charAt(0).toUpperCase() }), decor] }));
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The connection banner (`ConnectionBanner.tsx`). It CONSUMES the palette on
|
|
3
|
+
* `:root` and redefines none of it; a fallback is given on each `var()` that
|
|
4
|
+
* needs one so a banner rendered outside the app is still legible.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
.conn {
|
|
8
|
+
display: flex;
|
|
9
|
+
gap: 10px;
|
|
10
|
+
align-items: flex-start;
|
|
11
|
+
padding: 10px 14px;
|
|
12
|
+
border: 1px solid var(--line);
|
|
13
|
+
border-left-width: 3px;
|
|
14
|
+
border-radius: var(--radius, 8px);
|
|
15
|
+
background: var(--bg-raised);
|
|
16
|
+
color: var(--ink);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* The phase, as a colour. Never the only signal — the label says it in words. */
|
|
20
|
+
.conn--connecting,
|
|
21
|
+
.conn--reconnecting,
|
|
22
|
+
.conn--resyncing {
|
|
23
|
+
border-left-color: var(--accent);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.conn--offline {
|
|
27
|
+
border-left-color: var(--warn);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.conn--recovered {
|
|
31
|
+
border-left-color: var(--c-green);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.conn__dot {
|
|
35
|
+
width: 9px;
|
|
36
|
+
height: 9px;
|
|
37
|
+
margin-top: 5px;
|
|
38
|
+
border-radius: 50%;
|
|
39
|
+
background: currentColor;
|
|
40
|
+
opacity: 0.55;
|
|
41
|
+
flex: none;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* A pulse only while something is genuinely in flight, and never for a person
|
|
45
|
+
who asked the browser not to animate. */
|
|
46
|
+
.conn--connecting .conn__dot,
|
|
47
|
+
.conn--reconnecting .conn__dot,
|
|
48
|
+
.conn--resyncing .conn__dot {
|
|
49
|
+
animation: conn-pulse 1.4s ease-in-out infinite;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@media (prefers-reduced-motion: reduce) {
|
|
53
|
+
.conn__dot {
|
|
54
|
+
animation: none !important;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@keyframes conn-pulse {
|
|
59
|
+
50% {
|
|
60
|
+
opacity: 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.conn__text {
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: column;
|
|
67
|
+
gap: 2px;
|
|
68
|
+
min-width: 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.conn__label {
|
|
72
|
+
font-weight: 600;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.conn__detail {
|
|
76
|
+
color: var(--ink-dim);
|
|
77
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the connection is doing, said out loud.
|
|
3
|
+
*
|
|
4
|
+
* ## The bug this is, which is not a bug in the code
|
|
5
|
+
*
|
|
6
|
+
* A drafter's socket drops. The server holds their seat for the reservation
|
|
7
|
+
* TTL, the client re-joins on reconnect, the server answers with a full
|
|
8
|
+
* snapshot and the draft carries on — every part of that works and is tested
|
|
9
|
+
* (`draft/socket.test.ts`, `games/magic/server/src/room/draftRooms.ts`). What the
|
|
10
|
+
* player sees is a table that stops moving for thirty seconds and then jumps.
|
|
11
|
+
* They refresh, or they say it is broken, and both are reasonable responses to
|
|
12
|
+
* a screen that said nothing.
|
|
13
|
+
*
|
|
14
|
+
* So this component renders the one thing the app was not saying. It holds no
|
|
15
|
+
* state and starts no timers: it takes a `ConnectionState` computed by
|
|
16
|
+
* `draft/connection.ts` from facts the driver already tracks, which is why the
|
|
17
|
+
* banner can be tested without a socket and cannot drift from what the socket
|
|
18
|
+
* is actually doing.
|
|
19
|
+
*
|
|
20
|
+
* ## `role="status"`, not `alert`
|
|
21
|
+
*
|
|
22
|
+
* None of these are errors. `alert` interrupts a screen reader mid-sentence and
|
|
23
|
+
* is for something that has gone wrong; a reconnect is the system working. The
|
|
24
|
+
* live region still announces it, politely, when the player reaches a pause.
|
|
25
|
+
*/
|
|
26
|
+
import { type ConnectionState } from './connection-state.js';
|
|
27
|
+
import './ConnectionBanner.css';
|
|
28
|
+
export interface ConnectionBannerProps {
|
|
29
|
+
state: ConnectionState;
|
|
30
|
+
/** Render even when there is nothing to report. Off by default. */
|
|
31
|
+
always?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare function ConnectionBanner({ state, always }: ConnectionBannerProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* What the connection is doing, said out loud.
|
|
4
|
+
*
|
|
5
|
+
* ## The bug this is, which is not a bug in the code
|
|
6
|
+
*
|
|
7
|
+
* A drafter's socket drops. The server holds their seat for the reservation
|
|
8
|
+
* TTL, the client re-joins on reconnect, the server answers with a full
|
|
9
|
+
* snapshot and the draft carries on — every part of that works and is tested
|
|
10
|
+
* (`draft/socket.test.ts`, `games/magic/server/src/room/draftRooms.ts`). What the
|
|
11
|
+
* player sees is a table that stops moving for thirty seconds and then jumps.
|
|
12
|
+
* They refresh, or they say it is broken, and both are reasonable responses to
|
|
13
|
+
* a screen that said nothing.
|
|
14
|
+
*
|
|
15
|
+
* So this component renders the one thing the app was not saying. It holds no
|
|
16
|
+
* state and starts no timers: it takes a `ConnectionState` computed by
|
|
17
|
+
* `draft/connection.ts` from facts the driver already tracks, which is why the
|
|
18
|
+
* banner can be tested without a socket and cannot drift from what the socket
|
|
19
|
+
* is actually doing.
|
|
20
|
+
*
|
|
21
|
+
* ## `role="status"`, not `alert`
|
|
22
|
+
*
|
|
23
|
+
* None of these are errors. `alert` interrupts a screen reader mid-sentence and
|
|
24
|
+
* is for something that has gone wrong; a reconnect is the system working. The
|
|
25
|
+
* live region still announces it, politely, when the player reaches a pause.
|
|
26
|
+
*/
|
|
27
|
+
import { isWorthShowing } from "./connection-state.js";
|
|
28
|
+
import './ConnectionBanner.css';
|
|
29
|
+
export function ConnectionBanner({ state, always = false }) {
|
|
30
|
+
if (!always && !isWorthShowing(state))
|
|
31
|
+
return null;
|
|
32
|
+
return (_jsxs("aside", { className: `conn conn--${state.phase}`, "data-testid": "connection", "data-phase": state.phase, "data-seat-held": state.seatHeld ? 'true' : 'false', "data-stalled": state.stalled ? 'true' : 'false', role: "status", "aria-live": "polite", children: [_jsx("span", { className: "conn__dot", "aria-hidden": "true" }), _jsxs("div", { className: "conn__text", children: [_jsx("strong", { className: "conn__label", "data-testid": "connection-label", children: state.label }), _jsx("span", { className: "conn__detail", "data-testid": "connection-detail", children: state.detail })] })] }));
|
|
33
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* `Modal.tsx`: the room list's create form's look (`../rooms/rooms.css`), for any modal. */
|
|
2
|
+
|
|
3
|
+
.ct-modal {
|
|
4
|
+
position: fixed;
|
|
5
|
+
inset: 0;
|
|
6
|
+
z-index: var(--z-modal, 50);
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
padding: 16px;
|
|
11
|
+
background: var(--color-bg-overlay);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.ct-modal__panel {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 10px;
|
|
18
|
+
width: min(460px, 100%);
|
|
19
|
+
max-height: calc(100dvh - 32px);
|
|
20
|
+
overflow-y: auto;
|
|
21
|
+
padding: 16px 20px 20px;
|
|
22
|
+
border-radius: var(--hdk-radius-lg);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.ct-modal__panel[data-wide] {
|
|
26
|
+
width: min(680px, 100%);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.ct-modal__head {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: space-between;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ct-modal__head h3 {
|
|
36
|
+
margin: 0;
|
|
37
|
+
font-size: 16px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.ct-modal__close {
|
|
41
|
+
display: inline-flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
padding: 4px;
|
|
45
|
+
border: 1px solid transparent;
|
|
46
|
+
border-radius: var(--hdk-radius-sm);
|
|
47
|
+
background: transparent;
|
|
48
|
+
color: inherit;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.ct-modal__close:hover,
|
|
53
|
+
.ct-modal__close:focus-visible {
|
|
54
|
+
border-color: var(--color-border);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Its answers, along the foot: the affirmative last, in the primary fill. */
|
|
58
|
+
.ct-modal__actions {
|
|
59
|
+
display: flex;
|
|
60
|
+
flex-wrap: wrap;
|
|
61
|
+
justify-content: flex-end;
|
|
62
|
+
gap: 8px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.ct-modal__primary {
|
|
66
|
+
background: var(--color-primary);
|
|
67
|
+
color: var(--color-on-primary);
|
|
68
|
+
border-color: var(--color-primary);
|
|
69
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import './Modal.css';
|
|
3
|
+
export declare function Modal({ title, testId, onClose, children, actions, wide, }: {
|
|
4
|
+
title: string;
|
|
5
|
+
testId: string;
|
|
6
|
+
/** Absent: a question that must be answered through its `actions`. */
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
actions?: ReactNode;
|
|
10
|
+
/** A reading panel (long text) rather than a short question: wider than the default. */
|
|
11
|
+
wide?: boolean;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* A titled panel over a dimmed page, drawn the way the room list's create form is (`../rooms/RoomList.tsx`):
|
|
4
|
+
* Escape, its close button and a press on the backdrop close it. With no `onClose` it cannot be put
|
|
5
|
+
* away, only answered: no close button, and Escape and the backdrop do nothing. Its `actions`, when it
|
|
6
|
+
* has any, sit along its foot, the affirmative last (bottom right).
|
|
7
|
+
*
|
|
8
|
+
* It is drawn over the page (`./OverPage.tsx`), never inside the screen that opened it.
|
|
9
|
+
*/
|
|
10
|
+
import { useEffect, useId } from 'react';
|
|
11
|
+
import { Icon } from '@wolffm/themes';
|
|
12
|
+
import { uiLength } from '@wolffm/ui-shell/settings';
|
|
13
|
+
import { OverPage } from "./OverPage.js";
|
|
14
|
+
import './Modal.css';
|
|
15
|
+
export function Modal({ title, testId, onClose, children, actions, wide = false, }) {
|
|
16
|
+
const titleId = useId();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (onClose === undefined)
|
|
19
|
+
return;
|
|
20
|
+
const onKey = (event) => {
|
|
21
|
+
if (event.key === 'Escape')
|
|
22
|
+
onClose();
|
|
23
|
+
};
|
|
24
|
+
globalThis.document?.addEventListener('keydown', onKey);
|
|
25
|
+
return () => globalThis.document?.removeEventListener('keydown', onKey);
|
|
26
|
+
}, [onClose]);
|
|
27
|
+
return (_jsx(OverPage, { children: _jsx("div", { className: "ct-modal", "data-testid": `${testId}-backdrop`, onPointerDown: (e) => {
|
|
28
|
+
if (e.target === e.currentTarget)
|
|
29
|
+
onClose?.();
|
|
30
|
+
}, children: _jsxs("div", { className: "ct-modal__panel ct-surface ct-panel", "data-wide": wide || undefined, "data-testid": testId, role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, children: [_jsxs("div", { className: "ct-modal__head", children: [_jsx("h3", { id: titleId, children: title }), onClose !== undefined && (_jsx("button", { type: "button", className: "ct-modal__close", "aria-label": "Close", "data-testid": `${testId}-close`, onClick: onClose, children: _jsx(Icon, { name: "close", size: uiLength('1rem') }) }))] }), children, actions !== undefined && _jsx("div", { className: "ct-modal__actions", children: actions })] }) }) }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Where a layer placed in the window's own coordinates is drawn: the app's chrome root, outside every
|
|
3
|
+
* screen's box.
|
|
4
|
+
*
|
|
5
|
+
* A fit screen (`.shell--fit`, `../screens/screens.css`) carries `contain: layout`, which makes it the
|
|
6
|
+
* containing block of every `position: fixed` box inside it. Drawn there, a layer placed from
|
|
7
|
+
* `getBoundingClientRect()` is offset by the screen's own corner, scrolls with its content, and counts
|
|
8
|
+
* toward its scroll extent: a deck peek open beside the room's grid made the room scroll sideways
|
|
9
|
+
* (`e2e/lobby-fit.spec.ts`), and a modal covered only the screen. Every such layer (a modal, a
|
|
10
|
+
* popover, a peek, a backdrop) is drawn through this instead, where `fixed` means the window. The
|
|
11
|
+
* chrome root carries the theme; inside the embed's shadow root it is looked up there.
|
|
12
|
+
*/
|
|
13
|
+
import { createPortal } from 'react-dom';
|
|
14
|
+
import { documentScope } from "../dom.js";
|
|
15
|
+
export function OverPage({ children }) {
|
|
16
|
+
if (globalThis.document === undefined)
|
|
17
|
+
return children;
|
|
18
|
+
const scope = documentScope();
|
|
19
|
+
const host = scope.querySelector('.cardtable-chrome') ?? scope.querySelector('body') ?? document.body;
|
|
20
|
+
return createPortal(children, host);
|
|
21
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A popover (`Popover.tsx`): the settings gear's and a room's Match rules.
|
|
3
|
+
*
|
|
4
|
+
* Painted only from `@wolffm/themes` tokens — no literal colour anywhere; its
|
|
5
|
+
* native controls take the theme's accent from the fleet's `controls.css`
|
|
6
|
+
* (`main.tsx`): inside a match it sits in the
|
|
7
|
+
* `.live` island, outside it on the themed screens, and either way it reads as
|
|
8
|
+
* a card over the page.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
.ct-popover {
|
|
12
|
+
position: fixed;
|
|
13
|
+
z-index: var(--z-modal, 50);
|
|
14
|
+
width: min(18rem, calc(100vw - 16px));
|
|
15
|
+
max-height: calc(100dvh - 16px);
|
|
16
|
+
overflow-y: auto;
|
|
17
|
+
padding: 10px 14px 14px;
|
|
18
|
+
font-size: 13px;
|
|
19
|
+
text-align: left;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.ct-popover--wide {
|
|
23
|
+
width: min(24rem, calc(100vw - 16px));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.ct-popover:focus {
|
|
27
|
+
outline: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ct-popover__head {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
margin-bottom: 6px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.ct-popover__title {
|
|
38
|
+
margin: 0;
|
|
39
|
+
font-size: 15px;
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.ct-popover__close {
|
|
44
|
+
display: inline-flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
padding: 4px;
|
|
48
|
+
border: 1px solid transparent;
|
|
49
|
+
border-radius: var(--hdk-radius-sm);
|
|
50
|
+
background: transparent;
|
|
51
|
+
color: inherit;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.ct-popover__close:hover,
|
|
56
|
+
.ct-popover__close:focus-visible {
|
|
57
|
+
border-color: var(--color-border);
|
|
58
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import './Popover.css';
|
|
3
|
+
export interface PopoverProps {
|
|
4
|
+
/** What opened it: the popover is placed beside it, and a press on it is the trigger's to handle. */
|
|
5
|
+
trigger: Element;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
title: string;
|
|
8
|
+
/** The panel's test id; its close button's is `<testId>-close`. */
|
|
9
|
+
testId: string;
|
|
10
|
+
/** Room for a row of choices beside each label (a room's settings); the settings gear's switches need none. */
|
|
11
|
+
wide?: boolean;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export declare function Popover({ trigger, onClose, title, testId, wide, children }: PopoverProps): import("react").JSX.Element;
|
|
15
|
+
/** Which trigger has the popover open, if any. Pressing that trigger again closes it. */
|
|
16
|
+
export declare function usePopover(): {
|
|
17
|
+
trigger: Element | null;
|
|
18
|
+
toggle: (el: Element) => void;
|
|
19
|
+
close: () => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* A small titled panel opened from a button and placed beside it: the settings gear's
|
|
4
|
+
* (`../settings/Settings.tsx`) and a room's settings (`../rooms/MatchRules.tsx`).
|
|
5
|
+
* Escape, its close button and a press anywhere outside it close it; a press on the button that
|
|
6
|
+
* opened it is that button's to handle (`usePopover`'s toggle).
|
|
7
|
+
*/
|
|
8
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
9
|
+
import { Icon } from '@wolffm/themes';
|
|
10
|
+
import { useDismiss } from "../popover.js";
|
|
11
|
+
import { uiLength } from '@wolffm/ui-shell/settings';
|
|
12
|
+
import { OverPage } from "./OverPage.js";
|
|
13
|
+
import './Popover.css';
|
|
14
|
+
/** The gap between the popover and what opened it, and its distance from the viewport's edges. */
|
|
15
|
+
const GAP = 8;
|
|
16
|
+
/**
|
|
17
|
+
* Above an anchor in the lower half, below one in the upper; aligned to the anchor's nearer side, and
|
|
18
|
+
* no taller than the room between the anchor and that edge of the viewport. Capped at the viewport's
|
|
19
|
+
* height alone, a panel above an anchor low on the screen ran off its top: the match settings at
|
|
20
|
+
* 125% UI scale in a 720px window, whose scale slider was then out of reach.
|
|
21
|
+
*/
|
|
22
|
+
function place(anchor) {
|
|
23
|
+
const vw = globalThis.innerWidth;
|
|
24
|
+
const vh = globalThis.innerHeight;
|
|
25
|
+
const horizontal = anchor.left + anchor.width / 2 > vw / 2 ? { right: Math.max(GAP, vw - anchor.right) } : { left: Math.max(GAP, anchor.left) };
|
|
26
|
+
if (anchor.top + anchor.height / 2 > vh / 2) {
|
|
27
|
+
const bottom = Math.max(GAP, vh - anchor.top + GAP);
|
|
28
|
+
return { bottom, ...horizontal, maxHeight: Math.max(0, vh - bottom - GAP) };
|
|
29
|
+
}
|
|
30
|
+
const top = anchor.bottom + GAP;
|
|
31
|
+
return { top, ...horizontal, maxHeight: Math.max(0, vh - top - GAP) };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The placement moved sideways, once the panel's own width is known, so the whole panel is on screen:
|
|
35
|
+
* aligned to an anchor that sits in from the viewport's edge, a panel wider than the room on that
|
|
36
|
+
* side ran off the other edge (Room settings' wide panel at 390px, its left 39px off screen).
|
|
37
|
+
*/
|
|
38
|
+
function onScreen(at, width) {
|
|
39
|
+
const vw = globalThis.innerWidth;
|
|
40
|
+
const room = vw - GAP - width;
|
|
41
|
+
if (at.right !== undefined && at.right > room)
|
|
42
|
+
return { ...at, right: Math.max(GAP, room) };
|
|
43
|
+
if (at.left !== undefined && at.left > room)
|
|
44
|
+
return { ...at, left: Math.max(GAP, room) };
|
|
45
|
+
return at;
|
|
46
|
+
}
|
|
47
|
+
export function Popover({ trigger, onClose, title, testId, wide = false, children }) {
|
|
48
|
+
const titleId = useId();
|
|
49
|
+
const ref = useRef(null);
|
|
50
|
+
const [placement, setPlacement] = useState(() => place(trigger.getBoundingClientRect()));
|
|
51
|
+
useLayoutEffect(() => setPlacement(onScreen(place(trigger.getBoundingClientRect()), ref.current?.offsetWidth ?? 0)), [trigger]);
|
|
52
|
+
useDismiss(onClose, useCallback((target) => ref.current?.contains(target) !== false || trigger.contains(target), [trigger]));
|
|
53
|
+
useEffect(() => ref.current?.focus(), []);
|
|
54
|
+
// Placed in the window's coordinates, so drawn over the page, not inside the screen with its trigger.
|
|
55
|
+
return (_jsx(OverPage, { children: _jsxs("div", { ref: ref, className: `ct-popover ct-surface ct-panel${wide ? ' ct-popover--wide' : ''}`, role: "dialog", "aria-labelledby": titleId, "data-testid": testId, tabIndex: -1, style: placement, children: [_jsxs("div", { className: "ct-popover__head", children: [_jsx("h2", { id: titleId, className: "ct-popover__title ct-panel__title", children: title }), _jsx("button", { type: "button", className: "ct-popover__close", "aria-label": `Close ${title.toLowerCase()}`, "data-testid": `${testId}-close`, onClick: onClose, children: _jsx(Icon, { name: "close", size: uiLength('1rem') }) })] }), children] }) }));
|
|
56
|
+
}
|
|
57
|
+
/** Which trigger has the popover open, if any. Pressing that trigger again closes it. */
|
|
58
|
+
export function usePopover() {
|
|
59
|
+
const [trigger, setTrigger] = useState(null);
|
|
60
|
+
const close = useCallback(() => setTrigger(null), []);
|
|
61
|
+
const toggle = useCallback((el) => setTrigger((open) => (open === null ? el : null)), []);
|
|
62
|
+
return { trigger, toggle, close };
|
|
63
|
+
}
|