@tomny-dev/uzi 0.14.0 → 0.15.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 (130) hide show
  1. package/dist/components/filter-workspace/FilterWorkspace.d.ts +40 -0
  2. package/dist/components/filter-workspace/FilterWorkspace.d.ts.map +1 -0
  3. package/dist/components/filter-workspace/FilterWorkspace.test.d.ts +2 -0
  4. package/dist/components/filter-workspace/FilterWorkspace.test.d.ts.map +1 -0
  5. package/dist/index.cjs +18 -14
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +16 -15
  9. package/dist/index57.js +21 -10
  10. package/dist/index57.js.map +1 -1
  11. package/dist/index58.cjs +30 -11
  12. package/dist/index58.cjs.map +1 -1
  13. package/dist/index58.js +101 -14
  14. package/dist/index58.js.map +1 -1
  15. package/dist/index59.cjs +104 -13
  16. package/dist/index59.cjs.map +1 -1
  17. package/dist/index59.js +10 -11
  18. package/dist/index59.js.map +1 -1
  19. package/dist/index60.cjs +11 -13
  20. package/dist/index60.cjs.map +1 -1
  21. package/dist/index60.js +13 -16
  22. package/dist/index60.js.map +1 -1
  23. package/dist/index61.cjs +13 -16
  24. package/dist/index61.cjs.map +1 -1
  25. package/dist/index61.js +10 -8
  26. package/dist/index61.js.map +1 -1
  27. package/dist/index62.cjs +11 -10
  28. package/dist/index62.cjs.map +1 -1
  29. package/dist/index62.js +15 -87
  30. package/dist/index62.js.map +1 -1
  31. package/dist/index63.cjs +15 -89
  32. package/dist/index63.cjs.map +1 -1
  33. package/dist/index63.js +9 -23
  34. package/dist/index63.js.map +1 -1
  35. package/dist/index64.cjs +12 -33
  36. package/dist/index64.cjs.map +1 -1
  37. package/dist/index64.js +89 -43
  38. package/dist/index64.js.map +1 -1
  39. package/dist/index65.cjs +88 -42
  40. package/dist/index65.cjs.map +1 -1
  41. package/dist/index65.js +23 -15
  42. package/dist/index65.js.map +1 -1
  43. package/dist/index66.cjs +33 -21
  44. package/dist/index66.cjs.map +1 -1
  45. package/dist/index66.js +44 -51
  46. package/dist/index66.js.map +1 -1
  47. package/dist/index67.cjs +43 -52
  48. package/dist/index67.cjs.map +1 -1
  49. package/dist/index67.js +14 -14
  50. package/dist/index67.js.map +1 -1
  51. package/dist/index68.cjs +19 -19
  52. package/dist/index68.cjs.map +1 -1
  53. package/dist/index68.js +49 -290
  54. package/dist/index68.js.map +1 -1
  55. package/dist/index69.cjs +51 -290
  56. package/dist/index69.cjs.map +1 -1
  57. package/dist/index69.js +15 -57
  58. package/dist/index69.js.map +1 -1
  59. package/dist/index70.cjs +20 -83
  60. package/dist/index70.cjs.map +1 -1
  61. package/dist/index70.js +276 -418
  62. package/dist/index70.js.map +1 -1
  63. package/dist/index71.cjs +275 -419
  64. package/dist/index71.cjs.map +1 -1
  65. package/dist/index71.js +56 -58
  66. package/dist/index71.js.map +1 -1
  67. package/dist/index72.cjs +82 -85
  68. package/dist/index72.cjs.map +1 -1
  69. package/dist/index72.js +420 -226
  70. package/dist/index72.js.map +1 -1
  71. package/dist/index73.cjs +421 -225
  72. package/dist/index73.cjs.map +1 -1
  73. package/dist/index73.js +58 -42
  74. package/dist/index73.js.map +1 -1
  75. package/dist/index74.cjs +85 -61
  76. package/dist/index74.cjs.map +1 -1
  77. package/dist/index74.js +236 -76
  78. package/dist/index74.js.map +1 -1
  79. package/dist/index75.cjs +235 -75
  80. package/dist/index75.cjs.map +1 -1
  81. package/dist/index75.js +42 -20
  82. package/dist/index75.js.map +1 -1
  83. package/dist/index76.cjs +60 -27
  84. package/dist/index76.cjs.map +1 -1
  85. package/dist/index76.js +73 -88
  86. package/dist/index76.js.map +1 -1
  87. package/dist/index77.cjs +73 -90
  88. package/dist/index77.cjs.map +1 -1
  89. package/dist/index77.js +17 -15
  90. package/dist/index77.js.map +1 -1
  91. package/dist/index78.cjs +22 -19
  92. package/dist/index78.cjs.map +1 -1
  93. package/dist/index78.js +85 -143
  94. package/dist/index78.js.map +1 -1
  95. package/dist/index79.cjs +87 -143
  96. package/dist/index79.cjs.map +1 -1
  97. package/dist/index79.js +19 -91
  98. package/dist/index79.js.map +1 -1
  99. package/dist/index80.cjs +27 -135
  100. package/dist/index80.cjs.map +1 -1
  101. package/dist/index80.js +140 -673
  102. package/dist/index80.js.map +1 -1
  103. package/dist/index81.cjs +140 -673
  104. package/dist/index81.cjs.map +1 -1
  105. package/dist/index81.js +91 -31
  106. package/dist/index81.js.map +1 -1
  107. package/dist/index82.cjs +135 -45
  108. package/dist/index82.cjs.map +1 -1
  109. package/dist/index82.js +667 -206
  110. package/dist/index82.js.map +1 -1
  111. package/dist/index83.cjs +667 -204
  112. package/dist/index83.cjs.map +1 -1
  113. package/dist/index83.js +31 -15
  114. package/dist/index83.js.map +1 -1
  115. package/dist/index84.cjs +45 -21
  116. package/dist/index84.cjs.map +1 -1
  117. package/dist/index84.js +224 -29
  118. package/dist/index84.js.map +1 -1
  119. package/dist/index85.cjs +224 -30
  120. package/dist/index85.cjs.map +1 -1
  121. package/dist/index85.js +19 -0
  122. package/dist/index85.js.map +1 -0
  123. package/dist/index86.cjs +25 -0
  124. package/dist/index86.cjs.map +1 -0
  125. package/dist/index86.js +36 -0
  126. package/dist/index86.js.map +1 -0
  127. package/dist/index87.cjs +37 -0
  128. package/dist/index87.cjs.map +1 -0
  129. package/dist/style.css +53 -0
  130. package/package.json +1 -1
package/dist/index70.js CHANGED
@@ -1,440 +1,298 @@
1
- import { cx } from "./index3.js";
2
- import auth_pages_module_default from "./index69.js";
1
+ import { Button } from "./index5.js";
2
+ import { Input } from "./index21.js";
3
+ import { AuthCard } from "./index66.js";
4
+ import { AuthField, AuthForm, AuthModeSwitch } from "./index68.js";
5
+ import auth_page_module_default from "./index69.js";
3
6
  import * as React from "react";
4
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
- //#region src/components/auth-pages/AuthPages.tsx
6
- function EyeIcon({ open }) {
7
- if (open) return /* @__PURE__ */ jsxs("svg", {
8
- viewBox: "0 0 24 24",
9
- fill: "none",
10
- "aria-hidden": "true",
11
- className: auth_pages_module_default.eyeIcon,
12
- children: [/* @__PURE__ */ jsx("path", {
13
- d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z",
14
- stroke: "currentColor",
15
- strokeWidth: "2"
16
- }), /* @__PURE__ */ jsx("circle", {
17
- cx: "12",
18
- cy: "12",
19
- r: "3",
20
- stroke: "currentColor",
21
- strokeWidth: "2"
22
- })]
23
- });
24
- return /* @__PURE__ */ jsxs("svg", {
25
- viewBox: "0 0 24 24",
26
- fill: "none",
27
- "aria-hidden": "true",
28
- className: auth_pages_module_default.eyeIcon,
29
- children: [
30
- /* @__PURE__ */ jsx("path", {
31
- d: "M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94",
32
- stroke: "currentColor",
33
- strokeWidth: "2"
34
- }),
35
- /* @__PURE__ */ jsx("path", {
36
- d: "M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19",
37
- stroke: "currentColor",
38
- strokeWidth: "2"
39
- }),
40
- /* @__PURE__ */ jsx("line", {
41
- x1: "1",
42
- y1: "1",
43
- x2: "23",
44
- y2: "23",
45
- stroke: "currentColor",
46
- strokeWidth: "2"
47
- })
48
- ]
49
- });
50
- }
51
- function Field({ label, id, children, error }) {
52
- return /* @__PURE__ */ jsxs("div", {
53
- className: auth_pages_module_default.field,
54
- children: [
55
- /* @__PURE__ */ jsx("label", {
56
- htmlFor: id,
57
- className: auth_pages_module_default.label,
58
- children: label
59
- }),
60
- children,
61
- error && /* @__PURE__ */ jsx("span", {
62
- className: auth_pages_module_default.error,
63
- children: error
64
- })
65
- ]
66
- });
67
- }
68
- function PasswordField({ id, label, placeholder, value, onChange, error }) {
69
- const [show, setShow] = React.useState(false);
70
- const toggleRef = React.useRef(null);
71
- return /* @__PURE__ */ jsx(Field, {
72
- label: label ?? "Password",
73
- id,
74
- error,
75
- children: /* @__PURE__ */ jsxs("div", {
76
- className: auth_pages_module_default.passwordWrapper,
77
- children: [/* @__PURE__ */ jsx("input", {
78
- id,
79
- type: show ? "text" : "password",
80
- placeholder,
81
- value,
82
- onChange,
83
- className: auth_pages_module_default.input,
84
- autoComplete: "current-password"
85
- }), /* @__PURE__ */ jsx("button", {
86
- ref: toggleRef,
87
- type: "button",
88
- onClick: () => setShow((s) => !s),
89
- className: auth_pages_module_default.toggle,
90
- "aria-label": show ? "Hide password" : "Show password",
91
- children: /* @__PURE__ */ jsx(EyeIcon, { open: show })
92
- })]
93
- })
94
- });
95
- }
96
- function CheckboxRow({ label, linkText, linkHref, checked, onChange }) {
97
- if (!label) return null;
98
- return /* @__PURE__ */ jsxs("div", {
99
- className: auth_pages_module_default.checkboxRow,
100
- children: [/* @__PURE__ */ jsxs("label", {
101
- className: auth_pages_module_default.checkboxLabel,
102
- children: [/* @__PURE__ */ jsx("input", {
103
- type: "checkbox",
104
- className: auth_pages_module_default.checkbox,
105
- checked,
106
- onChange: (e) => onChange?.(e.target.checked)
107
- }), /* @__PURE__ */ jsx("span", { children: label })]
108
- }), linkHref && /* @__PURE__ */ jsx("a", {
109
- href: linkHref,
110
- className: auth_pages_module_default.forgotLink,
111
- children: linkText
112
- })]
113
- });
114
- }
115
- function SignInPage({ title = "Sign in", subtitle, footer, onSubmit, loading = false, brand, className, emailPlaceholder = "Email address", passwordPlaceholder = "Password", rememberLabel = "Remember me", forgotLinkText = "Forgot password?", forgotLinkHref }) {
116
- const id = React.useId();
117
- const [email, setEmail] = React.useState("");
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/components/auth-page/AuthPage.tsx
9
+ /**
10
+ * Complete app-neutral authentication UX. Uzi owns UI state and validation;
11
+ * the consuming application owns credentials, sessions, API calls and redirects.
12
+ */
13
+ function AuthPage({ brand, signInTitle = "Welcome back", signUpTitle = "Create your account", signInSubtitle, signUpSubtitle, signInIdentifier, signUpFields = [], requirePasswordConfirmation = true, initialError, footer, minSignInPasswordLength = 0, passwordMaxLength, defaultMode = "signin", mode: controlledMode, onModeChange, onSignIn, onSignUp, onError, initialEmail = "", disabled = false, minPasswordLength = 8, signUpOptions, forgotPasswordHref, className, layout = "fullscreen" }) {
14
+ const [internalMode, setInternalMode] = React.useState(defaultMode);
15
+ const mode = controlledMode ?? internalMode;
16
+ const [email, setEmail] = React.useState(initialEmail);
118
17
  const [password, setPassword] = React.useState("");
119
- const [rememberMe, setRememberMe] = React.useState(false);
18
+ const [confirmPasswordValue, setConfirmPassword] = React.useState("");
19
+ const [extraValues, setExtraValues] = React.useState({});
20
+ const [acceptedTerms, setAcceptedTerms] = React.useState(false);
21
+ const [showPassword, setShowPassword] = React.useState(false);
22
+ const [pending, setPending] = React.useState(false);
23
+ const pendingRef = React.useRef(false);
120
24
  const [errors, setErrors] = React.useState({});
121
- const [submitted, setSubmitted] = React.useState(false);
122
- const validate = () => {
123
- const newErrors = {};
124
- if (!email.trim()) newErrors.email = "Email is required";
125
- else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) newErrors.email = "Enter a valid email";
126
- if (!password) newErrors.password = "Password is required";
127
- setErrors(newErrors);
128
- return Object.keys(newErrors).length === 0;
129
- };
130
- const handleSubmit = (e) => {
131
- e.preventDefault();
132
- setSubmitted(true);
133
- if (!validate()) return;
134
- onSubmit?.({
135
- email,
136
- password,
137
- rememberMe
25
+ const [serverError, setServerError] = React.useState(initialError ?? "");
26
+ const id = React.useId();
27
+ const emailId = id + "-email";
28
+ const passwordId = id + "-password";
29
+ const confirmId = id + "-confirm";
30
+ const termsId = id + "-terms";
31
+ const signup = mode === "signup";
32
+ const identifierIsEmail = signup || (signInIdentifier?.type ?? "email") === "email";
33
+ const termsRequired = signup && !!signUpOptions?.requireTerms;
34
+ const canSwitch = !!onModeChange || !!onSignIn && !!onSignUp;
35
+ const fieldNames = signUpFields.map((field) => field.name).join("\\u0000");
36
+ React.useEffect(() => {
37
+ const activeNames = new Set(fieldNames.split("\\u0000").filter(Boolean));
38
+ setExtraValues((previous) => {
39
+ if (Object.keys(previous).every((name) => activeNames.has(name))) return previous;
40
+ return Object.fromEntries(Object.entries(previous).filter(([name]) => activeNames.has(name)));
138
41
  });
42
+ }, [fieldNames]);
43
+ React.useEffect(() => {
44
+ setServerError(initialError ?? "");
45
+ }, [initialError]);
46
+ React.useEffect(() => {
47
+ if (initialEmail) setEmail((previous) => previous || initialEmail);
48
+ }, [initialEmail]);
49
+ const switchMode = (next) => {
50
+ if (pendingRef.current || next === mode) return;
51
+ setInternalMode(next);
52
+ setPassword("");
53
+ setConfirmPassword("");
54
+ setShowPassword(false);
55
+ setErrors({});
56
+ setServerError("");
57
+ onModeChange?.(next);
58
+ };
59
+ const submit = async (event) => {
60
+ event.preventDefault();
61
+ if (pendingRef.current || disabled) return;
62
+ const nextErrors = {};
63
+ const normalizedEmail = email.trim();
64
+ if (!normalizedEmail) nextErrors.email = (signup ? "Email" : signInIdentifier?.label ?? "Email") + " is required";
65
+ else if (identifierIsEmail && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalizedEmail)) nextErrors.email = "Enter a valid email address";
66
+ if (!signup && signInIdentifier?.maxLength && normalizedEmail.length > signInIdentifier.maxLength) nextErrors.email = "Identifier is too long";
67
+ if (!password) nextErrors.password = "Password is required";
68
+ else if (signup && password.length < minPasswordLength) nextErrors.password = `Use at least ${minPasswordLength} characters`;
69
+ if (signup && requirePasswordConfirmation && password !== confirmPasswordValue) nextErrors.confirm = "Passwords do not match";
70
+ if (!signup && minSignInPasswordLength && password.length < minSignInPasswordLength) nextErrors.password = `Use at least ${minSignInPasswordLength} characters`;
71
+ if (passwordMaxLength && password.length > passwordMaxLength) nextErrors.password = "Password is too long";
72
+ if (signup) for (const field of signUpFields) {
73
+ const value = (extraValues[field.name] ?? "").trim();
74
+ if (field.required && !value) nextErrors[field.name] = field.label + " is required";
75
+ else if (value && field.minLength && value.length < field.minLength) nextErrors[field.name] = field.label + " is too short";
76
+ else if (field.maxLength && value.length > field.maxLength) nextErrors[field.name] = field.label + " is too long";
77
+ else if (field.type === "email" && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) nextErrors[field.name] = "Enter a valid email address";
78
+ }
79
+ if (termsRequired && !acceptedTerms) nextErrors.terms = "Accept the terms to continue";
80
+ setErrors(nextErrors);
81
+ setServerError("");
82
+ if (Object.keys(nextErrors).length) return;
83
+ pendingRef.current = true;
84
+ setPending(true);
85
+ try {
86
+ const credentials = {
87
+ email: normalizedEmail,
88
+ password
89
+ };
90
+ if (!signup && signInIdentifier) credentials.identifier = normalizedEmail;
91
+ if (signup && signUpFields.length) credentials.fields = Object.fromEntries(signUpFields.map((field) => [field.name, (extraValues[field.name] ?? "").trim()]));
92
+ if (signup) {
93
+ if (!onSignUp) return;
94
+ await onSignUp(credentials);
95
+ } else {
96
+ if (!onSignIn) return;
97
+ await onSignIn(credentials);
98
+ }
99
+ setPassword("");
100
+ setConfirmPassword("");
101
+ setExtraValues({});
102
+ } catch (error) {
103
+ setServerError(error instanceof Error && error.message ? error.message : "Unable to complete the request. Try again.");
104
+ onError?.(error, mode);
105
+ } finally {
106
+ pendingRef.current = false;
107
+ setPending(false);
108
+ }
139
109
  };
140
- return /* @__PURE__ */ jsx("div", {
141
- className: cx(auth_pages_module_default.authLayout, className),
142
- children: /* @__PURE__ */ jsxs("div", {
143
- className: auth_pages_module_default.authCard,
110
+ return /* @__PURE__ */ jsxs(AuthCard, {
111
+ className,
112
+ layout,
113
+ brand,
114
+ title: signup ? signUpTitle : signInTitle,
115
+ subtitle: signup ? signUpSubtitle : signInSubtitle,
116
+ footer,
117
+ children: [canSwitch && /* @__PURE__ */ jsx(AuthModeSwitch, {
118
+ mode,
119
+ onModeChange: switchMode
120
+ }), /* @__PURE__ */ jsxs(AuthForm, {
121
+ onSubmit: submit,
122
+ noValidate: true,
123
+ "aria-busy": pending,
144
124
  children: [
145
- brand && /* @__PURE__ */ jsx("div", {
146
- className: auth_pages_module_default.authBrand,
147
- children: brand
148
- }),
149
- /* @__PURE__ */ jsxs("div", {
150
- className: auth_pages_module_default.authHeader,
151
- children: [/* @__PURE__ */ jsx("h1", {
152
- className: auth_pages_module_default.authTitle,
153
- children: title
154
- }), subtitle && /* @__PURE__ */ jsx("p", {
155
- className: auth_pages_module_default.authSubtitle,
156
- children: subtitle
157
- })]
125
+ /* @__PURE__ */ jsx(AuthField, {
126
+ htmlFor: emailId,
127
+ label: signup ? "Email" : signInIdentifier?.label ?? "Email",
128
+ error: errors.email,
129
+ children: /* @__PURE__ */ jsx(Input, {
130
+ id: emailId,
131
+ type: signup ? "email" : signInIdentifier?.type ?? "email",
132
+ placeholder: signup ? "you@example.com" : signInIdentifier?.placeholder ?? "you@example.com",
133
+ value: email,
134
+ autoComplete: signup ? "email" : signInIdentifier?.autoComplete ?? "email",
135
+ maxLength: signup ? 254 : signInIdentifier?.maxLength,
136
+ required: true,
137
+ disabled: disabled || pending,
138
+ "aria-invalid": !!errors.email,
139
+ "aria-describedby": errors.email ? emailId + "-error" : void 0,
140
+ onChange: (event) => {
141
+ setEmail(event.target.value);
142
+ setErrors((old) => ({
143
+ ...old,
144
+ email: ""
145
+ }));
146
+ }
147
+ })
158
148
  }),
159
- /* @__PURE__ */ jsxs("form", {
160
- onSubmit: handleSubmit,
161
- className: auth_pages_module_default.authForm,
162
- children: [
163
- /* @__PURE__ */ jsx(Field, {
164
- label: emailPlaceholder,
165
- id: id + "-email",
166
- error: submitted ? errors.email : void 0,
167
- children: /* @__PURE__ */ jsx("input", {
168
- id: id + "-email",
169
- type: "email",
170
- placeholder: "you@example.com",
171
- value: email,
172
- onChange: (e) => setEmail(e.target.value),
173
- className: auth_pages_module_default.input,
174
- autoComplete: "email",
175
- autoFocus: true
176
- })
177
- }),
178
- /* @__PURE__ */ jsx(PasswordField, {
179
- label: passwordPlaceholder,
180
- id: id + "-password",
181
- placeholder: passwordPlaceholder,
149
+ /* @__PURE__ */ jsx(AuthField, {
150
+ htmlFor: passwordId,
151
+ label: "Password",
152
+ error: errors.password,
153
+ children: /* @__PURE__ */ jsxs("div", {
154
+ className: auth_page_module_default.passwordRow,
155
+ children: [/* @__PURE__ */ jsx(Input, {
156
+ id: passwordId,
157
+ type: showPassword ? "text" : "password",
158
+ placeholder: signup ? "At least " + minPasswordLength + " characters" : "Enter your password",
182
159
  value: password,
183
- onChange: (e) => {
184
- setPassword(e.target.value);
185
- if (submitted) setSubmitted(false);
186
- },
187
- error: submitted ? errors.password : void 0
188
- }),
189
- /* @__PURE__ */ jsx(CheckboxRow, {
190
- label: rememberLabel,
191
- linkText: forgotLinkText,
192
- linkHref: forgotLinkHref,
193
- checked: rememberMe,
194
- onChange: (c) => {
195
- setRememberMe(c);
196
- if (submitted) setSubmitted(false);
160
+ required: true,
161
+ maxLength: passwordMaxLength,
162
+ disabled: disabled || pending,
163
+ autoComplete: signup ? "new-password" : "current-password",
164
+ "aria-invalid": !!errors.password,
165
+ "aria-describedby": errors.password ? passwordId + "-error" : void 0,
166
+ onChange: (event) => {
167
+ setPassword(event.target.value);
168
+ setErrors((old) => ({
169
+ ...old,
170
+ password: ""
171
+ }));
197
172
  }
198
- }),
199
- /* @__PURE__ */ jsx("button", {
200
- type: "submit",
201
- disabled: loading,
202
- className: auth_pages_module_default.submitButton,
203
- children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", { className: auth_pages_module_default.spinner }), "Signing in..."] }) : "Sign in"
204
- })
205
- ]
206
- }),
207
- footer && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("hr", { className: auth_pages_module_default.divider }), /* @__PURE__ */ jsx("p", {
208
- className: auth_pages_module_default.authFooter,
209
- children: footer
210
- })] })
211
- ]
212
- })
213
- });
214
- }
215
- function SignUpPage({ title = "Create an account", subtitle, footer, onSubmit, loading = false, brand, className, emailPlaceholder = "Email address", passwordPlaceholder = "Password", confirmPasswordPlaceholder = "Confirm password", checkboxLabel, checkboxLinkText, checkboxLinkHref }) {
216
- const id = React.useId();
217
- const [email, setEmail] = React.useState("");
218
- const [password, setPassword] = React.useState("");
219
- const [confirmPassword, setConfirmPassword] = React.useState("");
220
- const [agreed, setAgreed] = React.useState(false);
221
- const [errors, setErrors] = React.useState({});
222
- const [submitted, setSubmitted] = React.useState(false);
223
- const validate = () => {
224
- const newErrors = {};
225
- if (!email.trim()) newErrors.email = "Email is required";
226
- else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) newErrors.email = "Enter a valid email";
227
- if (!password) newErrors.password = "Password is required";
228
- else if (password.length < 8) newErrors.password = "At least 8 characters";
229
- if (password !== confirmPassword) newErrors.confirmPassword = "Passwords do not match";
230
- if (checkboxLabel && !agreed) newErrors.agreed = "You must agree to continue";
231
- setErrors(newErrors);
232
- return Object.keys(newErrors).length === 0;
233
- };
234
- const handleSubmit = (e) => {
235
- e.preventDefault();
236
- setSubmitted(true);
237
- if (!validate()) return;
238
- onSubmit?.({
239
- email,
240
- password,
241
- agreed
242
- });
243
- };
244
- return /* @__PURE__ */ jsx("div", {
245
- className: cx(auth_pages_module_default.authLayout, className),
246
- children: /* @__PURE__ */ jsxs("div", {
247
- className: auth_pages_module_default.authCard,
248
- children: [
249
- brand && /* @__PURE__ */ jsx("div", {
250
- className: auth_pages_module_default.authBrand,
251
- children: brand
173
+ }), /* @__PURE__ */ jsx("button", {
174
+ type: "button",
175
+ className: auth_page_module_default.visibility,
176
+ disabled: disabled || pending,
177
+ "aria-label": showPassword ? "Hide password" : "Show password",
178
+ "aria-controls": passwordId,
179
+ "aria-pressed": showPassword,
180
+ onClick: () => setShowPassword((old) => !old),
181
+ children: showPassword ? "Hide" : "Show"
182
+ })]
183
+ })
252
184
  }),
253
- /* @__PURE__ */ jsxs("div", {
254
- className: auth_pages_module_default.authHeader,
255
- children: [/* @__PURE__ */ jsx("h1", {
256
- className: auth_pages_module_default.authTitle,
257
- children: title
258
- }), subtitle && /* @__PURE__ */ jsx("p", {
259
- className: auth_pages_module_default.authSubtitle,
260
- children: subtitle
261
- })]
185
+ signup && requirePasswordConfirmation && /* @__PURE__ */ jsx(AuthField, {
186
+ htmlFor: confirmId,
187
+ label: "Confirm password",
188
+ error: errors.confirm,
189
+ children: /* @__PURE__ */ jsx(Input, {
190
+ id: confirmId,
191
+ type: "password",
192
+ placeholder: "Re-enter password",
193
+ value: confirmPasswordValue,
194
+ autoComplete: "new-password",
195
+ required: true,
196
+ disabled: disabled || pending,
197
+ "aria-invalid": !!errors.confirm,
198
+ "aria-describedby": errors.confirm ? confirmId + "-error" : void 0,
199
+ onChange: (event) => {
200
+ setConfirmPassword(event.target.value);
201
+ setErrors((old) => ({
202
+ ...old,
203
+ confirm: ""
204
+ }));
205
+ }
206
+ })
262
207
  }),
263
- /* @__PURE__ */ jsxs("form", {
264
- onSubmit: handleSubmit,
265
- className: auth_pages_module_default.authForm,
266
- children: [
267
- /* @__PURE__ */ jsx(Field, {
268
- label: emailPlaceholder,
269
- id: id + "-email",
270
- error: submitted ? errors.email : void 0,
271
- children: /* @__PURE__ */ jsx("input", {
272
- id: id + "-email",
273
- type: "email",
274
- placeholder: "you@example.com",
275
- value: email,
276
- onChange: (e) => {
277
- setEmail(e.target.value);
278
- if (submitted) setSubmitted(false);
279
- },
280
- className: auth_pages_module_default.input,
281
- autoComplete: "email",
282
- autoFocus: true
283
- })
284
- }),
285
- /* @__PURE__ */ jsx(PasswordField, {
286
- label: passwordPlaceholder,
287
- id: id + "-password",
288
- placeholder: passwordPlaceholder,
289
- value: password,
290
- onChange: (e) => {
291
- setPassword(e.target.value);
292
- if (submitted) setSubmitted(false);
293
- },
294
- error: submitted ? errors.password : void 0
295
- }),
296
- /* @__PURE__ */ jsx(PasswordField, {
297
- label: confirmPasswordPlaceholder,
298
- id: id + "-confirm",
299
- placeholder: confirmPasswordPlaceholder,
300
- value: confirmPassword,
301
- onChange: (e) => {
302
- setConfirmPassword(e.target.value);
303
- if (submitted) setSubmitted(false);
304
- },
305
- error: submitted ? errors.confirmPassword : void 0
306
- }),
307
- checkboxLabel && /* @__PURE__ */ jsx("div", {
308
- className: auth_pages_module_default.checkboxRow,
309
- children: /* @__PURE__ */ jsxs("label", {
310
- className: auth_pages_module_default.checkboxLabel,
311
- children: [/* @__PURE__ */ jsx("input", {
312
- id: id + "-agreed",
313
- type: "checkbox",
314
- checked: agreed,
315
- onChange: (e) => {
316
- setAgreed(e.target.checked);
317
- if (submitted) setSubmitted(false);
318
- },
319
- className: auth_pages_module_default.checkbox
320
- }), /* @__PURE__ */ jsx("span", { children: checkboxLinkText ? /* @__PURE__ */ jsxs(Fragment, { children: [
321
- "I agree to the",
322
- " ",
323
- /* @__PURE__ */ jsx("a", {
324
- href: checkboxLinkHref,
325
- className: auth_pages_module_default.checkboxLink,
326
- children: checkboxLinkText
327
- })
328
- ] }) : checkboxLabel })]
329
- })
330
- }),
331
- submitted && errors.agreed && /* @__PURE__ */ jsx("span", {
332
- className: auth_pages_module_default.error,
333
- children: errors.agreed
334
- }),
335
- /* @__PURE__ */ jsx("button", {
336
- type: "submit",
337
- disabled: loading,
338
- className: auth_pages_module_default.submitButton,
339
- children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", { className: auth_pages_module_default.spinner }), "Creating account..."] }) : "Create account"
208
+ signup && signUpFields.map((field) => {
209
+ const fieldId = id + "-" + field.name;
210
+ return /* @__PURE__ */ jsx(AuthField, {
211
+ htmlFor: fieldId,
212
+ label: field.label,
213
+ error: errors[field.name],
214
+ children: /* @__PURE__ */ jsx(Input, {
215
+ id: fieldId,
216
+ type: field.type ?? "text",
217
+ value: extraValues[field.name] ?? "",
218
+ placeholder: field.placeholder,
219
+ autoComplete: field.autoComplete,
220
+ required: field.required,
221
+ minLength: field.minLength,
222
+ maxLength: field.maxLength,
223
+ disabled: disabled || pending,
224
+ "aria-invalid": !!errors[field.name],
225
+ "aria-describedby": errors[field.name] ? fieldId + "-error" : void 0,
226
+ onChange: (event) => {
227
+ setExtraValues((old) => ({
228
+ ...old,
229
+ [field.name]: event.target.value
230
+ }));
231
+ setErrors((old) => ({
232
+ ...old,
233
+ [field.name]: ""
234
+ }));
235
+ }
340
236
  })
341
- ]
237
+ }, field.name);
342
238
  }),
343
- footer && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("hr", { className: auth_pages_module_default.divider }), /* @__PURE__ */ jsx("p", {
344
- className: auth_pages_module_default.authFooter,
345
- children: footer
346
- })] })
347
- ]
348
- })
349
- });
350
- }
351
- function ForgotPasswordPage({ title = "Reset password", subtitle = "Enter your email and we'll send a reset link", footer, onSubmit, loading = false, brand, className, emailPlaceholder = "Email address", buttonText = "Send reset link", backLinkText = "Back to sign in", backLinkHref = "/signin" }) {
352
- const id = React.useId();
353
- const [email, setEmail] = React.useState("");
354
- const [error, setError] = React.useState("");
355
- const [sent, setSent] = React.useState(false);
356
- const handleSubmit = (e) => {
357
- e.preventDefault();
358
- if (!email.trim()) {
359
- setError("Email is required");
360
- return;
361
- }
362
- if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
363
- setError("Enter a valid email");
364
- return;
365
- }
366
- onSubmit?.({ email });
367
- setSent(true);
368
- };
369
- return /* @__PURE__ */ jsx("div", {
370
- className: cx(auth_pages_module_default.authLayout, className),
371
- children: /* @__PURE__ */ jsxs("div", {
372
- className: auth_pages_module_default.authCard,
373
- children: [
374
- brand && /* @__PURE__ */ jsx("div", {
375
- className: auth_pages_module_default.authBrand,
376
- children: brand
377
- }),
378
- /* @__PURE__ */ jsxs("div", {
379
- className: auth_pages_module_default.authHeader,
380
- children: [/* @__PURE__ */ jsx("h1", {
381
- className: auth_pages_module_default.authTitle,
382
- children: title
383
- }), subtitle && /* @__PURE__ */ jsx("p", {
384
- className: auth_pages_module_default.authSubtitle,
385
- children: subtitle
239
+ termsRequired && /* @__PURE__ */ jsxs("div", {
240
+ className: auth_page_module_default.terms,
241
+ children: [/* @__PURE__ */ jsxs("label", {
242
+ htmlFor: termsId,
243
+ className: auth_page_module_default.termsLabel,
244
+ children: [/* @__PURE__ */ jsx("input", {
245
+ id: termsId,
246
+ type: "checkbox",
247
+ checked: acceptedTerms,
248
+ disabled: disabled || pending,
249
+ "aria-invalid": !!errors.terms,
250
+ "aria-describedby": errors.terms ? termsId + "-error" : void 0,
251
+ onChange: (event) => {
252
+ setAcceptedTerms(event.target.checked);
253
+ setErrors((old) => ({
254
+ ...old,
255
+ terms: ""
256
+ }));
257
+ }
258
+ }), /* @__PURE__ */ jsxs("span", { children: [signUpOptions?.termsLabel ?? "I agree to the ", signUpOptions?.termsHref ? /* @__PURE__ */ jsx("a", {
259
+ href: signUpOptions.termsHref,
260
+ children: "Terms of Service"
261
+ }) : "Terms of Service"] })]
262
+ }), errors.terms && /* @__PURE__ */ jsx("p", {
263
+ className: auth_page_module_default.error,
264
+ id: termsId + "-error",
265
+ role: "alert",
266
+ children: errors.terms
386
267
  })]
387
268
  }),
388
- sent ? /* @__PURE__ */ jsxs("div", {
389
- className: auth_pages_module_default.sentMessage,
390
- children: [/* @__PURE__ */ jsxs("p", {
391
- className: auth_pages_module_default.sentText,
392
- children: [
393
- "If an account exists for ",
394
- /* @__PURE__ */ jsx("strong", { children: email }),
395
- ", you'll receive a reset link shortly."
396
- ]
397
- }), /* @__PURE__ */ jsx("a", {
398
- href: backLinkHref,
399
- className: auth_pages_module_default.backLink,
400
- children: backLinkText
401
- })]
402
- }) : /* @__PURE__ */ jsxs("form", {
403
- onSubmit: handleSubmit,
404
- className: auth_pages_module_default.authForm,
405
- children: [/* @__PURE__ */ jsx(Field, {
406
- label: emailPlaceholder,
407
- id: id + "-email",
408
- error,
409
- children: /* @__PURE__ */ jsx("input", {
410
- id: id + "-email",
411
- type: "email",
412
- placeholder: "you@example.com",
413
- value: email,
414
- onChange: (e) => {
415
- setEmail(e.target.value);
416
- setError("");
417
- },
418
- className: auth_pages_module_default.input,
419
- autoComplete: "email",
420
- autoFocus: true
421
- })
422
- }), /* @__PURE__ */ jsx("button", {
423
- type: "submit",
424
- disabled: loading,
425
- className: auth_pages_module_default.submitButton,
426
- children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", { className: auth_pages_module_default.spinner }), "Sending..."] }) : buttonText
427
- })]
269
+ !signup && forgotPasswordHref && /* @__PURE__ */ jsx("a", {
270
+ className: auth_page_module_default.forgot,
271
+ href: forgotPasswordHref,
272
+ children: "Forgot password?"
428
273
  }),
429
- footer && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("hr", { className: auth_pages_module_default.divider }), /* @__PURE__ */ jsx("p", {
430
- className: auth_pages_module_default.authFooter,
431
- children: footer
432
- })] })
274
+ serverError && /* @__PURE__ */ jsx("p", {
275
+ className: auth_page_module_default.error,
276
+ role: "alert",
277
+ children: serverError
278
+ }),
279
+ !(signup ? onSignUp : onSignIn) && /* @__PURE__ */ jsx("p", {
280
+ className: auth_page_module_default.error,
281
+ role: "status",
282
+ children: signup ? "Sign-up is not available." : "Sign-in is not available."
283
+ }),
284
+ /* @__PURE__ */ jsx(Button, {
285
+ type: "submit",
286
+ variant: "primary",
287
+ size: "lg",
288
+ disabled: disabled || pending || (signup ? !onSignUp : !onSignIn),
289
+ children: pending ? signup ? "Creating account..." : "Signing in..." : signup ? "Create account" : "Sign in"
290
+ })
433
291
  ]
434
- })
292
+ })]
435
293
  });
436
294
  }
437
295
  //#endregion
438
- export { ForgotPasswordPage, SignInPage, SignUpPage };
296
+ export { AuthPage };
439
297
 
440
298
  //# sourceMappingURL=index70.js.map