@jcsoftdev/ui 0.4.0 → 0.5.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.
Files changed (131) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +1 -1
  3. package/dist/atoms/button/button.d.ts +8 -1
  4. package/dist/atoms/button/button.js +10 -3
  5. package/dist/atoms/divider/divider.d.ts +15 -0
  6. package/dist/atoms/divider/divider.js +27 -0
  7. package/dist/atoms/divider/index.d.ts +1 -0
  8. package/dist/atoms/divider/index.js +1 -0
  9. package/dist/atoms/icon-button/icon-button.d.ts +1 -1
  10. package/dist/atoms/index.d.ts +1 -0
  11. package/dist/atoms/index.js +1 -0
  12. package/dist/auth/auth-illustration/auth-illustration.d.ts +35 -0
  13. package/dist/auth/auth-illustration/auth-illustration.js +72 -0
  14. package/dist/auth/auth-illustration/index.d.ts +3 -0
  15. package/dist/auth/auth-illustration/index.js +11 -0
  16. package/dist/auth/auth-illustration/look.d.ts +30 -0
  17. package/dist/auth/auth-illustration/look.js +0 -0
  18. package/dist/auth/auth-illustration/model.d.ts +133 -0
  19. package/dist/auth/auth-illustration/model.js +202 -0
  20. package/dist/auth/auth-illustration/use-art-pointer.d.ts +9 -0
  21. package/dist/auth/auth-illustration/use-art-pointer.js +69 -0
  22. package/dist/auth/auth-layout/auth-layout.d.ts +80 -0
  23. package/dist/auth/auth-layout/auth-layout.js +190 -0
  24. package/dist/auth/auth-layout/index.d.ts +1 -0
  25. package/dist/auth/auth-layout/index.js +1 -0
  26. package/dist/auth/character/character.d.ts +12 -0
  27. package/dist/auth/character/character.js +333 -0
  28. package/dist/auth/character/index.d.ts +1 -0
  29. package/dist/auth/character/index.js +1 -0
  30. package/dist/auth/index.d.ts +4 -0
  31. package/dist/auth/index.js +4 -0
  32. package/dist/auth/internal/auth-context.d.ts +17 -0
  33. package/dist/auth/internal/auth-context.js +10 -0
  34. package/dist/auth/internal/auth-styles.d.ts +1 -0
  35. package/dist/auth/internal/auth-styles.js +29 -0
  36. package/dist/auth/internal/portal-glyphs.d.ts +6 -0
  37. package/dist/auth/internal/portal-glyphs.js +39 -0
  38. package/dist/auth/login-form/context.d.ts +51 -0
  39. package/dist/auth/login-form/context.js +12 -0
  40. package/dist/auth/login-form/index.d.ts +2 -0
  41. package/dist/auth/login-form/index.js +23 -0
  42. package/dist/auth/login-form/login-form.d.ts +66 -0
  43. package/dist/auth/login-form/login-form.js +233 -0
  44. package/dist/auth/login-form/parts.d.ts +71 -0
  45. package/dist/auth/login-form/parts.js +371 -0
  46. package/dist/auth/looks/auth-illustration-any.d.ts +16 -0
  47. package/dist/auth/looks/auth-illustration-any.js +24 -0
  48. package/dist/auth/looks/index.d.ts +1 -0
  49. package/dist/auth/looks/index.js +1 -0
  50. package/dist/auth/mosaic/index.d.ts +1 -0
  51. package/dist/auth/mosaic/index.js +1 -0
  52. package/dist/auth/mosaic/mosaic.d.ts +11 -0
  53. package/dist/auth/mosaic/mosaic.js +195 -0
  54. package/dist/auth/slabs/index.d.ts +1 -0
  55. package/dist/auth/slabs/index.js +1 -0
  56. package/dist/auth/slabs/slabs.d.ts +13 -0
  57. package/dist/auth/slabs/slabs.js +136 -0
  58. package/dist/auth/stack/index.d.ts +1 -0
  59. package/dist/auth/stack/index.js +1 -0
  60. package/dist/auth/stack/stack.d.ts +6 -0
  61. package/dist/auth/stack/stack.js +222 -0
  62. package/dist/auth/statement/index.d.ts +1 -0
  63. package/dist/auth/statement/index.js +1 -0
  64. package/dist/auth/statement/statement.d.ts +13 -0
  65. package/dist/auth/statement/statement.js +99 -0
  66. package/dist/forms/index.d.ts +1 -0
  67. package/dist/forms/index.js +1 -0
  68. package/dist/forms/input/input.js +2 -1
  69. package/dist/forms/password-input/index.d.ts +1 -0
  70. package/dist/forms/password-input/index.js +1 -0
  71. package/dist/forms/password-input/password-input.d.ts +16 -0
  72. package/dist/forms/password-input/password-input.js +45 -0
  73. package/dist/i18n/strings.d.ts +64 -0
  74. package/dist/i18n/strings.js +34 -2
  75. package/dist/icons/eye.d.ts +2 -0
  76. package/dist/icons/eye.js +11 -0
  77. package/dist/icons/graduation-cap.d.ts +2 -0
  78. package/dist/icons/graduation-cap.js +12 -0
  79. package/dist/icons/house.d.ts +2 -0
  80. package/dist/icons/house.js +11 -0
  81. package/dist/icons/index.d.ts +4 -0
  82. package/dist/icons/index.js +8 -0
  83. package/dist/icons/mail.d.ts +2 -0
  84. package/dist/icons/mail.js +11 -0
  85. package/icons/svg/eye.svg +4 -0
  86. package/icons/svg/graduation-cap.svg +5 -0
  87. package/icons/svg/house.svg +4 -0
  88. package/icons/svg/mail.svg +4 -0
  89. package/package.json +2 -2
  90. package/src/atoms/button/button.tsx +25 -3
  91. package/src/atoms/divider/divider.tsx +40 -0
  92. package/src/atoms/divider/index.ts +1 -0
  93. package/src/atoms/icon-button/icon-button.tsx +1 -1
  94. package/src/atoms/index.ts +1 -0
  95. package/src/auth/auth-illustration/auth-illustration.tsx +100 -0
  96. package/src/auth/auth-illustration/index.ts +8 -0
  97. package/src/auth/auth-illustration/look.ts +32 -0
  98. package/src/auth/auth-illustration/model.ts +330 -0
  99. package/src/auth/auth-illustration/use-art-pointer.ts +78 -0
  100. package/src/auth/auth-layout/auth-layout.tsx +282 -0
  101. package/src/auth/auth-layout/index.ts +1 -0
  102. package/src/auth/character/character.tsx +346 -0
  103. package/src/auth/character/index.ts +1 -0
  104. package/src/auth/index.ts +4 -0
  105. package/src/auth/internal/auth-context.ts +26 -0
  106. package/src/auth/internal/auth-styles.tsx +39 -0
  107. package/src/auth/internal/portal-glyphs.tsx +32 -0
  108. package/src/auth/login-form/context.ts +78 -0
  109. package/src/auth/login-form/index.ts +21 -0
  110. package/src/auth/login-form/login-form.tsx +330 -0
  111. package/src/auth/login-form/parts.tsx +457 -0
  112. package/src/auth/looks/auth-illustration-any.tsx +38 -0
  113. package/src/auth/looks/index.ts +1 -0
  114. package/src/auth/mosaic/index.ts +1 -0
  115. package/src/auth/mosaic/mosaic.tsx +255 -0
  116. package/src/auth/slabs/index.ts +1 -0
  117. package/src/auth/slabs/slabs.tsx +181 -0
  118. package/src/auth/stack/index.ts +1 -0
  119. package/src/auth/stack/stack.tsx +267 -0
  120. package/src/auth/statement/index.ts +1 -0
  121. package/src/auth/statement/statement.tsx +122 -0
  122. package/src/forms/index.ts +1 -0
  123. package/src/forms/input/input.tsx +2 -0
  124. package/src/forms/password-input/index.ts +1 -0
  125. package/src/forms/password-input/password-input.tsx +57 -0
  126. package/src/i18n/strings.ts +64 -0
  127. package/src/icons/eye.tsx +12 -0
  128. package/src/icons/graduation-cap.tsx +13 -0
  129. package/src/icons/house.tsx +12 -0
  130. package/src/icons/index.ts +4 -0
  131. package/src/icons/mail.tsx +12 -0
@@ -0,0 +1,233 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import {
4
+ useEffect,
5
+ useId,
6
+ useMemo,
7
+ useRef,
8
+ useState
9
+ } from "react";
10
+ import { useUiStrings } from "../../i18n/index.js";
11
+ import { cn } from "../../utils/cn.js";
12
+ import { useControllableState } from "../../utils/use-controllable-state.js";
13
+ import { formProgress } from "../auth-illustration/model.js";
14
+ import { useOptionalAuth } from "../internal/auth-context.js";
15
+ import {
16
+ LoginFormContext
17
+ } from "./context.js";
18
+ import {
19
+ LoginFormError,
20
+ LoginFormFooter,
21
+ LoginFormHeader,
22
+ LoginFormIdentifier,
23
+ LoginFormOptions,
24
+ LoginFormPassword,
25
+ LoginFormPortals,
26
+ LoginFormProviders,
27
+ LoginFormSubmit
28
+ } from "./parts.js";
29
+ const MAX_ILLUSTRATED_PORTALS = 3;
30
+ function LoginForm({
31
+ onSubmit,
32
+ portals = [],
33
+ portal: portalProp,
34
+ appearance: appearanceProp,
35
+ defaultPortal,
36
+ onPortalChange,
37
+ loading: loadingProp,
38
+ error: errorProp,
39
+ success: successProp,
40
+ children,
41
+ className,
42
+ classNames,
43
+ onFocus,
44
+ onBlur,
45
+ ...props
46
+ }) {
47
+ const strings = useUiStrings();
48
+ const auth = useOptionalAuth();
49
+ const baseId = useId();
50
+ const identifierRef = useRef(null);
51
+ const passwordRef = useRef(null);
52
+ const [identifier, setIdentifier] = useState("");
53
+ const [password, setPassword] = useState("");
54
+ const [remember, setRemember] = useState(false);
55
+ const [internal, setInternal] = useState({ loading: false, error: null, success: false, field: null });
56
+ const [portalValue, setPortalValue] = useControllableState({
57
+ prop: portalProp,
58
+ defaultProp: defaultPortal ?? portals[0]?.value ?? "",
59
+ onChange: onPortalChange
60
+ });
61
+ const appearance = appearanceProp ?? (auth?.panel === "solid" ? "open" : "card");
62
+ const loading = loadingProp ?? internal.loading;
63
+ const error = errorProp !== void 0 ? errorProp : internal.error;
64
+ const success = successProp ?? internal.success;
65
+ const portalIndex = Math.max(
66
+ 0,
67
+ portals.findIndex((option) => option.value === portalValue)
68
+ );
69
+ const portal = portals[portalIndex];
70
+ const invalidField = error ? internal.field ?? "password" : null;
71
+ const errorPlacement = error === null || error === void 0 || error === "" ? null : errorProp === void 0 && internal.fieldError ? "field" : "form";
72
+ const focusedField = useRef(null);
73
+ const leftOutcome = useRef(false);
74
+ const setAuthState = auth?.setState;
75
+ const setAuthProgress = auth?.setProgress;
76
+ const setAuthActive = auth?.setActiveIndex;
77
+ const progress = formProgress(identifier.length, password.length > 0);
78
+ useEffect(() => {
79
+ setAuthProgress?.(progress);
80
+ }, [progress, setAuthProgress]);
81
+ const hasPortal = portal !== void 0;
82
+ useEffect(() => {
83
+ if (hasPortal) setAuthActive?.(Math.min(portalIndex, MAX_ILLUSTRATED_PORTALS - 1));
84
+ }, [hasPortal, portalIndex, setAuthActive]);
85
+ useEffect(() => {
86
+ if (success) {
87
+ leftOutcome.current = true;
88
+ setAuthState?.("success");
89
+ } else if (error) {
90
+ leftOutcome.current = true;
91
+ setAuthState?.("error");
92
+ } else if (leftOutcome.current) {
93
+ leftOutcome.current = false;
94
+ const field = focusedField.current;
95
+ setAuthState?.(field === "identifier" ? "typing" : field || loading ? "password" : "idle");
96
+ }
97
+ }, [success, error, loading, setAuthState]);
98
+ const context = useMemo(
99
+ () => ({
100
+ ids: {
101
+ identifier: `${baseId}-identifier`,
102
+ password: `${baseId}-password`,
103
+ error: `${baseId}-error`,
104
+ fieldError: `${baseId}-field-error`,
105
+ portals: `${baseId}-portals`
106
+ },
107
+ portals,
108
+ portal,
109
+ setPortal: setPortalValue,
110
+ identifier,
111
+ password,
112
+ appearance,
113
+ remember,
114
+ setRemember,
115
+ loading,
116
+ error,
117
+ invalidField,
118
+ errorPlacement,
119
+ setValue: (field, value) => {
120
+ if (field === "identifier") setIdentifier(value);
121
+ else setPassword(value);
122
+ if (internal.error || internal.field) {
123
+ setInternal((current) => ({ ...current, error: null, field: null }));
124
+ }
125
+ setAuthState?.(field === "identifier" ? "typing" : "password");
126
+ },
127
+ identifierRef,
128
+ passwordRef,
129
+ classNames
130
+ }),
131
+ [
132
+ baseId,
133
+ portals,
134
+ portal,
135
+ setPortalValue,
136
+ identifier,
137
+ password,
138
+ appearance,
139
+ remember,
140
+ loading,
141
+ error,
142
+ invalidField,
143
+ errorPlacement,
144
+ internal.error,
145
+ internal.field,
146
+ classNames,
147
+ setAuthState
148
+ ]
149
+ );
150
+ const fieldOf = (target) => target === identifierRef.current ? "identifier" : target === passwordRef.current ? "password" : null;
151
+ const handleFocus = (event) => {
152
+ onFocus?.(event);
153
+ const field = fieldOf(event.target);
154
+ if (field) focusedField.current = field;
155
+ if (field && !loading && !success && !error) {
156
+ setAuthState?.(field === "identifier" ? "typing" : "password");
157
+ }
158
+ };
159
+ const handleBlur = (event) => {
160
+ onBlur?.(event);
161
+ if (!fieldOf(event.target)) return;
162
+ const next = event.relatedTarget;
163
+ const staying = next !== null && fieldOf(next) !== null;
164
+ if (!staying) focusedField.current = null;
165
+ if (!staying && !loading && !success && !error) setAuthState?.("idle");
166
+ };
167
+ const fail = (message, field, fieldError = false) => {
168
+ setInternal({ loading: false, error: message, success: false, field, fieldError });
169
+ (field === "identifier" ? identifierRef : passwordRef).current?.focus();
170
+ };
171
+ const handleSubmit = async (event) => {
172
+ event.preventDefault();
173
+ if (loading) return;
174
+ if (!identifier.trim()) return fail(strings.enterIdentifier, "identifier", true);
175
+ if (!password) return fail(strings.enterPassword, "password", true);
176
+ const values = {
177
+ identifier: identifier.trim(),
178
+ password,
179
+ portal: portal?.value,
180
+ remember
181
+ };
182
+ setInternal({ loading: true, error: null, success: false, field: null });
183
+ try {
184
+ await onSubmit?.(values);
185
+ setInternal({ loading: false, error: null, success: onSubmit !== void 0, field: null });
186
+ } catch (cause) {
187
+ fail(
188
+ cause instanceof Error && cause.message ? cause.message : strings.signInFailed,
189
+ "password"
190
+ );
191
+ }
192
+ };
193
+ return /* @__PURE__ */ jsx(LoginFormContext, { value: context, children: /* @__PURE__ */ jsx(
194
+ "form",
195
+ {
196
+ method: "post",
197
+ noValidate: true,
198
+ ...props,
199
+ "aria-busy": loading || void 0,
200
+ onFocus: handleFocus,
201
+ onBlur: handleBlur,
202
+ onSubmit: handleSubmit,
203
+ "data-appearance": appearance,
204
+ className: cn(
205
+ "grid",
206
+ appearance === "open" ? "mx-auto w-full max-w-110 gap-5" : "gap-3.5 px-7 pt-6.5 pb-5.5 @max-md/auth:px-1 @max-md/auth:pt-4",
207
+ appearance === "open" && auth?.panel === "paper" && "px-7 pt-7.5 pb-6",
208
+ classNames?.root,
209
+ className
210
+ ),
211
+ children: children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
212
+ /* @__PURE__ */ jsx(LoginFormHeader, {}),
213
+ /* @__PURE__ */ jsx(LoginFormPortals, {}),
214
+ /* @__PURE__ */ jsx(LoginFormError, {}),
215
+ /* @__PURE__ */ jsx(LoginFormIdentifier, {}),
216
+ /* @__PURE__ */ jsx(LoginFormPassword, {}),
217
+ /* @__PURE__ */ jsx(LoginFormSubmit, {})
218
+ ] })
219
+ }
220
+ ) });
221
+ }
222
+ LoginForm.Header = LoginFormHeader;
223
+ LoginForm.Portals = LoginFormPortals;
224
+ LoginForm.Identifier = LoginFormIdentifier;
225
+ LoginForm.Password = LoginFormPassword;
226
+ LoginForm.Options = LoginFormOptions;
227
+ LoginForm.Providers = LoginFormProviders;
228
+ LoginForm.Error = LoginFormError;
229
+ LoginForm.Submit = LoginFormSubmit;
230
+ LoginForm.Footer = LoginFormFooter;
231
+ export {
232
+ LoginForm
233
+ };
@@ -0,0 +1,71 @@
1
+ import type { ComponentPropsWithoutRef, ReactNode } from "react";
2
+ import { type ButtonProps } from "../../atoms/button/button.js";
3
+ import { Lock } from "../../icons/index.js";
4
+ export interface LoginFormHeaderProps extends Omit<ComponentPropsWithoutRef<"div">, "title"> {
5
+ /** Defaults to the localized "Sign in". */
6
+ title?: ReactNode;
7
+ /** Defaults to the description of the selected portal. */
8
+ description?: ReactNode;
9
+ /** Heading element of the title. Defaults to `h1`: the form is the point of the page. */
10
+ titleAs?: "h1" | "h2" | "h3";
11
+ }
12
+ export declare function LoginFormHeader({ title, description, titleAs: Title, className, ...props }: LoginFormHeaderProps): import("react").JSX.Element;
13
+ export interface LoginFormPortalsProps {
14
+ /** Visible heading of the picker. Defaults to the localized "Sign in as". */
15
+ label?: string;
16
+ className?: string;
17
+ }
18
+ /**
19
+ * Picker of the portal the person signs in through: a radio group of icon tiles with arrow-key
20
+ * navigation. Renders nothing when the form has fewer than two portals.
21
+ */
22
+ export declare function LoginFormPortals({ label, className }: LoginFormPortalsProps): import("react").JSX.Element | null;
23
+ export interface LoginFormFieldProps {
24
+ /** Visible label. The default design hides it visually and keeps it for assistive technology. */
25
+ label?: string;
26
+ placeholder?: string;
27
+ className?: string;
28
+ }
29
+ export declare function LoginFormIdentifier({ label, placeholder, className }: LoginFormFieldProps): import("react").JSX.Element;
30
+ export interface LoginFormPasswordProps extends LoginFormFieldProps {
31
+ /** Adds a "Forgot your password?" link to this address. */
32
+ forgotHref?: string;
33
+ /** Replaces the forgot link with any node (a router link, a button). */
34
+ forgot?: ReactNode;
35
+ }
36
+ export declare function LoginFormPassword({ label, placeholder, forgotHref, forgot, className, }: LoginFormPasswordProps): import("react").JSX.Element;
37
+ export interface LoginFormErrorProps extends Omit<ComponentPropsWithoutRef<"p">, "children"> {
38
+ }
39
+ /**
40
+ * Live region for errors about the sign-in itself (wrong credentials, a server message), shown as a
41
+ * callout with an alert icon; place it above the fields. A field left empty is reported under that
42
+ * field instead. It stays in the page while empty so the message is announced.
43
+ */
44
+ export declare function LoginFormError({ className, ...props }: LoginFormErrorProps): import("react").JSX.Element;
45
+ export interface LoginFormSubmitProps extends Omit<ButtonProps, "type" | "loading"> {
46
+ }
47
+ export declare function LoginFormSubmit({ children, className, ...props }: LoginFormSubmitProps): import("react").JSX.Element;
48
+ export interface LoginFormFooterProps extends ComponentPropsWithoutRef<"div"> {
49
+ }
50
+ /** Terms and privacy links under the form. In the card appearance it is a strip running edge to edge. */
51
+ export declare function LoginFormFooter({ className, ...props }: LoginFormFooterProps): import("react").JSX.Element;
52
+ export { Lock as LoginFormLockIcon };
53
+ export interface LoginFormOptionsProps extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
54
+ /** Label of the checkbox. Defaults to the localized "Remember me". */
55
+ rememberLabel?: string;
56
+ /** Help link or button at the end of the row. */
57
+ help?: ReactNode;
58
+ /** Adds the localized "Need help?" link to this address when `help` is not given. */
59
+ helpHref?: string;
60
+ }
61
+ /** Row under the fields with a remember-me checkbox (reported to `onSubmit` as `remember`) and a help slot. */
62
+ export declare function LoginFormOptions({ rememberLabel, help, helpHref, className, ...props }: LoginFormOptionsProps): import("react").JSX.Element;
63
+ export interface LoginFormProvidersProps extends ComponentPropsWithoutRef<"div"> {
64
+ /** Text on the divider above the providers. Defaults to the localized "Or log in with". */
65
+ label?: string;
66
+ }
67
+ /**
68
+ * Labelled slot for alternative ways to sign in. The library ships no providers: it renders only
69
+ * the children you pass (buttons, links) in a wrapping row, and nothing when there are none.
70
+ */
71
+ export declare function LoginFormProviders({ label, children, className, ...props }: LoginFormProvidersProps): import("react").JSX.Element | null;
@@ -0,0 +1,371 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { Button } from "../../atoms/button/button.js";
4
+ import { Checkbox } from "../../atoms/checkbox/checkbox.js";
5
+ import { Divider } from "../../atoms/divider/divider.js";
6
+ import { RadioGroupItem, RadioGroupRoot } from "../../atoms/radio-group/radio-group-primitive.js";
7
+ import { Spinner } from "../../atoms/spinner/spinner.js";
8
+ import { Field } from "../../forms/field/field.js";
9
+ import { Input } from "../../forms/input/input.js";
10
+ import { PasswordInput } from "../../forms/password-input/password-input.js";
11
+ import { useUiStrings } from "../../i18n/index.js";
12
+ import {
13
+ BookOpen,
14
+ Check,
15
+ CircleAlert,
16
+ GraduationCap,
17
+ House,
18
+ Lock,
19
+ Mail
20
+ } from "../../icons/index.js";
21
+ import { cn } from "../../utils/cn.js";
22
+ import {
23
+ useLoginForm
24
+ } from "./context.js";
25
+ const FALLBACK_ICONS = [
26
+ /* @__PURE__ */ jsx(BookOpen, {}, "book"),
27
+ /* @__PURE__ */ jsx(House, {}, "house"),
28
+ /* @__PURE__ */ jsx(GraduationCap, {}, "cap")
29
+ ];
30
+ function LoginFormHeader({
31
+ title,
32
+ description,
33
+ titleAs: Title = "h1",
34
+ className,
35
+ ...props
36
+ }) {
37
+ const strings = useUiStrings();
38
+ const { portal, appearance, classNames } = useLoginForm("Header");
39
+ const open = appearance === "open";
40
+ const text = description ?? portal?.description;
41
+ return /* @__PURE__ */ jsxs("div", { ...props, className: cn("grid gap-1.5", classNames?.header, className), children: [
42
+ /* @__PURE__ */ jsx(
43
+ Title,
44
+ {
45
+ className: cn(
46
+ "m-0 font-extrabold tracking-tight",
47
+ open ? "text-4xl" : "text-center text-3xl",
48
+ classNames?.title
49
+ ),
50
+ children: title ?? strings.signIn
51
+ }
52
+ ),
53
+ text ? /* @__PURE__ */ jsx(
54
+ "p",
55
+ {
56
+ className: cn(
57
+ "m-0 text-balance text-ink-3 text-control",
58
+ !open && "text-center",
59
+ classNames?.description
60
+ ),
61
+ children: text
62
+ }
63
+ ) : null
64
+ ] });
65
+ }
66
+ const PORTAL_TILE = "relative grid h-13 w-16 place-items-center rounded-input border-[1.5px] border-ink-3 bg-surface text-ink transition-[border-color,background-color,transform,box-shadow] duration-150 group-hover:-translate-y-0.5 group-focus-visible:-translate-y-0.5 group-data-[state=checked]:border-ink group-data-[state=checked]:bg-surface-2 group-data-[state=checked]:shadow-[0_2px_0_var(--ink)] [&>svg]:size-6";
67
+ const PORTAL_CHECK = "absolute top-1 right-1 grid size-4 scale-50 place-items-center rounded-full bg-ink text-surface opacity-0 transition-[opacity,scale] duration-150 group-data-[state=checked]:scale-100 group-data-[state=checked]:opacity-100 [&>svg]:size-3 [&>svg]:stroke-3";
68
+ function LoginFormPortals({ label, className }) {
69
+ const strings = useUiStrings();
70
+ const { portals, portal, setPortal, ids, appearance, classNames } = useLoginForm("Portals");
71
+ if (portals.length < 2) return null;
72
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-2.5", children: [
73
+ /* @__PURE__ */ jsx(
74
+ "div",
75
+ {
76
+ id: ids.portals,
77
+ className: cn(
78
+ "font-semibold text-ink text-control",
79
+ appearance === "card" && "text-center"
80
+ ),
81
+ children: label ?? strings.signInAs
82
+ }
83
+ ),
84
+ /* @__PURE__ */ jsx(
85
+ RadioGroupRoot,
86
+ {
87
+ "aria-labelledby": ids.portals,
88
+ value: portal?.value ?? "",
89
+ onValueChange: setPortal,
90
+ orientation: "horizontal",
91
+ className: cn("grid gap-2.5", classNames?.portals, className),
92
+ style: { gridTemplateColumns: `repeat(${portals.length}, minmax(0, 1fr))` },
93
+ children: portals.map((option, index) => /* @__PURE__ */ jsxs(
94
+ RadioGroupItem,
95
+ {
96
+ value: option.value,
97
+ className: cn(
98
+ "group grid cursor-pointer justify-items-center gap-1.5 rounded-input bg-transparent p-0 font-medium text-control text-ink focus-visible:focus-ring",
99
+ classNames?.portal
100
+ ),
101
+ children: [
102
+ /* @__PURE__ */ jsxs("span", { "aria-hidden": "true", className: PORTAL_TILE, children: [
103
+ option.icon ?? FALLBACK_ICONS[index],
104
+ /* @__PURE__ */ jsx("span", { "data-portal-check": "", className: PORTAL_CHECK, children: /* @__PURE__ */ jsx(Check, {}) })
105
+ ] }),
106
+ option.label
107
+ ]
108
+ },
109
+ option.value
110
+ ))
111
+ }
112
+ ),
113
+ /* @__PURE__ */ jsx(Divider, { className: "mt-1.5", children: strings.withYourAccount })
114
+ ] });
115
+ }
116
+ const fieldClasses = "[&_input]:text-fs-140";
117
+ const INVALID_INPUT = {
118
+ root: "focus-within:outline-danger has-[input[aria-invalid=true]]:border-2",
119
+ start: "text-danger"
120
+ };
121
+ function fieldErrorOf(field, { invalidField, errorPlacement, error, ids }) {
122
+ const invalid = invalidField === field;
123
+ const below = invalid && errorPlacement === "field" ? error : null;
124
+ return {
125
+ invalid,
126
+ below,
127
+ describedBy: invalid ? below ? ids.fieldError : ids.error : void 0
128
+ };
129
+ }
130
+ function FieldError({ id, children }) {
131
+ return /* @__PURE__ */ jsxs(
132
+ "p",
133
+ {
134
+ id,
135
+ role: "alert",
136
+ className: "m-0 flex items-center gap-1.5 font-semibold text-danger text-meta [&>svg]:size-3.5 [&>svg]:shrink-0",
137
+ children: [
138
+ /* @__PURE__ */ jsx(CircleAlert, { "aria-hidden": "true" }),
139
+ children
140
+ ]
141
+ }
142
+ );
143
+ }
144
+ function LoginFormIdentifier({ label, placeholder, className }) {
145
+ const strings = useUiStrings();
146
+ const form = useLoginForm("Identifier");
147
+ const { ids, portal, identifier, setValue, identifierRef, appearance, classNames } = form;
148
+ const { invalid, below, describedBy } = fieldErrorOf("identifier", form);
149
+ const hideLabel = appearance === "card";
150
+ const text = label ?? portal?.identifierLabel ?? strings.identifier;
151
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", "data-login-field": "identifier", children: [
152
+ /* @__PURE__ */ jsx(
153
+ Field,
154
+ {
155
+ label: text,
156
+ controlId: ids.identifier,
157
+ classNames: { label: hideLabel ? "sr-only" : "" },
158
+ className: cn(fieldClasses, classNames?.identifier, className),
159
+ children: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
160
+ Input,
161
+ {
162
+ ref: identifierRef,
163
+ id: ids.identifier,
164
+ name: "identifier",
165
+ size: "lg",
166
+ autoComplete: "username",
167
+ autoCapitalize: "none",
168
+ spellCheck: false,
169
+ placeholder: placeholder ?? (hideLabel ? text : void 0),
170
+ value: identifier,
171
+ onChange: (event) => setValue("identifier", event.currentTarget.value),
172
+ start: /* @__PURE__ */ jsx(Mail, {}),
173
+ classNames: invalid ? INVALID_INPUT : void 0,
174
+ "aria-invalid": invalid || void 0,
175
+ "aria-describedby": describedBy
176
+ }
177
+ ) })
178
+ }
179
+ ),
180
+ below ? /* @__PURE__ */ jsx(FieldError, { id: ids.fieldError, children: below }) : null
181
+ ] });
182
+ }
183
+ function LoginFormPassword({
184
+ label,
185
+ placeholder,
186
+ forgotHref,
187
+ forgot,
188
+ className
189
+ }) {
190
+ const strings = useUiStrings();
191
+ const form = useLoginForm("Password");
192
+ const { ids, password, setValue, passwordRef, appearance, classNames } = form;
193
+ const { invalid, below, describedBy } = fieldErrorOf("password", form);
194
+ const hideLabel = appearance === "card";
195
+ const text = label ?? strings.password;
196
+ const link = forgot ?? (forgotHref ? /* @__PURE__ */ jsx(
197
+ "a",
198
+ {
199
+ href: forgotHref,
200
+ className: "font-medium text-accent-ink text-control underline underline-offset-3 focus-visible:focus-ring",
201
+ children: strings.forgotPassword
202
+ }
203
+ ) : null);
204
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", "data-login-field": "password", children: [
205
+ /* @__PURE__ */ jsx(
206
+ Field,
207
+ {
208
+ label: text,
209
+ controlId: ids.password,
210
+ classNames: { label: hideLabel ? "sr-only" : "" },
211
+ className: cn(fieldClasses, classNames?.password, className),
212
+ children: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
213
+ PasswordInput,
214
+ {
215
+ ref: passwordRef,
216
+ id: ids.password,
217
+ name: "password",
218
+ size: "lg",
219
+ start: /* @__PURE__ */ jsx(Lock, {}),
220
+ placeholder: placeholder ?? (hideLabel ? text : void 0),
221
+ value: password,
222
+ onChange: (event) => setValue("password", event.currentTarget.value),
223
+ classNames: invalid ? INVALID_INPUT : void 0,
224
+ "aria-invalid": invalid || void 0,
225
+ "aria-describedby": describedBy
226
+ }
227
+ ) })
228
+ }
229
+ ),
230
+ below ? /* @__PURE__ */ jsx(FieldError, { id: ids.fieldError, children: below }) : null,
231
+ link ? /* @__PURE__ */ jsx("div", { className: "justify-self-end", children: link }) : null
232
+ ] });
233
+ }
234
+ function LoginFormError({ className, ...props }) {
235
+ const { ids, error, errorPlacement, classNames } = useLoginForm("Error");
236
+ const message = errorPlacement === "form" ? error : null;
237
+ return /* @__PURE__ */ jsx(
238
+ "p",
239
+ {
240
+ ...props,
241
+ id: ids.error,
242
+ role: "alert",
243
+ className: cn(
244
+ "m-0 empty:absolute",
245
+ message && "flex items-start gap-2 rounded-input bg-danger-soft px-3 py-2.5 font-semibold text-danger text-meta [&>svg]:mt-px [&>svg]:size-4 [&>svg]:shrink-0",
246
+ classNames?.error,
247
+ className
248
+ ),
249
+ children: message ? /* @__PURE__ */ jsxs(Fragment, { children: [
250
+ /* @__PURE__ */ jsx(CircleAlert, { "aria-hidden": "true" }),
251
+ message
252
+ ] }) : null
253
+ }
254
+ );
255
+ }
256
+ function LoginFormSubmit({ children, className, ...props }) {
257
+ const strings = useUiStrings();
258
+ const { loading, appearance, classNames } = useLoginForm("Submit");
259
+ return /* @__PURE__ */ jsxs(
260
+ Button,
261
+ {
262
+ variant: "primary",
263
+ size: "lg",
264
+ block: true,
265
+ ...props,
266
+ type: "submit",
267
+ loading,
268
+ className: cn(appearance === "open" && "rounded-pill", classNames?.submit, className),
269
+ children: [
270
+ loading ? /* @__PURE__ */ jsx(Spinner, { size: "sm", label: false }) : null,
271
+ children ?? strings.signInAction
272
+ ]
273
+ }
274
+ );
275
+ }
276
+ function LoginFormFooter({ className, ...props }) {
277
+ const { appearance, classNames } = useLoginForm("Footer");
278
+ return /* @__PURE__ */ jsx(
279
+ "div",
280
+ {
281
+ ...props,
282
+ className: cn(
283
+ "text-ink-3 text-meta [&_a]:text-inherit [&_a]:underline [&_a]:underline-offset-2",
284
+ appearance === "card" ? "-mx-7 -mb-5.5 mt-1 border-t-divider px-5 py-3.5 text-center @max-md/auth:-mx-1 @max-md/auth:px-1" : "text-center",
285
+ classNames?.footer,
286
+ className
287
+ )
288
+ }
289
+ );
290
+ }
291
+ function LoginFormOptions({
292
+ rememberLabel,
293
+ help,
294
+ helpHref,
295
+ className,
296
+ ...props
297
+ }) {
298
+ const strings = useUiStrings();
299
+ const { remember, setRemember, classNames } = useLoginForm("Options");
300
+ const link = help ?? (helpHref ? /* @__PURE__ */ jsx(
301
+ "a",
302
+ {
303
+ href: helpHref,
304
+ className: "font-medium text-accent-ink text-control underline underline-offset-3 focus-visible:focus-ring",
305
+ children: strings.needHelp
306
+ }
307
+ ) : null);
308
+ return /* @__PURE__ */ jsxs(
309
+ "div",
310
+ {
311
+ ...props,
312
+ className: cn(
313
+ "flex flex-wrap items-center justify-between gap-x-4 gap-y-2",
314
+ classNames?.options,
315
+ className
316
+ ),
317
+ children: [
318
+ /* @__PURE__ */ jsx(
319
+ Checkbox,
320
+ {
321
+ name: "remember",
322
+ checked: remember,
323
+ onCheckedChange: (checked) => setRemember(checked === true),
324
+ label: rememberLabel ?? strings.rememberMe,
325
+ classNames: { wrapper: "-ml-2.75" }
326
+ }
327
+ ),
328
+ link
329
+ ]
330
+ }
331
+ );
332
+ }
333
+ function LoginFormProviders({
334
+ label,
335
+ children,
336
+ className,
337
+ ...props
338
+ }) {
339
+ const strings = useUiStrings();
340
+ const { classNames } = useLoginForm("Providers");
341
+ if (children === void 0 || children === null || children === false) return null;
342
+ const text = label ?? strings.orLogInWith;
343
+ return (
344
+ // biome-ignore lint/a11y/useSemanticElements: a fieldset would add a legend and form-disabling behaviour the slot does not want
345
+ /* @__PURE__ */ jsxs(
346
+ "div",
347
+ {
348
+ ...props,
349
+ role: "group",
350
+ "aria-label": text,
351
+ className: cn("grid gap-3", classNames?.providers, className),
352
+ children: [
353
+ /* @__PURE__ */ jsx(Divider, { children: text }),
354
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center justify-center gap-2.5", children })
355
+ ]
356
+ }
357
+ )
358
+ );
359
+ }
360
+ export {
361
+ LoginFormError,
362
+ LoginFormFooter,
363
+ LoginFormHeader,
364
+ LoginFormIdentifier,
365
+ Lock as LoginFormLockIcon,
366
+ LoginFormOptions,
367
+ LoginFormPassword,
368
+ LoginFormPortals,
369
+ LoginFormProviders,
370
+ LoginFormSubmit
371
+ };
@@ -0,0 +1,16 @@
1
+ import { type AuthIllustrationProps } from "../auth-illustration/auth-illustration.js";
2
+ import type { AuthLook } from "../auth-illustration/look.js";
3
+ export type AuthIllustrationVariant = "slabs" | "stack" | "mosaic" | "character" | "statement";
4
+ /** The five looks by name. Importing this module keeps all of them in the bundle. */
5
+ export declare const AUTH_LOOKS: Readonly<Record<AuthIllustrationVariant, AuthLook>>;
6
+ export interface AuthIllustrationAnyProps extends Omit<AuthIllustrationProps, "look"> {
7
+ /** The look by name. Defaults to `slabs`. */
8
+ variant?: AuthIllustrationVariant;
9
+ }
10
+ /**
11
+ * `AuthIllustration` with the look chosen by a string. It imports all five looks on purpose, so an
12
+ * app that renders it pays for every look in its bundle (about 2 to 3 KB gzip each). Apps that use
13
+ * one look should pass it to `AuthIllustration` from its own entry, for example
14
+ * `@jcsoftdev/ui/auth/stack`.
15
+ */
16
+ export declare function AuthIllustrationAny({ variant, ...props }: AuthIllustrationAnyProps): import("react").JSX.Element;