@glimstone/react 4.5.4 → 4.5.5

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,26 @@
1
+ import { type ReactNode } from "react";
2
+ import { type PickGroup, type PickItem, type PickerText } from "@glimstone/core";
3
+ import { type WindowAction } from "./Window.tsx";
4
+ export type { PickGroup, PickerText, TileMark } from "@glimstone/core";
5
+ export type PickerItem = PickItem<ReactNode>;
6
+ export interface PickerWindowProps {
7
+ /** The notch's words, also the window's accessible name. */
8
+ title: string;
9
+ /** What the picker is for, as the (i) in its notch. */
10
+ hint?: string;
11
+ /** The choices, sorted by their names in the page's language. */
12
+ items: PickerItem[];
13
+ /** The groups the items name, in the order they stand. Without them the tiles stand in one. */
14
+ groups?: PickGroup[];
15
+ text: PickerText;
16
+ onPick: (id: string) => void;
17
+ /** The picked tile's form, which takes the tiles' place until it is gone again. */
18
+ children?: ReactNode;
19
+ /** The form's buttons, the forward one last. Cancel and Back stand before them. */
20
+ actions?: WindowAction[];
21
+ /** Back from the form to the tiles, with the search as it was. */
22
+ onBack?: () => void;
23
+ /** Called for every way out: the foot, Escape and a press beside the window. */
24
+ onClose: () => void;
25
+ }
26
+ export declare function PickerWindow({ title, hint, items, groups, text, onPick, children, actions, onBack, onClose }: PickerWindowProps): import("react").JSX.Element;
@@ -0,0 +1,38 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLayoutEffect, useRef, useState } from "react";
3
+ import { fill, holdPickHeight, isTileMark, pageLocale, windowFocusTarget, pickSearchKey, pickSections, pickTileKey, pickTileStyle, } from "@glimstone/core";
4
+ import { IconBack, IconClose } from "./glyphs.js";
5
+ import { InfoBubble } from "./InfoBubble.js";
6
+ import { BrandMark, ReadmeButton } from "./ReadmeButton.js";
7
+ import { Window } from "./Window.js";
8
+ export function PickerWindow({ title, hint, items, groups = [], text, onPick, children, actions = [], onBack, onClose }) {
9
+ const [query, setQuery] = useState("");
10
+ const card = useRef(null);
11
+ const search = useRef(null);
12
+ const scroll = useRef(null);
13
+ const form = children !== undefined && children !== null && children !== false;
14
+ useLayoutEffect(() => {
15
+ if (scroll.current)
16
+ holdPickHeight(scroll.current);
17
+ if (card.current)
18
+ windowFocusTarget(card.current)?.focus();
19
+ }, [form]);
20
+ // Back keeps the window open, so it returns false.
21
+ const back = {
22
+ label: text.back,
23
+ labelKey: "common.back",
24
+ glyph: _jsx(IconBack, {}),
25
+ onClick: () => {
26
+ onBack?.();
27
+ return false;
28
+ },
29
+ };
30
+ const sections = pickSections(items, groups, query, pageLocale());
31
+ const used = (e, handled) => {
32
+ if (!handled)
33
+ return;
34
+ e.preventDefault();
35
+ e.stopPropagation();
36
+ };
37
+ return (_jsx(Window, { "data-glim": "PickerWindow", title: title, drawn: hint ? (_jsxs(_Fragment, { children: [title, _jsx(InfoBubble, { tip: hint, onAccent: true })] })) : undefined, ref: card, className: "glim-pick-window", text: { cancel: text.cancel, close: text.close }, actions: form ? [back, ...actions] : [{ label: text.close, labelKey: "common.close", glyph: _jsx(IconClose, {}), wayOut: true }], onClose: onClose, children: form ? (children) : (_jsxs(_Fragment, { children: [_jsx("input", { ref: search, className: "glim-input glim-pick-search", type: "search", "aria-label": text.search, placeholder: text.search, spellCheck: false, autoComplete: "off", value: query, onChange: (e) => setQuery(e.target.value), onKeyDown: (e) => used(e, pickSearchKey(e.key, query, scroll.current, () => setQuery(""))) }), _jsx("div", { ref: scroll, className: "glim-pick-scroll", onKeyDown: (e) => e.target !== e.currentTarget && used(e, pickTileKey(e.key, e.target, e.currentTarget, search.current)), children: sections.length === 0 ? (_jsx("p", { className: "glim-pick-none", children: fill(text.none, { query: query.trim() }) })) : (sections.map((s) => (_jsxs("section", { className: "glim-pick-section", children: [s.title && _jsx("h3", { className: "glim-eyebrow", children: s.title }), _jsx("ul", { className: "glim-provider-pick", children: s.items.map((item) => (_jsx("li", { style: pickTileStyle(item.mark), children: _jsx(ReadmeButton, { brand: "house", parts: [{ name: item.label, onClick: () => onPick(item.id) }], mark: isTileMark(item.mark) ? _jsx(BrandMark, { svg: item.mark.svg }) : item.mark, markClass: isTileMark(item.mark) ? undefined : "glim-house-mark", hint: item.hint }) }, item.id))) })] }, s.id)))) })] })) }));
38
+ }
package/dist/index.d.ts CHANGED
@@ -36,6 +36,7 @@ export * from "./NumberField.tsx";
36
36
  export * from "./PasswordField.tsx";
37
37
  export * from "./PathField.tsx";
38
38
  export * from "./PaypalDialog.tsx";
39
+ export * from "./PickerWindow.tsx";
39
40
  export * from "./Pill.tsx";
40
41
  export * from "./Popover.tsx";
41
42
  export * from "./ProgressBar.tsx";
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ export * from "./NumberField.js";
36
36
  export * from "./PasswordField.js";
37
37
  export * from "./PathField.js";
38
38
  export * from "./PaypalDialog.js";
39
+ export * from "./PickerWindow.js";
39
40
  export * from "./Pill.js";
40
41
  export * from "./Popover.js";
41
42
  export * from "./ProgressBar.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/react",
3
- "version": "4.5.4",
3
+ "version": "4.5.5",
4
4
  "description": "GlimStone's components for React",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/junkerderprovinz/glimstone.git", "directory": "packages/react" },
@@ -16,7 +16,7 @@
16
16
  "build": "tsc -p tsconfig.build.json"
17
17
  },
18
18
  "dependencies": {
19
- "@glimstone/core": "4.5.4"
19
+ "@glimstone/core": "4.5.5"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@internationalized/date": "^3.12.4",