@glimstone/react 4.3.4 → 4.3.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.
@@ -37,10 +37,11 @@ export interface SignInCardProps extends SignInHandlers {
37
37
  /** Classes for the page around the card. */
38
38
  className?: string;
39
39
  }
40
- export declare function SignInField({ label, htmlFor, hint, children }: {
40
+ export declare function SignInField({ label, htmlFor, hint, hidden, children }: {
41
41
  label: string;
42
42
  htmlFor: string;
43
43
  hint?: string;
44
+ hidden?: boolean;
44
45
  children: ReactNode;
45
46
  }): import("react").JSX.Element;
46
47
  export declare function SignInCard({ logo, appName, text, passkey, reset, minPassword, note, fields, actions, step, labelKeys, idPrefix, autoFocus, className, ...handlers }: SignInCardProps): import("react").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
3
- import { createSignInFlow, focusFirstField, resetBlocked, showRefusal, signInBlocked, signInStage } from "@glimstone/core";
3
+ import { createSignInFlow, focusFirstField, labelInside, resetBlocked, showRefusal, signInBlocked, signInStage } from "@glimstone/core";
4
4
  import { Button } from "./Button.js";
5
5
  import { InfoBubble } from "./InfoBubble.js";
6
6
  import { PasswordField } from "./PasswordField.js";
@@ -12,8 +12,16 @@ const LABEL_KEYS = {
12
12
  back: "back",
13
13
  setPassword: "setPassword",
14
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] }));
15
+ // A field on the sign-in card. Its label stands inside the field until the
16
+ // first key, and above it when the field brings a placeholder or a hint.
17
+ export function SignInField({ label, htmlFor, hint, hidden, children }) {
18
+ const [inside, setInside] = useState(false);
19
+ const was = useRef(undefined);
20
+ useEffect(() => {
21
+ setInside(labelInside(document.getElementById(htmlFor), label, hint, was.current));
22
+ was.current = label;
23
+ }, [htmlFor, label, hint]);
24
+ return (_jsxs("div", { className: "glim-signin-field", hidden: hidden, children: [_jsxs("label", { htmlFor: htmlFor, className: inside ? "glim-sr-only" : "glim-signin-label", children: [label, hint && _jsx(InfoBubble, { tip: hint })] }), children] }));
17
25
  }
18
26
  export function SignInCard({ logo, appName, text, passkey = false, reset = false, minPassword = 12, note, fields, actions, step, labelKeys, idPrefix, autoFocus = true, className, ...handlers }) {
19
27
  const latest = useRef({ ...handlers, text, minPassword });
@@ -41,7 +49,7 @@ export function SignInCard({ logo, appName, text, passkey = false, reset = false
41
49
  const error = s.error && (_jsx("p", { className: "glim-signin-error", role: "alert", children: s.error }));
42
50
  const back = _jsx(Button, { label: text.back, labelKey: keys.back, tone: "subtle", "data-signin": "back", disabled: !!s.busy, onClick: flow.back });
43
51
  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
52
+ (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, _jsx(SignInField, { label: text.password, htmlFor: id("password"), hidden: s.viaPasskey, children: _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
53
  ? back
46
54
  : 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
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/react",
3
- "version": "4.3.4",
3
+ "version": "4.3.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.3.4"
19
+ "@glimstone/core": "4.3.5"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@zag-js/combobox": "^1.46.0",