@glimstone/react 0.0.0-stage → 4.1.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/README.md +125 -2
- package/dist/AboutCard.d.ts +152 -0
- package/dist/AboutCard.js +82 -0
- package/dist/Badge.d.ts +47 -0
- package/dist/Badge.js +35 -0
- package/dist/Button.d.ts +54 -0
- package/dist/Button.js +52 -0
- package/dist/Card.d.ts +29 -0
- package/dist/Card.js +20 -0
- package/dist/Checkbox.d.ts +14 -0
- package/dist/Checkbox.js +7 -0
- package/dist/CoffeeDialog.d.ts +17 -0
- package/dist/CoffeeDialog.js +9 -0
- package/dist/ColorPicker.d.ts +21 -0
- package/dist/ColorPicker.js +68 -0
- package/dist/Combobox.d.ts +16 -0
- package/dist/Combobox.js +32 -0
- package/dist/ConfirmDialog.d.ts +29 -0
- package/dist/ConfirmDialog.js +15 -0
- package/dist/ContextMenu.d.ts +23 -0
- package/dist/ContextMenu.js +137 -0
- package/dist/CopyField.d.ts +15 -0
- package/dist/CopyField.js +24 -0
- package/dist/CryptoDonateDialog.d.ts +61 -0
- package/dist/CryptoDonateDialog.js +23 -0
- package/dist/DropdownListbox.d.ts +22 -0
- package/dist/DropdownListbox.js +182 -0
- package/dist/EmptyState.d.ts +19 -0
- package/dist/EmptyState.js +10 -0
- package/dist/IconTipButton.d.ts +18 -0
- package/dist/IconTipButton.js +13 -0
- package/dist/InfoBubble.d.ts +4 -0
- package/dist/InfoBubble.js +19 -0
- package/dist/Kbd.d.ts +5 -0
- package/dist/Kbd.js +6 -0
- package/dist/MenuBar.d.ts +18 -0
- package/dist/MenuBar.js +40 -0
- package/dist/Meter.d.ts +18 -0
- package/dist/Meter.js +9 -0
- package/dist/NumberField.d.ts +16 -0
- package/dist/NumberField.js +18 -0
- package/dist/PasswordField.d.ts +12 -0
- package/dist/PasswordField.js +8 -0
- package/dist/PaypalDialog.d.ts +51 -0
- package/dist/PaypalDialog.js +20 -0
- package/dist/Pill.d.ts +12 -0
- package/dist/Pill.js +5 -0
- package/dist/ProgressBar.d.ts +14 -0
- package/dist/ProgressBar.js +6 -0
- package/dist/ReadmeButton.d.ts +29 -0
- package/dist/ReadmeButton.js +27 -0
- package/dist/Select.d.ts +41 -0
- package/dist/Select.js +192 -0
- package/dist/Selector.d.ts +67 -0
- package/dist/Selector.js +128 -0
- package/dist/SidebarRow.d.ts +22 -0
- package/dist/SidebarRow.js +10 -0
- package/dist/Slider.d.ts +12 -0
- package/dist/Slider.js +18 -0
- package/dist/SubCard.d.ts +15 -0
- package/dist/SubCard.js +14 -0
- package/dist/Toast.d.ts +29 -0
- package/dist/Toast.js +24 -0
- package/dist/Toggle.d.ts +16 -0
- package/dist/Toggle.js +4 -0
- package/dist/UnavailableNotice.d.ts +15 -0
- package/dist/UnavailableNotice.js +12 -0
- package/dist/Window.d.ts +37 -0
- package/dist/Window.js +43 -0
- package/dist/WindowBar.d.ts +24 -0
- package/dist/WindowBar.js +31 -0
- package/dist/glyphs.d.ts +26 -0
- package/dist/glyphs.js +34 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +39 -0
- package/dist/portalHue.d.ts +10 -0
- package/dist/portalHue.js +15 -0
- package/dist/useConfirm.d.ts +26 -0
- package/dist/useConfirm.js +39 -0
- package/dist/useLabelMode.d.ts +6 -0
- package/dist/useLabelMode.js +11 -0
- package/dist/usePaypalButtons.d.ts +15 -0
- package/dist/usePaypalButtons.js +42 -0
- package/dist/useTipBubble.d.ts +34 -0
- package/dist/useTipBubble.js +63 -0
- package/package.json +28 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// What a card shows in place of a control when the environment forbids what the
|
|
3
|
+
// control would do, such as a passkey on a bare IP address or an untrusted
|
|
4
|
+
// certificate, where WebAuthn refuses the exchange. See "The second way in
|
|
5
|
+
// (second factor and passkey)" in the design language.
|
|
6
|
+
//
|
|
7
|
+
// Every string is a prop and arrives translated; a server's verdict travels as a
|
|
8
|
+
// boolean, never as the sentence shown here. It is a paragraph rather than an
|
|
9
|
+
// info bubble because there is no control to hang a bubble off.
|
|
10
|
+
export function UnavailableNotice({ title, reason, action, }) {
|
|
11
|
+
return (_jsxs("div", { className: "glim-notice", children: [_jsx("p", { className: "glim-notice-title", children: title }), _jsx("p", { className: "glim-notice-reason", children: reason }), action ? _jsx("div", { className: "glim-notice-action", children: action }) : null] }));
|
|
12
|
+
}
|
package/dist/Window.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type WindowSize } from "@glimstone/core";
|
|
3
|
+
export type { WindowSize } from "@glimstone/core";
|
|
4
|
+
export interface WindowAction {
|
|
5
|
+
label: string;
|
|
6
|
+
/** The translation key behind `label`, which picks the glyph, or `null`. */
|
|
7
|
+
labelKey: string | null;
|
|
8
|
+
glyph?: ReactNode;
|
|
9
|
+
/** The forward action, filled with the accent and placed last. */
|
|
10
|
+
primary?: boolean;
|
|
11
|
+
/** This action already leaves the window, such as Done, so no Cancel or Close is added. */
|
|
12
|
+
wayOut?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/** Runs on press. The window closes afterwards unless it returns false. */
|
|
15
|
+
onClick?: () => void | false;
|
|
16
|
+
}
|
|
17
|
+
export interface WindowProps {
|
|
18
|
+
/** The notch's words, also the window's accessible name. */
|
|
19
|
+
title: string;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
/** The foot's buttons, in reading order. Cancel or Close is added before
|
|
22
|
+
* them unless one of them is a way out itself. */
|
|
23
|
+
actions?: WindowAction[];
|
|
24
|
+
/** A quiet line at the start of the foot, such as where the work carries on. */
|
|
25
|
+
start?: ReactNode;
|
|
26
|
+
/** `normal` for a question or a form, `wide` for a list, `full` for a tool. */
|
|
27
|
+
size?: WindowSize;
|
|
28
|
+
/** The words of the way out the window adds. */
|
|
29
|
+
text: {
|
|
30
|
+
cancel: string;
|
|
31
|
+
close: string;
|
|
32
|
+
};
|
|
33
|
+
/** Called for every way out: the foot, Escape and a press beside the window. */
|
|
34
|
+
onClose: () => void;
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function Window({ title, children, actions, start, size, text, onClose, className }: WindowProps): import("react").ReactPortal;
|
package/dist/Window.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The general window: a notch with the title, a body for anything and a foot
|
|
3
|
+
// whose actions stand at the end. It owns the portal, its place on the stack,
|
|
4
|
+
// Escape, the Tab trap and the focus, so a caller only mounts it and unmounts
|
|
5
|
+
// it on onClose.
|
|
6
|
+
import { useId, useLayoutEffect, useRef, useState } from "react";
|
|
7
|
+
import { createPortal } from "react-dom";
|
|
8
|
+
import { focusedAsker, menuIsOpen, returnFocus, stackWindow, windowFocusTarget, windowFoot, } from "@glimstone/core";
|
|
9
|
+
import { Badge } from "./Badge.js";
|
|
10
|
+
import { Button } from "./Button.js";
|
|
11
|
+
import { IconCancel, IconClose } from "./glyphs.js";
|
|
12
|
+
export function Window({ title, children, actions = [], start, size = "normal", text, onClose, className }) {
|
|
13
|
+
const card = useRef(null);
|
|
14
|
+
const titleId = useId();
|
|
15
|
+
// Read before the window takes the focus.
|
|
16
|
+
const [asker] = useState(focusedAsker);
|
|
17
|
+
const close = useRef(onClose);
|
|
18
|
+
useLayoutEffect(() => {
|
|
19
|
+
close.current = onClose;
|
|
20
|
+
});
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
const unstack = stackWindow(() => card.current, () => close.current());
|
|
23
|
+
if (card.current)
|
|
24
|
+
windowFocusTarget(card.current)?.focus();
|
|
25
|
+
return () => {
|
|
26
|
+
unstack();
|
|
27
|
+
returnFocus(asker);
|
|
28
|
+
};
|
|
29
|
+
}, [asker]);
|
|
30
|
+
const foot = windowFoot(actions, start !== undefined, {
|
|
31
|
+
cancel: { label: text.cancel, labelKey: "common.cancel", glyph: _jsx(IconCancel, {}), wayOut: true },
|
|
32
|
+
close: { label: text.close, labelKey: "common.close", glyph: _jsx(IconClose, {}), wayOut: true },
|
|
33
|
+
});
|
|
34
|
+
return createPortal(_jsx("div", { className: "glim-modal-backdrop",
|
|
35
|
+
// A press beside an open menu only closes the menu, not the window under it.
|
|
36
|
+
onMouseDown: (e) => {
|
|
37
|
+
if (e.target === e.currentTarget && !menuIsOpen())
|
|
38
|
+
close.current();
|
|
39
|
+
}, children: _jsxs("div", { ref: card, role: "dialog", "aria-modal": "true", "aria-labelledby": titleId, className: ["glim-modal-card", "glim-window", size !== "normal" && `glim-window--${size}`, className].filter(Boolean).join(" "), children: [_jsx("h2", { id: titleId, className: "glim-window-title", children: _jsx(Badge, { tone: "heading", size: "heading", wrap: true, insetStart: 5, children: title }) }), _jsx("div", { className: "glim-modal-body glim-window-body", children: children }), foot.length > 0 && (_jsxs("div", { className: "glim-modal-foot", children: [start !== undefined && _jsx("span", { className: "glim-window-start", children: start }), foot.map((a, i) => (_jsx(Button, { label: a.label, labelKey: a.labelKey, glyph: a.glyph, tone: a.primary ? "accent" : "neutral", disabled: a.disabled, onClick: () => {
|
|
40
|
+
if (a.onClick?.() !== false)
|
|
41
|
+
close.current();
|
|
42
|
+
} }, i)))] }))] }) }), document.body);
|
|
43
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface WindowBarProps {
|
|
2
|
+
/** The app's name. The bar shows none, so this is what a screen reader
|
|
3
|
+
* announces for it. */
|
|
4
|
+
appName: string;
|
|
5
|
+
/** Whether the window fills the screen. The middle button then restores it,
|
|
6
|
+
* and the app turns its edge resizing off. */
|
|
7
|
+
maximised: boolean;
|
|
8
|
+
/** The buttons' accessible names, which also show in their bubbles. */
|
|
9
|
+
text: {
|
|
10
|
+
minimise: string;
|
|
11
|
+
maximise: string;
|
|
12
|
+
restore: string;
|
|
13
|
+
close: string;
|
|
14
|
+
};
|
|
15
|
+
onMinimise: () => void;
|
|
16
|
+
onToggleMaximise: () => void;
|
|
17
|
+
/** Asks the way the native close button does, so an app that hides to the
|
|
18
|
+
* tray on close still does. */
|
|
19
|
+
onClose: () => void;
|
|
20
|
+
/** Called once a press on the bar starts to move. The app hands the press to
|
|
21
|
+
* the system, which moves the window from there. */
|
|
22
|
+
onDragStart: () => void;
|
|
23
|
+
}
|
|
24
|
+
export declare function WindowBar({ appName, maximised, text, onMinimise, onToggleMaximise, onClose, onDragStart, }: WindowBarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { IconClose, IconWindowMaximise, IconWindowMinimise, IconWindowRestore } from "./glyphs.js";
|
|
4
|
+
import { IconTipButton } from "./IconTipButton.js";
|
|
5
|
+
const onButton = (e) => e.target.closest("button") !== null;
|
|
6
|
+
export function WindowBar({ appName, maximised, text, onMinimise, onToggleMaximise, onClose, onDragStart, }) {
|
|
7
|
+
// The drag starts on the first move, not on the press, so a click and a
|
|
8
|
+
// double click on the bar stay clicks. An edge the app's resize has taken
|
|
9
|
+
// arrives with its default prevented and is left to it.
|
|
10
|
+
const pressed = useRef(false);
|
|
11
|
+
const down = (e) => {
|
|
12
|
+
pressed.current = e.button === 0 && !e.defaultPrevented && !onButton(e);
|
|
13
|
+
};
|
|
14
|
+
const move = (e) => {
|
|
15
|
+
if (!pressed.current)
|
|
16
|
+
return;
|
|
17
|
+
pressed.current = false;
|
|
18
|
+
if (e.buttons === 1)
|
|
19
|
+
onDragStart();
|
|
20
|
+
};
|
|
21
|
+
const toggle = (e) => {
|
|
22
|
+
if (!onButton(e))
|
|
23
|
+
onToggleMaximise();
|
|
24
|
+
};
|
|
25
|
+
return (_jsxs("header", { "aria-label": appName, className: "glim-window-bar", onMouseDown: down, onMouseMove: move, onMouseUp: () => (pressed.current = false), onDoubleClick: toggle, children: [_jsx(WindowButton, { label: text.minimise, onPress: onMinimise, children: _jsx(IconWindowMinimise, {}) }), _jsx(WindowButton, { label: maximised ? text.restore : text.maximise, onPress: onToggleMaximise, children: maximised ? _jsx(IconWindowRestore, {}) : _jsx(IconWindowMaximise, {}) }), _jsx(WindowButton, { label: text.close, onPress: onClose, children: _jsx(IconClose, {}) })] }));
|
|
26
|
+
}
|
|
27
|
+
// The button takes the bar's full height and shows the house square inside, so
|
|
28
|
+
// a pointer thrown into the corner of a maximised window still lands on close.
|
|
29
|
+
function WindowButton({ label, onPress, children }) {
|
|
30
|
+
return (_jsx(IconTipButton, { tip: label, onClick: onPress, className: "glim-window-button", children: _jsx("span", { className: "glim-window-square", children: children }) }));
|
|
31
|
+
}
|
package/dist/glyphs.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type Mark } from "@glimstone/core";
|
|
3
|
+
/**
|
|
4
|
+
* Register the app's label-key-to-glyph mapping, once, at boot. A button that is
|
|
5
|
+
* given no glyph cannot be shown in glyph mode, and one place to ask saves
|
|
6
|
+
* passing an icon at every call site.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setGlyphResolver(fn: (labelKey: string) => ReactNode | undefined): void;
|
|
9
|
+
/** The mark for a label key, or nothing when no app resolver knows it. */
|
|
10
|
+
export declare function glyphFor(labelKey: string): ReactNode | undefined;
|
|
11
|
+
/** A mark from the core, drawn in the current colour. */
|
|
12
|
+
export declare function MarkSvg({ mark, className }: {
|
|
13
|
+
mark: Mark;
|
|
14
|
+
className?: string;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
16
|
+
export declare const IconClose: () => import("react").JSX.Element;
|
|
17
|
+
export declare const IconCancel: () => import("react").JSX.Element;
|
|
18
|
+
export declare const IconCheck: () => import("react").JSX.Element;
|
|
19
|
+
export declare const IconExpand: () => import("react").JSX.Element;
|
|
20
|
+
export declare const IconPencil: () => import("react").JSX.Element;
|
|
21
|
+
export declare const IconWindowMinimise: () => import("react").JSX.Element;
|
|
22
|
+
export declare const IconWindowMaximise: () => import("react").JSX.Element;
|
|
23
|
+
export declare const IconWindowRestore: () => import("react").JSX.Element;
|
|
24
|
+
export declare const IconEye: () => import("react").JSX.Element;
|
|
25
|
+
export declare const IconEyeOff: () => import("react").JSX.Element;
|
|
26
|
+
export declare const IconCopy: () => import("react").JSX.Element;
|
package/dist/glyphs.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { MARKS } from "@glimstone/core";
|
|
3
|
+
// The icon on a "Save" button or a nav item is the app's vocabulary, so GlimStone
|
|
4
|
+
// ships the assortment as a specification (`packages/core/glyphs.md`) and lets the app
|
|
5
|
+
// register a resolver. `Button` then picks a glyph by meaning. Without a resolver a
|
|
6
|
+
// button falls back to the glyph it was handed, and with neither, to text alone.
|
|
7
|
+
let resolver = null;
|
|
8
|
+
/**
|
|
9
|
+
* Register the app's label-key-to-glyph mapping, once, at boot. A button that is
|
|
10
|
+
* given no glyph cannot be shown in glyph mode, and one place to ask saves
|
|
11
|
+
* passing an icon at every call site.
|
|
12
|
+
*/
|
|
13
|
+
export function setGlyphResolver(fn) {
|
|
14
|
+
resolver = fn;
|
|
15
|
+
}
|
|
16
|
+
/** The mark for a label key, or nothing when no app resolver knows it. */
|
|
17
|
+
export function glyphFor(labelKey) {
|
|
18
|
+
return resolver ? resolver(labelKey) : undefined;
|
|
19
|
+
}
|
|
20
|
+
/** A mark from the core, drawn in the current colour. */
|
|
21
|
+
export function MarkSvg({ mark, className }) {
|
|
22
|
+
return (_jsx("svg", { width: mark.size, height: mark.size, viewBox: mark.viewBox, fill: "currentColor", className: className, "aria-hidden": "true", dangerouslySetInnerHTML: { __html: mark.body } }));
|
|
23
|
+
}
|
|
24
|
+
export const IconClose = () => _jsx(MarkSvg, { mark: MARKS.close, className: "glim-mark" });
|
|
25
|
+
export const IconCancel = () => _jsx(MarkSvg, { mark: MARKS.cancel, className: "glim-mark" });
|
|
26
|
+
export const IconCheck = () => _jsx(MarkSvg, { mark: MARKS.check, className: "glim-mark" });
|
|
27
|
+
export const IconExpand = () => _jsx(MarkSvg, { mark: MARKS.expand, className: "glim-mark" });
|
|
28
|
+
export const IconPencil = () => _jsx(MarkSvg, { mark: MARKS.pencil, className: "glim-mark" });
|
|
29
|
+
export const IconWindowMinimise = () => _jsx(MarkSvg, { mark: MARKS.windowMinimise, className: "glim-mark" });
|
|
30
|
+
export const IconWindowMaximise = () => _jsx(MarkSvg, { mark: MARKS.windowMaximise, className: "glim-mark" });
|
|
31
|
+
export const IconWindowRestore = () => _jsx(MarkSvg, { mark: MARKS.windowRestore, className: "glim-mark" });
|
|
32
|
+
export const IconEye = () => _jsx(MarkSvg, { mark: MARKS.eye, className: "glim-mark" });
|
|
33
|
+
export const IconEyeOff = () => _jsx(MarkSvg, { mark: MARKS.eyeOff, className: "glim-mark" });
|
|
34
|
+
export const IconCopy = () => _jsx(MarkSvg, { mark: MARKS.copy, className: "glim-mark" });
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export * from "./AboutCard.tsx";
|
|
2
|
+
export * from "./Badge.tsx";
|
|
3
|
+
export * from "./Button.tsx";
|
|
4
|
+
export * from "./Card.tsx";
|
|
5
|
+
export * from "./Checkbox.tsx";
|
|
6
|
+
export * from "./CoffeeDialog.tsx";
|
|
7
|
+
export * from "./ColorPicker.tsx";
|
|
8
|
+
export * from "./ConfirmDialog.tsx";
|
|
9
|
+
export * from "./ContextMenu.tsx";
|
|
10
|
+
export * from "./CopyField.tsx";
|
|
11
|
+
export * from "./CryptoDonateDialog.tsx";
|
|
12
|
+
export * from "./DropdownListbox.tsx";
|
|
13
|
+
export * from "./EmptyState.tsx";
|
|
14
|
+
export * from "./IconTipButton.tsx";
|
|
15
|
+
export * from "./InfoBubble.tsx";
|
|
16
|
+
export * from "./Kbd.tsx";
|
|
17
|
+
export * from "./MenuBar.tsx";
|
|
18
|
+
export * from "./Meter.tsx";
|
|
19
|
+
export * from "./NumberField.tsx";
|
|
20
|
+
export * from "./PasswordField.tsx";
|
|
21
|
+
export * from "./PaypalDialog.tsx";
|
|
22
|
+
export * from "./Pill.tsx";
|
|
23
|
+
export * from "./ProgressBar.tsx";
|
|
24
|
+
export * from "./ReadmeButton.tsx";
|
|
25
|
+
export * from "./Selector.tsx";
|
|
26
|
+
export * from "./SidebarRow.tsx";
|
|
27
|
+
export * from "./SubCard.tsx";
|
|
28
|
+
export * from "./Toast.tsx";
|
|
29
|
+
export * from "./Toggle.tsx";
|
|
30
|
+
export * from "./UnavailableNotice.tsx";
|
|
31
|
+
export * from "./Window.tsx";
|
|
32
|
+
export * from "./WindowBar.tsx";
|
|
33
|
+
export * from "./glyphs.tsx";
|
|
34
|
+
export * from "./portalHue.ts";
|
|
35
|
+
export * from "./useConfirm.tsx";
|
|
36
|
+
export * from "./useLabelMode.ts";
|
|
37
|
+
export * from "./usePaypalButtons.ts";
|
|
38
|
+
export * from "./useTipBubble.tsx";
|
|
39
|
+
export { GLIMSTONE_VERSION } from "@glimstone/core";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export * from "./AboutCard.js";
|
|
2
|
+
export * from "./Badge.js";
|
|
3
|
+
export * from "./Button.js";
|
|
4
|
+
export * from "./Card.js";
|
|
5
|
+
export * from "./Checkbox.js";
|
|
6
|
+
export * from "./CoffeeDialog.js";
|
|
7
|
+
export * from "./ColorPicker.js";
|
|
8
|
+
export * from "./ConfirmDialog.js";
|
|
9
|
+
export * from "./ContextMenu.js";
|
|
10
|
+
export * from "./CopyField.js";
|
|
11
|
+
export * from "./CryptoDonateDialog.js";
|
|
12
|
+
export * from "./DropdownListbox.js";
|
|
13
|
+
export * from "./EmptyState.js";
|
|
14
|
+
export * from "./IconTipButton.js";
|
|
15
|
+
export * from "./InfoBubble.js";
|
|
16
|
+
export * from "./Kbd.js";
|
|
17
|
+
export * from "./MenuBar.js";
|
|
18
|
+
export * from "./Meter.js";
|
|
19
|
+
export * from "./NumberField.js";
|
|
20
|
+
export * from "./PasswordField.js";
|
|
21
|
+
export * from "./PaypalDialog.js";
|
|
22
|
+
export * from "./Pill.js";
|
|
23
|
+
export * from "./ProgressBar.js";
|
|
24
|
+
export * from "./ReadmeButton.js";
|
|
25
|
+
export * from "./Selector.js";
|
|
26
|
+
export * from "./SidebarRow.js";
|
|
27
|
+
export * from "./SubCard.js";
|
|
28
|
+
export * from "./Toast.js";
|
|
29
|
+
export * from "./Toggle.js";
|
|
30
|
+
export * from "./UnavailableNotice.js";
|
|
31
|
+
export * from "./Window.js";
|
|
32
|
+
export * from "./WindowBar.js";
|
|
33
|
+
export * from "./glyphs.js";
|
|
34
|
+
export * from "./portalHue.js";
|
|
35
|
+
export * from "./useConfirm.js";
|
|
36
|
+
export * from "./useLabelMode.js";
|
|
37
|
+
export * from "./usePaypalButtons.js";
|
|
38
|
+
export * from "./useTipBubble.js";
|
|
39
|
+
export { GLIMSTONE_VERSION } from "@glimstone/core";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
/** What a portalled panel needs to stand in its trigger's palette position. */
|
|
3
|
+
export interface PortalHue {
|
|
4
|
+
/** Inline custom properties to spread onto the portalled element. */
|
|
5
|
+
style: Record<string, string> | undefined;
|
|
6
|
+
/** `"glim-hue"` when there is a hue to apply, otherwise `""`. */
|
|
7
|
+
className: string;
|
|
8
|
+
}
|
|
9
|
+
/** Copies the trigger's rainbow position onto a portalled panel while it is open. */
|
|
10
|
+
export declare function usePortalHue(open: boolean, triggerRef: RefObject<HTMLElement | null>): PortalHue;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useLayoutEffect, useState } from "react";
|
|
2
|
+
import { readPortalHue } from "@glimstone/core";
|
|
3
|
+
/** Copies the trigger's rainbow position onto a portalled panel while it is open. */
|
|
4
|
+
export function usePortalHue(open, triggerRef) {
|
|
5
|
+
const [hue, setHue] = useState(null);
|
|
6
|
+
useLayoutEffect(() => {
|
|
7
|
+
if (!open) {
|
|
8
|
+
setHue(null);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (triggerRef.current)
|
|
12
|
+
setHue(readPortalHue(triggerRef.current));
|
|
13
|
+
}, [open, triggerRef]);
|
|
14
|
+
return { style: hue ?? undefined, className: hue ? "glim-hue" : "" };
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from "react";
|
|
2
|
+
export interface ConfirmText {
|
|
3
|
+
/** The dialog's title, the same for every question, such as "Confirm". */
|
|
4
|
+
title: string;
|
|
5
|
+
cancel: string;
|
|
6
|
+
/** The confirm button's words where a question passes none of its own. */
|
|
7
|
+
confirm: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ConfirmOptions {
|
|
10
|
+
/** The words of the action being confirmed, so the answer repeats "Delete"
|
|
11
|
+
* rather than a bare "Confirm". */
|
|
12
|
+
confirmLabel?: string;
|
|
13
|
+
/** Translation key behind confirmLabel, so the confirm button shows its glyph. */
|
|
14
|
+
confirmLabelKey?: string;
|
|
15
|
+
confirmGlyph?: ReactNode;
|
|
16
|
+
/** A switch or two the answer needs, shown under the question. */
|
|
17
|
+
extra?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export declare function useConfirm(text: ConfirmText): {
|
|
20
|
+
confirm: (message: string, options?: ConfirmOptions) => Promise<boolean>;
|
|
21
|
+
confirmDialog: import("react").ReactPortal | null;
|
|
22
|
+
dismiss: () => void;
|
|
23
|
+
};
|
|
24
|
+
/** Escape from anywhere and a Tab trap over the dialog's own controls, so focus
|
|
25
|
+
* never reaches the page it covers. Exported for any other modal window. */
|
|
26
|
+
export declare function useDialogKeys(open: boolean, dialogRef: RefObject<HTMLDivElement | null>, onCancel: () => void): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import { focusedAsker, returnFocus, trapDialogKeys } from "@glimstone/core";
|
|
5
|
+
import { ConfirmDialog } from "./ConfirmDialog.js";
|
|
6
|
+
export function useConfirm(text) {
|
|
7
|
+
const [pending, setPending] = useState(null);
|
|
8
|
+
const resolveRef = useRef(null);
|
|
9
|
+
const dialogRef = useRef(null);
|
|
10
|
+
const askerRef = useRef(null);
|
|
11
|
+
const confirm = useCallback((message, options) => {
|
|
12
|
+
askerRef.current = focusedAsker();
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
resolveRef.current = resolve;
|
|
15
|
+
setPending({ message, ...options });
|
|
16
|
+
});
|
|
17
|
+
}, []);
|
|
18
|
+
const settle = useCallback((result) => {
|
|
19
|
+
resolveRef.current?.(result);
|
|
20
|
+
resolveRef.current = null;
|
|
21
|
+
setPending(null);
|
|
22
|
+
returnFocus(askerRef.current);
|
|
23
|
+
askerRef.current = null;
|
|
24
|
+
}, []);
|
|
25
|
+
/** For a caller whose question stopped making sense while it was open. */
|
|
26
|
+
const dismiss = useCallback(() => settle(false), [settle]);
|
|
27
|
+
useDialogKeys(pending !== null, dialogRef, dismiss);
|
|
28
|
+
// An ancestor with a transform would confine a fixed backdrop to its own box,
|
|
29
|
+
// so the dialog goes to <body>.
|
|
30
|
+
const confirmDialog = pending
|
|
31
|
+
? createPortal(_jsx(ConfirmDialog, { ref: dialogRef, title: text.title, message: pending.message, confirmLabel: pending.confirmLabel ?? text.confirm, confirmLabelKey: pending.confirmLabelKey, confirmGlyph: pending.confirmGlyph, cancelLabel: text.cancel, extra: pending.extra, onConfirm: () => settle(true), onCancel: () => settle(false) }), document.body)
|
|
32
|
+
: null;
|
|
33
|
+
return { confirm, confirmDialog, dismiss };
|
|
34
|
+
}
|
|
35
|
+
/** Escape from anywhere and a Tab trap over the dialog's own controls, so focus
|
|
36
|
+
* never reaches the page it covers. Exported for any other modal window. */
|
|
37
|
+
export function useDialogKeys(open, dialogRef, onCancel) {
|
|
38
|
+
useEffect(() => (open ? trapDialogKeys(() => dialogRef.current, onCancel) : undefined), [open, dialogRef, onCancel]);
|
|
39
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { getLabelMode, subscribeLabelMode } from "@glimstone/core";
|
|
3
|
+
/**
|
|
4
|
+
* The current label mode for one axis. The first value is read synchronously so
|
|
5
|
+
* the first paint is already right.
|
|
6
|
+
*/
|
|
7
|
+
export function useLabelMode(axis) {
|
|
8
|
+
const [mode, setMode] = useState(() => getLabelMode(axis));
|
|
9
|
+
useEffect(() => subscribeLabelMode(() => setMode(getLabelMode(axis))), [axis]);
|
|
10
|
+
return mode;
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type GiveFrequency, type PaypalConfig } from "@glimstone/core";
|
|
2
|
+
/**
|
|
3
|
+
* Renders PayPal's two buttons into the returned ref, and again whenever the
|
|
4
|
+
* frequency changes, since a subscription needs the other SDK namespace. The
|
|
5
|
+
* amount is read at click time, so picking another amount reloads nothing.
|
|
6
|
+
*/
|
|
7
|
+
export declare function usePaypalButtons({ config, frequency, amount, description, onDone, onError, }: {
|
|
8
|
+
config: PaypalConfig;
|
|
9
|
+
frequency: GiveFrequency;
|
|
10
|
+
/** The amount to charge, or null while the typed amount is not valid. */
|
|
11
|
+
amount: string | null;
|
|
12
|
+
description: string;
|
|
13
|
+
onDone: () => void;
|
|
14
|
+
onError: () => void;
|
|
15
|
+
}): import("react").RefObject<HTMLDivElement | null>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { donationHandlers, loadPaypal } from "@glimstone/core";
|
|
3
|
+
/**
|
|
4
|
+
* Renders PayPal's two buttons into the returned ref, and again whenever the
|
|
5
|
+
* frequency changes, since a subscription needs the other SDK namespace. The
|
|
6
|
+
* amount is read at click time, so picking another amount reloads nothing.
|
|
7
|
+
*/
|
|
8
|
+
export function usePaypalButtons({ config, frequency, amount, description, onDone, onError, }) {
|
|
9
|
+
const container = useRef(null);
|
|
10
|
+
const latest = useRef({ amount, onDone, onError });
|
|
11
|
+
latest.current = { amount, onDone, onError };
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const box = container.current;
|
|
14
|
+
if (!box)
|
|
15
|
+
return;
|
|
16
|
+
let buttons = null;
|
|
17
|
+
let cancelled = false;
|
|
18
|
+
loadPaypal(config, frequency !== "once").then((paypal) => {
|
|
19
|
+
if (cancelled)
|
|
20
|
+
return;
|
|
21
|
+
const instance = paypal.Buttons({
|
|
22
|
+
// Blue is one of the five colours PayPal allows, and reads on both themes.
|
|
23
|
+
style: { layout: "vertical", color: "blue", shape: "rect", borderRadius: 10, label: "donate", height: 40 },
|
|
24
|
+
// A half-typed amount keeps the buttons from opening PayPal at all.
|
|
25
|
+
onClick: (_, actions) => (latest.current.amount ? actions.resolve() : actions.reject()),
|
|
26
|
+
...donationHandlers(config, frequency, () => latest.current.amount ?? "0", description, () => latest.current.onDone()),
|
|
27
|
+
onError: () => latest.current.onError(),
|
|
28
|
+
});
|
|
29
|
+
buttons = instance;
|
|
30
|
+
box.replaceChildren();
|
|
31
|
+
instance.render(box).catch(() => latest.current.onError());
|
|
32
|
+
}, () => {
|
|
33
|
+
if (!cancelled)
|
|
34
|
+
latest.current.onError();
|
|
35
|
+
});
|
|
36
|
+
return () => {
|
|
37
|
+
cancelled = true;
|
|
38
|
+
buttons?.close().catch(() => { });
|
|
39
|
+
};
|
|
40
|
+
}, [config, frequency, description]);
|
|
41
|
+
return container;
|
|
42
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface TipBubble {
|
|
3
|
+
/** Ref callback for the trigger element the bubble is placed against. A
|
|
4
|
+
* callback, so a trigger that keeps its own ref can feed both from one
|
|
5
|
+
* attribute. */
|
|
6
|
+
ref: (el: HTMLElement | null) => void;
|
|
7
|
+
/** Spread on the trigger. Focus opens the bubble too, when it came from the
|
|
8
|
+
* keyboard. */
|
|
9
|
+
handlers: {
|
|
10
|
+
onMouseEnter: () => void;
|
|
11
|
+
onMouseLeave: () => void;
|
|
12
|
+
onFocus: () => void;
|
|
13
|
+
onBlur: () => void;
|
|
14
|
+
};
|
|
15
|
+
/** `aria-describedby` while open, so the bubble is announced as the
|
|
16
|
+
* trigger's description. */
|
|
17
|
+
describedBy: string | undefined;
|
|
18
|
+
/** The bubble, portalled to <body> so no card's `overflow: hidden` clips it,
|
|
19
|
+
* or null when there is nothing to show. Render it beside the trigger. */
|
|
20
|
+
bubble: ReactNode;
|
|
21
|
+
/** Wraps a disabled trigger with a tip in a box that still sees the pointer,
|
|
22
|
+
* since a disabled <button> emits no mouse events. Other triggers pass
|
|
23
|
+
* through unchanged. */
|
|
24
|
+
wrap: (node: ReactNode) => ReactNode;
|
|
25
|
+
/** Open or close by hand, for a hover wrapper of the call site's own. */
|
|
26
|
+
show: () => void;
|
|
27
|
+
hide: () => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @param tip What the bubble says. When it is empty nothing opens or renders
|
|
31
|
+
* and `wrap` passes its node through.
|
|
32
|
+
* @param disabled Whether the trigger is currently disabled; see `wrap`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function useTipBubble(tip?: string, disabled?: boolean): TipBubble;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import { dismissBubbleOn, placeBubble, pointerWasLast, trackInputModality } from "@glimstone/core";
|
|
5
|
+
/**
|
|
6
|
+
* @param tip What the bubble says. When it is empty nothing opens or renders
|
|
7
|
+
* and `wrap` passes its node through.
|
|
8
|
+
* @param disabled Whether the trigger is currently disabled; see `wrap`.
|
|
9
|
+
*/
|
|
10
|
+
export function useTipBubble(tip, disabled = false) {
|
|
11
|
+
const [open, setOpen] = useState(false);
|
|
12
|
+
const triggerRef = useRef(null);
|
|
13
|
+
const bubbleRef = useRef(null);
|
|
14
|
+
const tooltipId = useId();
|
|
15
|
+
// Flipping `disabled` replaces the trigger element: `wrap` boxes a disabled
|
|
16
|
+
// one, so React mounts a new <button> in its place. The old one takes its
|
|
17
|
+
// focus and hover with it without firing blur or mouseleave, so an open
|
|
18
|
+
// bubble would stay up for good. Closing during render keeps it from being
|
|
19
|
+
// painted even once; a pointer still over the control reopens it on its
|
|
20
|
+
// next move, through the wrapper's mouseenter.
|
|
21
|
+
const [seenDisabled, setSeenDisabled] = useState(disabled);
|
|
22
|
+
if (seenDisabled !== disabled) {
|
|
23
|
+
setSeenDisabled(disabled);
|
|
24
|
+
setOpen(false);
|
|
25
|
+
}
|
|
26
|
+
const shown = !!tip && open;
|
|
27
|
+
function show() {
|
|
28
|
+
if (!tip)
|
|
29
|
+
return;
|
|
30
|
+
setOpen(true);
|
|
31
|
+
}
|
|
32
|
+
function hide() {
|
|
33
|
+
setOpen(false);
|
|
34
|
+
}
|
|
35
|
+
useEffect(trackInputModality, []);
|
|
36
|
+
function showOnFocus() {
|
|
37
|
+
if (!pointerWasLast())
|
|
38
|
+
show();
|
|
39
|
+
}
|
|
40
|
+
useLayoutEffect(() => {
|
|
41
|
+
if (shown && triggerRef.current && bubbleRef.current)
|
|
42
|
+
placeBubble(triggerRef.current, bubbleRef.current);
|
|
43
|
+
}, [shown]);
|
|
44
|
+
useEffect(() => (shown ? dismissBubbleOn(hide) : undefined), [shown]);
|
|
45
|
+
return {
|
|
46
|
+
ref: (el) => {
|
|
47
|
+
triggerRef.current = el;
|
|
48
|
+
},
|
|
49
|
+
handlers: {
|
|
50
|
+
onMouseEnter: show,
|
|
51
|
+
onMouseLeave: hide,
|
|
52
|
+
onFocus: showOnFocus,
|
|
53
|
+
onBlur: hide,
|
|
54
|
+
},
|
|
55
|
+
describedBy: shown ? tooltipId : undefined,
|
|
56
|
+
bubble: shown
|
|
57
|
+
? createPortal(_jsx("div", { ref: bubbleRef, role: "tooltip", id: tooltipId, className: "glim-bubble glim-fade", children: tip }), document.body)
|
|
58
|
+
: null,
|
|
59
|
+
wrap: (node) => disabled && tip ? (_jsx("span", { className: "glim-tip-wrap", onMouseEnter: show, onMouseLeave: hide, children: node })) : (node),
|
|
60
|
+
show,
|
|
61
|
+
hide,
|
|
62
|
+
};
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glimstone/react",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "4.1.0",
|
|
4
|
+
"description": "GlimStone's components for React",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/junkerderprovinz/glimstone.git", "directory": "packages/react" },
|
|
7
|
+
"homepage": "https://junkerderprovinz.github.io/glimstone/",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
|
|
12
|
+
"./*": { "types": "./dist/*.d.ts", "default": "./dist/*.js" }
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.build.json"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@glimstone/core": "4.1.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@zag-js/combobox": "^1.46.0",
|
|
23
|
+
"@zag-js/menu": "^1.46.0",
|
|
24
|
+
"@zag-js/react": "^1.46.0",
|
|
25
|
+
"@zag-js/select": "^1.46.0",
|
|
26
|
+
"@zag-js/slider": "^1.46.0",
|
|
27
|
+
"react": "^19.0.0",
|
|
28
|
+
"react-dom": "^19.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|