@glimstone/react 4.1.2 → 4.2.2

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 CHANGED
@@ -76,6 +76,7 @@ needs none of them.
76
76
  | `GlyphField` | A field with a glyph inside it, such as a filter, and controls after it in the box |
77
77
  | `Table` | A short list of facts in columns |
78
78
  | `PasswordField`, `CopyField` | A secret with the reveal eye inside the field, and a value in monospace with a button that copies it |
79
+ | `SignInCard`, `SignInField` | The sign-in page: the app's logo and name, the password, a code when the app asks for one, a passkey and the reset form in the same card. The app's own fields, buttons and steps go into `fields`, `actions` and `step`, and `SignInField` gives a field of the app's own the label above it |
79
80
  | `PathField`, `Tree` | A path with a button that asks the app for one, and a hierarchy loaded as it opens, for the picker behind that button |
80
81
  | `ListRow`, `RowMark`, `GlyphTile` | One row of a list with a tile, badges and buttons that come in on hover, the round mark on a row picked for an action on many, and a small holder for a glyph |
81
82
  | `IconButton` | A glyph in a square in every label mode, for a row that keeps its text, as a link with `href`, on or off with `pressed`, and `absent` to hold a missing button's place |
@@ -0,0 +1,46 @@
1
+ import { type ReactNode } from "react";
2
+ import { type SignInHandlers, type SignInText } from "@glimstone/core";
3
+ export type { ResetAnswer, SignInAnswer, SignInText } from "@glimstone/core";
4
+ /** The label keys behind the card's buttons, which pick their glyphs (see Button). */
5
+ export interface SignInLabelKeys {
6
+ signIn: string;
7
+ passkey: string;
8
+ forgot: string;
9
+ back: string;
10
+ setPassword: string;
11
+ }
12
+ export interface SignInCardProps extends SignInHandlers {
13
+ /** The app's logo, as an address or as markup. It stands large above the name. */
14
+ logo?: string | ReactNode;
15
+ /** The page's heading. */
16
+ appName: string;
17
+ text: SignInText;
18
+ /** Offers Sign in with a passkey. Pass it only where a passkey can answer on this address. */
19
+ passkey?: boolean;
20
+ /** Offers Forgot password? and the reset form. */
21
+ reset?: boolean;
22
+ /** The shortest new password the reset form takes, as the server says. */
23
+ minPassword?: number;
24
+ /** One line at the top of the sign-in form, such as "You are signed out". */
25
+ note?: string;
26
+ /** The app's own fields, above the password. */
27
+ fields?: ReactNode;
28
+ /** The app's own buttons, under Sign in and the passkey. */
29
+ actions?: ReactNode;
30
+ /** A step the app runs itself, in place of the card's forms. */
31
+ step?: ReactNode;
32
+ labelKeys?: Partial<SignInLabelKeys>;
33
+ /** The start of the fields' ids: `-password`, `-code`, `-reset-code`, `-new` and `-confirm` follow it. */
34
+ idPrefix?: string;
35
+ /** Puts the focus in the first empty field when the card opens. */
36
+ autoFocus?: boolean;
37
+ /** Classes for the page around the card. */
38
+ className?: string;
39
+ }
40
+ export declare function SignInField({ label, htmlFor, hint, children }: {
41
+ label: string;
42
+ htmlFor: string;
43
+ hint?: string;
44
+ children: ReactNode;
45
+ }): import("react").JSX.Element;
46
+ export declare function SignInCard({ logo, appName, text, passkey, reset, minPassword, note, fields, actions, step, labelKeys, idPrefix, autoFocus, className, ...handlers }: SignInCardProps): import("react").JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
3
+ import { createSignInFlow, focusFirstField, resetBlocked, showRefusal, signInBlocked, signInStage } from "@glimstone/core";
4
+ import { Button } from "./Button.js";
5
+ import { InfoBubble } from "./InfoBubble.js";
6
+ import { PasswordField } from "./PasswordField.js";
7
+ import { TextField } from "./TextField.js";
8
+ const LABEL_KEYS = {
9
+ signIn: "signIn",
10
+ passkey: "signInWithPasskey",
11
+ forgot: "forgotPassword",
12
+ back: "back",
13
+ setPassword: "setPassword",
14
+ };
15
+ export function SignInField({ label, htmlFor, hint, children }) {
16
+ return (_jsxs("div", { className: "glim-signin-field", children: [_jsxs("label", { htmlFor: htmlFor, className: "glim-signin-label", children: [label, hint && _jsx(InfoBubble, { tip: hint })] }), children] }));
17
+ }
18
+ export function SignInCard({ logo, appName, text, passkey = false, reset = false, minPassword = 12, note, fields, actions, step, labelKeys, idPrefix, autoFocus = true, className, ...handlers }) {
19
+ const latest = useRef({ ...handlers, text, minPassword });
20
+ latest.current = { ...handlers, text, minPassword };
21
+ const [flow] = useState(() => createSignInFlow(() => latest.current));
22
+ const s = useSyncExternalStore(flow.subscribe, flow.state, flow.state);
23
+ const ownId = useId();
24
+ const id = (name) => `${idPrefix ?? ownId}-${name}`;
25
+ const keys = { ...LABEL_KEYS, ...labelKeys };
26
+ const eye = { show: text.show, hide: text.hide };
27
+ const card = useRef(null);
28
+ const stage = step ? "step" : signInStage(s);
29
+ const opened = useRef(false);
30
+ useEffect(() => {
31
+ if (opened.current || autoFocus)
32
+ focusFirstField(card.current);
33
+ opened.current = true;
34
+ }, [stage]);
35
+ const refusal = s.refusal;
36
+ useEffect(() => (refusal ? showRefusal(card.current, refusal) : undefined), [refusal?.count]);
37
+ const submit = (e) => {
38
+ e.preventDefault();
39
+ void flow.submit();
40
+ };
41
+ const error = s.error && (_jsx("p", { className: "glim-signin-error", role: "alert", children: s.error }));
42
+ const back = _jsx(Button, { label: text.back, labelKey: keys.back, tone: "subtle", "data-signin": "back", disabled: !!s.busy, onClick: flow.back });
43
+ return (_jsx("div", { className: ["glim-signin", className].filter(Boolean).join(" "), children: _jsxs("div", { ref: card, className: "glim-card glim-signin-card", children: [_jsxs("div", { className: "glim-signin-head", children: [logo && (_jsx("span", { className: "glim-signin-logo", "aria-hidden": "true", children: typeof logo === "string" ? _jsx("img", { src: logo, alt: "", draggable: false }) : logo })), _jsx("h1", { className: "glim-signin-name", children: appName })] }), step ??
44
+ (s.view === "reset" ? (_jsxs("form", { className: "glim-signin-form", noValidate: true, onSubmit: submit, children: [_jsx(SignInField, { label: text.resetCode, htmlFor: id("reset-code"), hint: text.resetCodeTip, children: _jsx(TextField, { id: id("reset-code"), "data-signin-field": "resetCode", className: "glim-signin-log-code", value: s.resetCode, onChange: (e) => flow.set("resetCode", e.target.value), autoComplete: "one-time-code", autoCapitalize: "characters", spellCheck: false, placeholder: "XXXX-XXXX-XXXX" }) }), _jsx(SignInField, { label: text.newPassword, htmlFor: id("new"), children: _jsx(PasswordField, { id: id("new"), "data-signin-field": "newPassword", value: s.newPassword, onChange: (e) => flow.set("newPassword", e.target.value), autoComplete: "new-password", text: eye }) }), _jsx(SignInField, { label: text.confirmPassword, htmlFor: id("confirm"), children: _jsx(PasswordField, { id: id("confirm"), "data-signin-field": "confirm", value: s.confirm, onChange: (e) => flow.set("confirm", e.target.value), autoComplete: "new-password", text: eye }) }), error, _jsx(Button, { label: text.setPassword, labelKey: keys.setPassword, tone: "accent", type: "submit", "data-signin": "set-password", disabled: resetBlocked(s), busy: s.busy === "setPassword", title: s.busy === "setPassword" ? text.saving : undefined }), back] })) : (_jsxs("form", { className: "glim-signin-form", noValidate: true, onSubmit: submit, children: [note && (_jsx("p", { className: "glim-signin-note", role: "status", children: note })), !s.viaPasskey && fields, _jsxs("div", { className: "glim-signin-field", hidden: s.viaPasskey, children: [_jsx("label", { htmlFor: id("password"), className: "glim-signin-label", children: text.password }), _jsx(PasswordField, { id: id("password"), "data-signin-field": "password", value: s.password, onChange: (e) => flow.set("password", e.target.value), autoComplete: "current-password", text: eye })] }), s.needCode && (_jsxs("div", { className: "glim-signin-field", children: [_jsx("label", { htmlFor: id("code"), className: "glim-signin-label", children: text.code }), _jsx(TextField, { id: id("code"), "data-signin-field": "code", className: "glim-signin-code", value: s.code, onChange: (e) => flow.set("code", e.target.value), inputMode: "numeric", autoComplete: "one-time-code", spellCheck: false, placeholder: "000000" }), _jsx("p", { className: "glim-signin-hint", children: text.codeHint })] })), error, _jsx(Button, { label: text.signIn, labelKey: keys.signIn, tone: "accent", type: "submit", "data-signin": "submit", disabled: signInBlocked(s), busy: s.busy === "signIn", title: s.busy === "signIn" ? text.signingIn : undefined }), !s.needCode && passkey && (_jsx(Button, { label: text.passkey, labelKey: keys.passkey, "data-signin": "passkey", disabled: !!s.busy, busy: s.busy === "passkey", onClick: () => void flow.passkey() })), !s.needCode && actions, s.needCode
45
+ ? back
46
+ : reset && (_jsx(Button, { label: text.forgot, labelKey: keys.forgot, tone: "subtle", "data-signin": "forgot", disabled: !!s.busy, busy: s.busy === "askCode", onClick: () => void flow.forgot() }))] })))] }) }));
47
+ }
package/dist/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export * from "./ReadmeButton.tsx";
33
33
  export * from "./RowMark.tsx";
34
34
  export * from "./Selector.tsx";
35
35
  export * from "./SidebarRow.tsx";
36
+ export * from "./SignInCard.tsx";
36
37
  export * from "./SubCard.tsx";
37
38
  export * from "./Table.tsx";
38
39
  export * from "./TextField.tsx";
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ export * from "./ReadmeButton.js";
33
33
  export * from "./RowMark.js";
34
34
  export * from "./Selector.js";
35
35
  export * from "./SidebarRow.js";
36
+ export * from "./SignInCard.js";
36
37
  export * from "./SubCard.js";
37
38
  export * from "./Table.js";
38
39
  export * from "./TextField.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/react",
3
- "version": "4.1.2",
3
+ "version": "4.2.2",
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.1.2"
19
+ "@glimstone/core": "4.2.2"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@zag-js/combobox": "^1.46.0",