@better-auth-ui/heroui 1.6.7 → 1.6.9

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 (280) hide show
  1. package/dist/components/auth/additional-field.d.ts +2 -2
  2. package/dist/components/auth/additional-field.js +133 -266
  3. package/dist/components/auth/api-key/api-key-skeleton.js +4 -20
  4. package/dist/components/auth/api-key/api-key.d.ts +6 -2
  5. package/dist/components/auth/api-key/api-key.js +16 -54
  6. package/dist/components/auth/api-key/api-keys-empty.d.ts +3 -1
  7. package/dist/components/auth/api-key/api-keys-empty.js +8 -34
  8. package/dist/components/auth/api-key/api-keys.d.ts +10 -2
  9. package/dist/components/auth/api-key/api-keys.js +21 -40
  10. package/dist/components/auth/api-key/create-api-key-dialog.d.ts +3 -1
  11. package/dist/components/auth/api-key/create-api-key-dialog.js +43 -73
  12. package/dist/components/auth/api-key/delete-api-key-dialog.d.ts +4 -2
  13. package/dist/components/auth/api-key/delete-api-key-dialog.js +16 -50
  14. package/dist/components/auth/api-key/new-api-key-dialog.js +23 -59
  15. package/dist/components/auth/api-key/organization-api-keys.d.ts +14 -0
  16. package/dist/components/auth/api-key/organization-api-keys.js +22 -0
  17. package/dist/components/auth/auth-provider.d.ts +1 -1
  18. package/dist/components/auth/auth-provider.js +10 -16
  19. package/dist/components/auth/auth.d.ts +3 -3
  20. package/dist/components/auth/auth.js +86 -61
  21. package/dist/components/auth/delete-user/danger-zone.d.ts +3 -3
  22. package/dist/components/auth/delete-user/danger-zone.js +11 -17
  23. package/dist/components/auth/delete-user/delete-account.d.ts +9 -0
  24. package/dist/components/auth/delete-user/delete-account.js +50 -0
  25. package/dist/components/auth/email/email-changed-email.d.ts +2 -2
  26. package/dist/components/auth/email/email-changed-email.js +22 -29
  27. package/dist/components/auth/email/email-verification-email.d.ts +2 -2
  28. package/dist/components/auth/email/email-verification-email.js +22 -29
  29. package/dist/components/auth/email/magic-link-email.d.ts +2 -2
  30. package/dist/components/auth/email/magic-link-email.js +22 -29
  31. package/dist/components/auth/email/new-device-email.d.ts +2 -2
  32. package/dist/components/auth/email/new-device-email.js +22 -29
  33. package/dist/components/auth/email/organization-invitation-email.d.ts +3 -0
  34. package/dist/components/auth/email/organization-invitation-email.js +23 -0
  35. package/dist/components/auth/email/otp-email.d.ts +2 -2
  36. package/dist/components/auth/email/otp-email.js +21 -28
  37. package/dist/components/auth/email/password-changed-email.d.ts +2 -2
  38. package/dist/components/auth/email/password-changed-email.js +22 -29
  39. package/dist/components/auth/email/reset-password-email.d.ts +2 -2
  40. package/dist/components/auth/email/reset-password-email.js +22 -29
  41. package/dist/components/auth/error-toaster.js +32 -16
  42. package/dist/components/auth/field-separator.d.ts +1 -1
  43. package/dist/components/auth/field-separator.js +4 -17
  44. package/dist/components/auth/forgot-password.d.ts +1 -1
  45. package/dist/components/auth/forgot-password.js +36 -88
  46. package/dist/components/auth/magic-link/magic-link-button.d.ts +1 -1
  47. package/dist/components/auth/magic-link/magic-link-button.js +33 -19
  48. package/dist/components/auth/magic-link/magic-link.d.ts +2 -2
  49. package/dist/components/auth/magic-link/magic-link.js +39 -86
  50. package/dist/components/auth/multi-session/manage-account.d.ts +1 -1
  51. package/dist/components/auth/multi-session/manage-account.js +32 -48
  52. package/dist/components/auth/multi-session/manage-accounts.d.ts +1 -1
  53. package/dist/components/auth/multi-session/manage-accounts.js +32 -33
  54. package/dist/components/auth/multi-session/switch-account-submenu-content.d.ts +3 -1
  55. package/dist/components/auth/multi-session/switch-account-submenu-content.js +24 -27
  56. package/dist/components/auth/multi-session/switch-account-submenu-item.d.ts +3 -2
  57. package/dist/components/auth/multi-session/switch-account-submenu-item.js +16 -19
  58. package/dist/components/auth/multi-session/switch-account-submenu.d.ts +2 -1
  59. package/dist/components/auth/multi-session/switch-account-submenu.js +23 -23
  60. package/dist/components/auth/organization/change-organization-logo.d.ts +4 -0
  61. package/dist/components/auth/organization/change-organization-logo.js +69 -0
  62. package/dist/components/auth/organization/create-organization-dialog.d.ts +13 -0
  63. package/dist/components/auth/organization/create-organization-dialog.js +37 -0
  64. package/dist/components/auth/organization/delete-organization-dialog.d.ts +7 -0
  65. package/dist/components/auth/organization/delete-organization-dialog.js +25 -0
  66. package/dist/components/auth/organization/delete-organization-skeleton.d.ts +4 -0
  67. package/dist/components/auth/organization/delete-organization-skeleton.js +8 -0
  68. package/dist/components/auth/organization/delete-organization.d.ts +5 -0
  69. package/dist/components/auth/organization/delete-organization.js +27 -0
  70. package/dist/components/auth/organization/invite-member-dialog.d.ts +13 -0
  71. package/dist/components/auth/organization/invite-member-dialog.js +47 -0
  72. package/dist/components/auth/organization/leave-organization-dialog.d.ts +7 -0
  73. package/dist/components/auth/organization/leave-organization-dialog.js +21 -0
  74. package/dist/components/auth/organization/leave-organization.d.ts +4 -0
  75. package/dist/components/auth/organization/leave-organization.js +16 -0
  76. package/dist/components/auth/organization/organization-danger-zone.d.ts +16 -0
  77. package/dist/components/auth/organization/organization-danger-zone.js +23 -0
  78. package/dist/components/auth/organization/organization-invitation-row-skeleton.d.ts +5 -0
  79. package/dist/components/auth/organization/organization-invitation-row-skeleton.js +9 -0
  80. package/dist/components/auth/organization/organization-invitation-row.d.ts +5 -0
  81. package/dist/components/auth/organization/organization-invitation-row.js +31 -0
  82. package/dist/components/auth/organization/organization-invitations-empty.d.ts +8 -0
  83. package/dist/components/auth/organization/organization-invitations-empty.js +13 -0
  84. package/dist/components/auth/organization/organization-invitations.d.ts +9 -0
  85. package/dist/components/auth/organization/organization-invitations.js +66 -0
  86. package/dist/components/auth/organization/organization-logo.d.ts +15 -0
  87. package/dist/components/auth/organization/organization-logo.js +14 -0
  88. package/dist/components/auth/organization/organization-member-row-skeleton.d.ts +4 -0
  89. package/dist/components/auth/organization/organization-member-row-skeleton.js +9 -0
  90. package/dist/components/auth/organization/organization-member-row.d.ts +9 -0
  91. package/dist/components/auth/organization/organization-member-row.js +34 -0
  92. package/dist/components/auth/organization/organization-members.d.ts +9 -0
  93. package/dist/components/auth/organization/organization-members.js +67 -0
  94. package/dist/components/auth/organization/organization-people.d.ts +10 -0
  95. package/dist/components/auth/organization/organization-people.js +11 -0
  96. package/dist/components/auth/organization/organization-profile.d.ts +9 -0
  97. package/dist/components/auth/organization/organization-profile.js +34 -0
  98. package/dist/components/auth/organization/organization-row.d.ts +8 -0
  99. package/dist/components/auth/organization/organization-row.js +31 -0
  100. package/dist/components/auth/organization/organization-settings.d.ts +12 -0
  101. package/dist/components/auth/organization/organization-settings.js +13 -0
  102. package/dist/components/auth/organization/organization-switcher.d.ts +20 -0
  103. package/dist/components/auth/organization/organization-switcher.js +48 -0
  104. package/dist/components/auth/organization/organization-view-skeleton.d.ts +6 -0
  105. package/dist/components/auth/organization/organization-view-skeleton.js +9 -0
  106. package/dist/components/auth/organization/organization-view.d.ts +15 -0
  107. package/dist/components/auth/organization/organization-view.js +31 -0
  108. package/dist/components/auth/organization/organization.d.ts +17 -0
  109. package/dist/components/auth/organization/organization.js +60 -0
  110. package/dist/components/auth/organization/organizations-empty.d.ts +4 -0
  111. package/dist/components/auth/organization/organizations-empty.js +9 -0
  112. package/dist/components/auth/organization/organizations-settings.d.ts +17 -0
  113. package/dist/components/auth/organization/organizations-settings.js +17 -0
  114. package/dist/components/auth/organization/organizations.d.ts +10 -0
  115. package/dist/components/auth/organization/organizations.js +21 -0
  116. package/dist/components/auth/organization/remove-member-dialog.d.ts +9 -0
  117. package/dist/components/auth/organization/remove-member-dialog.js +20 -0
  118. package/dist/components/auth/organization/slug-field.d.ts +19 -0
  119. package/dist/components/auth/organization/slug-field.js +38 -0
  120. package/dist/components/auth/organization/user-invitation-row-skeleton.d.ts +4 -0
  121. package/dist/components/auth/organization/user-invitation-row-skeleton.js +8 -0
  122. package/dist/components/auth/organization/user-invitation-row.d.ts +10 -0
  123. package/dist/components/auth/organization/user-invitation-row.js +22 -0
  124. package/dist/components/auth/organization/user-invitations-empty.d.ts +4 -0
  125. package/dist/components/auth/organization/user-invitations-empty.js +12 -0
  126. package/dist/components/auth/organization/user-invitations.d.ts +10 -0
  127. package/dist/components/auth/organization/user-invitations.js +18 -0
  128. package/dist/components/auth/passkey/add-passkey-dialog.d.ts +5 -0
  129. package/dist/components/auth/passkey/add-passkey-dialog.js +22 -0
  130. package/dist/components/auth/passkey/delete-passkey-dialog.d.ts +11 -0
  131. package/dist/components/auth/passkey/delete-passkey-dialog.js +14 -0
  132. package/dist/components/auth/passkey/passkey-button.d.ts +1 -1
  133. package/dist/components/auth/passkey/passkey-button.js +24 -23
  134. package/dist/components/auth/passkey/passkey-skeleton.d.ts +1 -0
  135. package/dist/components/auth/passkey/passkey-skeleton.js +5 -0
  136. package/dist/components/auth/passkey/passkey.d.ts +2 -5
  137. package/dist/components/auth/passkey/passkey.js +16 -44
  138. package/dist/components/auth/passkey/passkeys-empty.d.ts +4 -0
  139. package/dist/components/auth/passkey/passkeys-empty.js +9 -0
  140. package/dist/components/auth/passkey/passkeys.d.ts +1 -1
  141. package/dist/components/auth/passkey/passkeys.js +15 -105
  142. package/dist/components/auth/provider-button.d.ts +2 -2
  143. package/dist/components/auth/provider-button.js +28 -24
  144. package/dist/components/auth/provider-buttons.js +28 -18
  145. package/dist/components/auth/reset-password.d.ts +1 -1
  146. package/dist/components/auth/reset-password.js +56 -146
  147. package/dist/components/auth/settings/account/account-settings.d.ts +2 -2
  148. package/dist/components/auth/settings/account/account-settings.js +21 -19
  149. package/dist/components/auth/settings/account/change-avatar.js +53 -88
  150. package/dist/components/auth/settings/account/change-email.d.ts +1 -1
  151. package/dist/components/auth/settings/account/change-email.js +27 -53
  152. package/dist/components/auth/settings/account/user-profile.d.ts +1 -1
  153. package/dist/components/auth/settings/account/user-profile.js +64 -85
  154. package/dist/components/auth/settings/security/active-session.d.ts +1 -1
  155. package/dist/components/auth/settings/security/active-session.js +50 -57
  156. package/dist/components/auth/settings/security/active-sessions.d.ts +1 -1
  157. package/dist/components/auth/settings/security/active-sessions.js +21 -32
  158. package/dist/components/auth/settings/security/change-password.d.ts +1 -1
  159. package/dist/components/auth/settings/security/change-password.js +76 -186
  160. package/dist/components/auth/settings/security/linked-account.d.ts +1 -1
  161. package/dist/components/auth/settings/security/linked-account.js +37 -55
  162. package/dist/components/auth/settings/security/linked-accounts.d.ts +1 -1
  163. package/dist/components/auth/settings/security/linked-accounts.js +34 -43
  164. package/dist/components/auth/settings/security/security-settings.d.ts +2 -2
  165. package/dist/components/auth/settings/security/security-settings.js +19 -21
  166. package/dist/components/auth/settings/settings.d.ts +4 -4
  167. package/dist/components/auth/settings/settings.js +52 -44
  168. package/dist/components/auth/sign-in.d.ts +2 -2
  169. package/dist/components/auth/sign-in.js +63 -132
  170. package/dist/components/auth/sign-out.js +32 -26
  171. package/dist/components/auth/sign-up.d.ts +2 -2
  172. package/dist/components/auth/sign-up.js +97 -211
  173. package/dist/components/auth/theme/appearance.d.ts +1 -1
  174. package/dist/components/auth/theme/appearance.js +23 -71
  175. package/dist/components/auth/theme/theme-toggle-item.js +56 -61
  176. package/dist/components/auth/user/user-avatar.d.ts +4 -4
  177. package/dist/components/auth/user/user-avatar.js +31 -28
  178. package/dist/components/auth/user/user-button.d.ts +6 -7
  179. package/dist/components/auth/user/user-button.js +38 -72
  180. package/dist/components/auth/user/user-view.d.ts +13 -7
  181. package/dist/components/auth/user/user-view.js +26 -36
  182. package/dist/components/auth/username/sign-in-username.d.ts +2 -2
  183. package/dist/components/auth/username/sign-in-username.js +87 -147
  184. package/dist/components/auth/username/username-field.d.ts +1 -1
  185. package/dist/components/auth/username/username-field.js +44 -52
  186. package/dist/email.d.ts +8 -7
  187. package/dist/email.js +8 -8
  188. package/dist/index.d.ts +21 -21
  189. package/dist/index.js +21 -22
  190. package/dist/lib/auth/api-key-plugin.d.ts +7 -4
  191. package/dist/lib/auth/api-key-plugin.js +12 -10
  192. package/dist/lib/auth/auth-plugin.d.ts +10 -6
  193. package/dist/lib/auth/auth-plugin.js +1 -0
  194. package/dist/lib/auth/delete-user-plugin.d.ts +6 -6
  195. package/dist/lib/auth/delete-user-plugin.js +6 -9
  196. package/dist/lib/auth/magic-link-plugin.d.ts +5 -5
  197. package/dist/lib/auth/magic-link-plugin.js +17 -12
  198. package/dist/lib/auth/multi-session-plugin.d.ts +5 -5
  199. package/dist/lib/auth/multi-session-plugin.js +8 -11
  200. package/dist/lib/auth/organization-plugin.d.ts +37 -0
  201. package/dist/lib/auth/organization-plugin.js +19 -0
  202. package/dist/lib/auth/passkey-plugin.d.ts +9 -6
  203. package/dist/lib/auth/passkey-plugin.js +8 -11
  204. package/dist/lib/auth/theme-plugin.d.ts +6 -6
  205. package/dist/lib/auth/theme-plugin.js +25 -22
  206. package/dist/lib/auth/username-plugin.d.ts +11 -11
  207. package/dist/lib/auth/username-plugin.js +18 -17
  208. package/dist/plugins.d.ts +46 -22
  209. package/dist/plugins.js +47 -22
  210. package/package.json +25 -19
  211. package/src/components/auth/api-key/api-key.tsx +25 -16
  212. package/src/components/auth/api-key/api-keys-empty.tsx +8 -4
  213. package/src/components/auth/api-key/api-keys.tsx +52 -14
  214. package/src/components/auth/api-key/create-api-key-dialog.tsx +17 -4
  215. package/src/components/auth/api-key/delete-api-key-dialog.tsx +10 -2
  216. package/src/components/auth/api-key/organization-api-keys.tsx +55 -0
  217. package/src/components/auth/delete-user/danger-zone.tsx +3 -3
  218. package/src/components/auth/delete-user/{delete-user.tsx → delete-account.tsx} +9 -9
  219. package/src/components/auth/email/organization-invitation-email.tsx +38 -0
  220. package/src/components/auth/error-toaster.tsx +28 -10
  221. package/src/components/auth/forgot-password.tsx +10 -2
  222. package/src/components/auth/multi-session/manage-accounts.tsx +1 -1
  223. package/src/components/auth/multi-session/switch-account-submenu-content.tsx +7 -2
  224. package/src/components/auth/multi-session/switch-account-submenu-item.tsx +4 -2
  225. package/src/components/auth/multi-session/switch-account-submenu.tsx +8 -4
  226. package/src/components/auth/organization/change-organization-logo.tsx +171 -0
  227. package/src/components/auth/organization/create-organization-dialog.tsx +133 -0
  228. package/src/components/auth/organization/delete-organization-dialog.tsx +97 -0
  229. package/src/components/auth/organization/delete-organization-skeleton.tsx +17 -0
  230. package/src/components/auth/organization/delete-organization.tsx +77 -0
  231. package/src/components/auth/organization/invite-member-dialog.tsx +177 -0
  232. package/src/components/auth/organization/leave-organization-dialog.tsx +95 -0
  233. package/src/components/auth/organization/leave-organization.tsx +59 -0
  234. package/src/components/auth/organization/organization-danger-zone.tsx +68 -0
  235. package/src/components/auth/organization/organization-invitation-row-skeleton.tsx +29 -0
  236. package/src/components/auth/organization/organization-invitation-row.tsx +97 -0
  237. package/src/components/auth/organization/organization-invitations-empty.tsx +39 -0
  238. package/src/components/auth/organization/organization-invitations.tsx +351 -0
  239. package/src/components/auth/organization/organization-logo.tsx +64 -0
  240. package/src/components/auth/organization/organization-member-row-skeleton.tsx +24 -0
  241. package/src/components/auth/organization/organization-member-row.tsx +157 -0
  242. package/src/components/auth/organization/organization-members.tsx +284 -0
  243. package/src/components/auth/organization/organization-people.tsx +26 -0
  244. package/src/components/auth/organization/organization-profile.tsx +141 -0
  245. package/src/components/auth/organization/organization-row.tsx +66 -0
  246. package/src/components/auth/organization/organization-settings.tsx +38 -0
  247. package/src/components/auth/organization/organization-switcher.tsx +233 -0
  248. package/src/components/auth/organization/organization-view-skeleton.tsx +36 -0
  249. package/src/components/auth/organization/organization-view.tsx +109 -0
  250. package/src/components/auth/organization/organization.tsx +162 -0
  251. package/src/components/auth/organization/organizations-empty.tsx +35 -0
  252. package/src/components/auth/organization/organizations-settings.tsx +36 -0
  253. package/src/components/auth/organization/organizations.tsx +80 -0
  254. package/src/components/auth/organization/remove-member-dialog.tsx +95 -0
  255. package/src/components/auth/organization/slug-field.tsx +111 -0
  256. package/src/components/auth/organization/user-invitation-row-skeleton.tsx +17 -0
  257. package/src/components/auth/organization/user-invitation-row.tsx +90 -0
  258. package/src/components/auth/organization/user-invitations-empty.tsx +30 -0
  259. package/src/components/auth/organization/user-invitations.tsx +59 -0
  260. package/src/components/auth/passkey/add-passkey-dialog.tsx +109 -0
  261. package/src/components/auth/passkey/delete-passkey-dialog.tsx +95 -0
  262. package/src/components/auth/passkey/passkey-skeleton.tsx +16 -0
  263. package/src/components/auth/passkey/passkey.tsx +23 -22
  264. package/src/components/auth/passkey/passkeys-empty.tsx +35 -0
  265. package/src/components/auth/passkey/passkeys.tsx +33 -154
  266. package/src/components/auth/settings/account/change-email.tsx +1 -1
  267. package/src/components/auth/settings/account/user-profile.tsx +5 -5
  268. package/src/components/auth/settings/security/active-sessions.tsx +6 -4
  269. package/src/components/auth/settings/security/linked-accounts.tsx +2 -2
  270. package/src/components/auth/settings/settings.tsx +77 -14
  271. package/src/components/auth/user/user-avatar.tsx +4 -1
  272. package/src/components/auth/user/user-button.tsx +14 -11
  273. package/src/components/auth/user/user-view.tsx +32 -12
  274. package/src/email.ts +1 -0
  275. package/src/lib/auth/api-key-plugin.ts +10 -4
  276. package/src/lib/auth/auth-plugin.ts +6 -1
  277. package/src/lib/auth/organization-plugin.tsx +32 -0
  278. package/src/plugins.ts +25 -1
  279. package/dist/components/auth/delete-user/delete-user.d.ts +0 -9
  280. package/dist/components/auth/delete-user/delete-user.js +0 -95
@@ -1,212 +1,98 @@
1
- import { AdditionalField as e } from "./additional-field.js";
2
- import { FieldSeparator as t } from "./field-separator.js";
3
- import { ProviderButtons as n } from "./provider-buttons.js";
4
- import { authMutationKeys as r, parseAdditionalFieldValue as i } from "@better-auth-ui/core";
5
- import { useAuth as a, useFetchOptions as o, useSignUpEmail as ee } from "@better-auth-ui/react";
6
- import { Eye as s, EyeSlash as c } from "@gravity-ui/icons";
7
- import { Button as l, Card as u, Description as d, FieldError as f, Form as te, Input as p, InputGroup as m, Label as h, Link as g, Spinner as _, TextField as v, cn as y, toast as b } from "@heroui/react";
8
- import { useState as x } from "react";
9
- import { Fragment as S, jsx as C, jsxs as w } from "react/jsx-runtime";
10
- import { useIsMutating as T } from "@tanstack/react-query";
11
- //#region src/components/auth/sign-up.tsx
12
- function E({ className: E, socialLayout: D, socialPosition: O = "bottom", variant: k, ...A }) {
13
- let { additionalFields: j, authClient: M, basePaths: N, emailAndPassword: P, localization: F, plugins: I, redirectTo: L, socialProviders: R, viewPaths: z, navigate: B } = a(), { fetchOptions: V, resetFetchOptions: H } = o(), [U, W] = x(""), [G, K] = x(""), { mutate: q, isPending: J } = ee(M, {
14
- onError: (e) => {
15
- W(""), K(""), b.danger(e.error?.message || e.message), H();
16
- },
17
- onSuccess: () => {
18
- P?.requireEmailVerification ? (b.success(F.auth.verifyYourEmail), B({ to: `${N.auth}/${z.auth.signIn}` })) : B({ to: L });
19
- }
20
- }), [Y, ne] = x(!1), [X, re] = x(!1), Z = T({ mutationKey: r.signIn.all }) + T({ mutationKey: r.signUp.all }) > 0, Q = I.find((e) => e.captchaComponent)?.captchaComponent, ie = async (e) => {
21
- e.preventDefault();
22
- let t = new FormData(e.currentTarget), n = t.get("name") ?? "", r = t.get("email");
23
- if (P?.confirmPassword && U !== G) {
24
- b.danger(F.auth.passwordsDoNotMatch), W(""), K("");
25
- return;
26
- }
27
- let a = {};
28
- for (let e of j ?? []) {
29
- if (!e.signUp || e.readOnly) continue;
30
- let n = i(e, t.get(e.name));
31
- if (e.validate) try {
32
- await e.validate(n);
33
- } catch (e) {
34
- b.danger(e instanceof Error ? e.message : String(e));
35
- return;
36
- }
37
- n !== void 0 && (a[e.name] = n);
38
- }
39
- q({
40
- name: n,
41
- email: r,
42
- password: U,
43
- ...a,
44
- fetchOptions: V
45
- });
46
- }, $ = P?.enabled && !!R?.length;
47
- return /* @__PURE__ */ w(u, {
48
- className: y("w-full max-w-sm gap-4 md:p-6", E),
49
- variant: k,
50
- ...A,
51
- children: [
52
- /* @__PURE__ */ C(u.Header, { children: /* @__PURE__ */ C(u.Title, {
53
- className: "text-xl font-semibold mb-1",
54
- children: F.auth.signUp
55
- }) }),
56
- /* @__PURE__ */ w(u.Content, {
57
- className: "gap-4",
58
- children: [
59
- O === "top" && /* @__PURE__ */ w(S, { children: [!!R?.length && /* @__PURE__ */ C(n, { socialLayout: D }), $ && /* @__PURE__ */ C(t, { children: F.auth.or })] }),
60
- P?.enabled && /* @__PURE__ */ w(te, {
61
- onSubmit: ie,
62
- className: "flex flex-col gap-4",
63
- children: [
64
- P.name !== !1 && /* @__PURE__ */ w(v, {
65
- name: "name",
66
- type: "text",
67
- autoComplete: "name",
68
- isDisabled: Z,
69
- children: [
70
- /* @__PURE__ */ C(h, { children: F.auth.name }),
71
- /* @__PURE__ */ C(p, {
72
- placeholder: F.auth.namePlaceholder,
73
- required: !0,
74
- variant: k === "transparent" ? "primary" : "secondary"
75
- }),
76
- /* @__PURE__ */ C(f, {})
77
- ]
78
- }),
79
- /* @__PURE__ */ w(v, {
80
- name: "email",
81
- type: "email",
82
- autoComplete: "email",
83
- isDisabled: Z,
84
- children: [
85
- /* @__PURE__ */ C(h, { children: F.auth.email }),
86
- /* @__PURE__ */ C(p, {
87
- placeholder: F.auth.emailPlaceholder,
88
- required: !0,
89
- variant: k === "transparent" ? "primary" : "secondary"
90
- }),
91
- /* @__PURE__ */ C(f, {})
92
- ]
93
- }),
94
- j?.map((t) => t.signUp === "above" && /* @__PURE__ */ C(e, {
95
- name: t.name,
96
- field: t,
97
- isPending: Z,
98
- variant: k
99
- }, t.name)),
100
- /* @__PURE__ */ w(v, {
101
- minLength: P?.minPasswordLength,
102
- maxLength: P?.maxPasswordLength,
103
- name: "password",
104
- autoComplete: "new-password",
105
- isDisabled: Z,
106
- value: U,
107
- onChange: W,
108
- children: [
109
- /* @__PURE__ */ C(h, { children: F.auth.password }),
110
- /* @__PURE__ */ w(m, {
111
- variant: k === "transparent" ? "primary" : "secondary",
112
- children: [/* @__PURE__ */ C(m.Input, {
113
- placeholder: F.auth.passwordPlaceholder,
114
- type: Y ? "text" : "password",
115
- name: "password",
116
- required: !0
117
- }), /* @__PURE__ */ C(m.Suffix, {
118
- className: "px-0",
119
- children: /* @__PURE__ */ C(l, {
120
- isIconOnly: !0,
121
- "aria-label": Y ? F.auth.hidePassword : F.auth.showPassword,
122
- size: "sm",
123
- variant: "ghost",
124
- onPress: () => ne(!Y),
125
- isDisabled: Z,
126
- children: C(Y ? c : s, {})
127
- })
128
- })]
129
- }),
130
- /* @__PURE__ */ C(f, {})
131
- ]
132
- }),
133
- P?.confirmPassword && /* @__PURE__ */ w(v, {
134
- minLength: P?.minPasswordLength,
135
- maxLength: P?.maxPasswordLength,
136
- name: "confirmPassword",
137
- autoComplete: "new-password",
138
- isDisabled: Z,
139
- value: G,
140
- onChange: K,
141
- children: [
142
- /* @__PURE__ */ C(h, { children: F.auth.confirmPassword }),
143
- /* @__PURE__ */ w(m, {
144
- variant: k === "transparent" ? "primary" : "secondary",
145
- children: [/* @__PURE__ */ C(m.Input, {
146
- name: "confirmPassword",
147
- placeholder: F.auth.confirmPasswordPlaceholder,
148
- type: X ? "text" : "password",
149
- required: !0
150
- }), /* @__PURE__ */ C(m.Suffix, {
151
- className: "px-0",
152
- children: /* @__PURE__ */ C(l, {
153
- isIconOnly: !0,
154
- "aria-label": X ? F.auth.hidePassword : F.auth.showPassword,
155
- size: "sm",
156
- variant: "ghost",
157
- onPress: () => re(!X),
158
- isDisabled: Z,
159
- children: C(X ? c : s, {})
160
- })
161
- })]
162
- }),
163
- /* @__PURE__ */ C(f, {})
164
- ]
165
- }),
166
- j?.map((t) => t.signUp && t.signUp !== "above" && /* @__PURE__ */ C(e, {
167
- name: t.name,
168
- field: t,
169
- isPending: Z,
170
- variant: k
171
- }, t.name)),
172
- Q && /* @__PURE__ */ C("div", {
173
- className: "flex justify-center",
174
- children: Q
175
- }),
176
- /* @__PURE__ */ w("div", {
177
- className: "flex flex-col gap-3",
178
- children: [/* @__PURE__ */ w(l, {
179
- type: "submit",
180
- className: "w-full",
181
- isPending: Z,
182
- children: [J && /* @__PURE__ */ C(_, {
183
- color: "current",
184
- size: "sm"
185
- }), F.auth.signUp]
186
- }), I.flatMap((e) => e.authButtons?.map((t, n) => /* @__PURE__ */ C(t, { view: "signUp" }, `${e.id}-${n.toString()}`)))]
187
- })
188
- ]
189
- }),
190
- O === "bottom" && /* @__PURE__ */ w(S, { children: [$ && /* @__PURE__ */ C(t, { children: F.auth.or }), !!R?.length && /* @__PURE__ */ C(n, { socialLayout: D })] })
191
- ]
192
- }),
193
- /* @__PURE__ */ C(u.Footer, {
194
- className: "flex-col gap-3",
195
- children: /* @__PURE__ */ w(d, {
196
- className: "text-sm",
197
- children: [
198
- F.auth.alreadyHaveAnAccount,
199
- " ",
200
- /* @__PURE__ */ C(g, {
201
- href: `${N.auth}/${z.auth.signIn}`,
202
- className: "text-accent no-underline hover:underline decoration-accent-hover",
203
- children: F.auth.signIn
204
- })
205
- ]
206
- })
207
- })
208
- ]
209
- });
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { authMutationKeys, parseAdditionalFieldValue } from "@better-auth-ui/core";
3
+ import { useAuth, useFetchOptions, useSignUpEmail } from "@better-auth-ui/react";
4
+ import { Eye, EyeSlash } from "@gravity-ui/icons";
5
+ import { Button, Card, cn, Description, FieldError, Form, Input, InputGroup, Label, Link, Spinner, TextField, toast } from "@heroui/react";
6
+ import { useIsMutating } from "@tanstack/react-query";
7
+ import { useState } from "react";
8
+ import { AdditionalField } from "./additional-field";
9
+ import { FieldSeparator } from "./field-separator";
10
+ import { ProviderButtons } from "./provider-buttons";
11
+ /**
12
+ * Render a sign-up form with name, email, password (and optional confirm password) fields, optional social provider buttons, and password visibility controls.
13
+ *
14
+ * The component reflects request state by disabling inputs and showing a pending indicator during sign-up or social sign-in.
15
+ *
16
+ * @param className - Additional CSS classes applied to the outer card container
17
+ * @param socialLayout - Social layout to apply to the provider buttons component
18
+ * @param socialPosition - Position of social provider buttons relative to the form; `"top"` or `"bottom"` (default `"bottom"`)
19
+ * @returns The sign-up form React element
20
+ */
21
+ export function SignUp({ className, socialLayout, socialPosition = "bottom", variant, ...props }) {
22
+ const { additionalFields, authClient, basePaths, emailAndPassword, localization, plugins, redirectTo, socialProviders, viewPaths, navigate } = useAuth();
23
+ const { fetchOptions, resetFetchOptions } = useFetchOptions();
24
+ const [password, setPassword] = useState("");
25
+ const [confirmPassword, setConfirmPassword] = useState("");
26
+ const { mutate: signUpEmail, isPending: signUpEmailPending } = useSignUpEmail(authClient, {
27
+ onError: (error) => {
28
+ setPassword("");
29
+ setConfirmPassword("");
30
+ toast.danger(error.error?.message || error.message);
31
+ resetFetchOptions();
32
+ },
33
+ onSuccess: () => {
34
+ if (emailAndPassword?.requireEmailVerification) {
35
+ toast.success(localization.auth.verifyYourEmail);
36
+ navigate({ to: `${basePaths.auth}/${viewPaths.auth.signIn}` });
37
+ }
38
+ else {
39
+ navigate({ to: redirectTo });
40
+ }
41
+ }
42
+ });
43
+ const [isPasswordVisible, setIsPasswordVisible] = useState(false);
44
+ const [isConfirmPasswordVisible, setIsConfirmPasswordVisible] = useState(false);
45
+ const signInMutating = useIsMutating({
46
+ mutationKey: authMutationKeys.signIn.all
47
+ });
48
+ const signUpMutating = useIsMutating({
49
+ mutationKey: authMutationKeys.signUp.all
50
+ });
51
+ const isPending = signInMutating + signUpMutating > 0;
52
+ const Captcha = plugins.find((plugin) => plugin.captchaComponent)?.captchaComponent;
53
+ const handleSubmit = async (e) => {
54
+ e.preventDefault();
55
+ const formData = new FormData(e.currentTarget);
56
+ // `emailAndPassword.name === false` hides the name field and submits "".
57
+ const name = formData.get("name") ?? "";
58
+ const email = formData.get("email");
59
+ if (emailAndPassword?.confirmPassword && password !== confirmPassword) {
60
+ toast.danger(localization.auth.passwordsDoNotMatch);
61
+ setPassword("");
62
+ setConfirmPassword("");
63
+ return;
64
+ }
65
+ const additionalFieldValues = {};
66
+ for (const field of additionalFields ?? []) {
67
+ if (!field.signUp || field.readOnly)
68
+ continue;
69
+ const value = parseAdditionalFieldValue(field, formData.get(field.name));
70
+ if (field.validate) {
71
+ try {
72
+ await field.validate(value);
73
+ }
74
+ catch (error) {
75
+ toast.danger(error instanceof Error ? error.message : String(error));
76
+ return;
77
+ }
78
+ }
79
+ if (value !== undefined) {
80
+ additionalFieldValues[field.name] = value;
81
+ }
82
+ }
83
+ signUpEmail({
84
+ name,
85
+ email,
86
+ password,
87
+ ...additionalFieldValues,
88
+ fetchOptions
89
+ });
90
+ };
91
+ const showSeparator = emailAndPassword?.enabled && !!socialProviders?.length;
92
+ return (_jsxs(Card, { className: cn("w-full max-w-sm gap-4 md:p-6", className), variant: variant, ...props, children: [_jsx(Card.Header, { children: _jsx(Card.Title, { className: "text-xl font-semibold mb-1", children: localization.auth.signUp }) }), _jsxs(Card.Content, { className: "gap-4", children: [socialPosition === "top" && (_jsxs(_Fragment, { children: [!!socialProviders?.length && (_jsx(ProviderButtons, { socialLayout: socialLayout })), showSeparator && (_jsx(FieldSeparator, { children: localization.auth.or }))] })), emailAndPassword?.enabled && (_jsxs(Form, { onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [emailAndPassword.name !== false && (_jsxs(TextField, { name: "name", type: "text", autoComplete: "name", isDisabled: isPending, children: [_jsx(Label, { children: localization.auth.name }), _jsx(Input, { placeholder: localization.auth.namePlaceholder, required: true, variant: variant === "transparent" ? "primary" : "secondary" }), _jsx(FieldError, {})] })), _jsxs(TextField, { name: "email", type: "email", autoComplete: "email", isDisabled: isPending, children: [_jsx(Label, { children: localization.auth.email }), _jsx(Input, { placeholder: localization.auth.emailPlaceholder, required: true, variant: variant === "transparent" ? "primary" : "secondary" }), _jsx(FieldError, {})] }), additionalFields?.map((field) => field.signUp === "above" && (_jsx(AdditionalField, { name: field.name, field: field, isPending: isPending, variant: variant }, field.name))), _jsxs(TextField, { minLength: emailAndPassword?.minPasswordLength, maxLength: emailAndPassword?.maxPasswordLength, name: "password", autoComplete: "new-password", isDisabled: isPending, value: password, onChange: setPassword, children: [_jsx(Label, { children: localization.auth.password }), _jsxs(InputGroup, { variant: variant === "transparent" ? "primary" : "secondary", children: [_jsx(InputGroup.Input, { placeholder: localization.auth.passwordPlaceholder, type: isPasswordVisible ? "text" : "password", name: "password", required: true }), _jsx(InputGroup.Suffix, { className: "px-0", children: _jsx(Button, { isIconOnly: true, "aria-label": isPasswordVisible
93
+ ? localization.auth.hidePassword
94
+ : localization.auth.showPassword, size: "sm", variant: "ghost", onPress: () => setIsPasswordVisible(!isPasswordVisible), isDisabled: isPending, children: isPasswordVisible ? _jsx(EyeSlash, {}) : _jsx(Eye, {}) }) })] }), _jsx(FieldError, {})] }), emailAndPassword?.confirmPassword && (_jsxs(TextField, { minLength: emailAndPassword?.minPasswordLength, maxLength: emailAndPassword?.maxPasswordLength, name: "confirmPassword", autoComplete: "new-password", isDisabled: isPending, value: confirmPassword, onChange: setConfirmPassword, children: [_jsx(Label, { children: localization.auth.confirmPassword }), _jsxs(InputGroup, { variant: variant === "transparent" ? "primary" : "secondary", children: [_jsx(InputGroup.Input, { name: "confirmPassword", placeholder: localization.auth.confirmPasswordPlaceholder, type: isConfirmPasswordVisible ? "text" : "password", required: true }), _jsx(InputGroup.Suffix, { className: "px-0", children: _jsx(Button, { isIconOnly: true, "aria-label": isConfirmPasswordVisible
95
+ ? localization.auth.hidePassword
96
+ : localization.auth.showPassword, size: "sm", variant: "ghost", onPress: () => setIsConfirmPasswordVisible(!isConfirmPasswordVisible), isDisabled: isPending, children: isConfirmPasswordVisible ? _jsx(EyeSlash, {}) : _jsx(Eye, {}) }) })] }), _jsx(FieldError, {})] })), additionalFields?.map((field) => field.signUp &&
97
+ field.signUp !== "above" && (_jsx(AdditionalField, { name: field.name, field: field, isPending: isPending, variant: variant }, field.name))), Captcha && _jsx("div", { className: "flex justify-center", children: Captcha }), _jsxs("div", { className: "flex flex-col gap-3", children: [_jsxs(Button, { type: "submit", className: "w-full", isPending: isPending, children: [signUpEmailPending && _jsx(Spinner, { color: "current", size: "sm" }), localization.auth.signUp] }), plugins.flatMap((plugin) => plugin.authButtons?.map((AuthButton, index) => (_jsx(AuthButton, { view: "signUp" }, `${plugin.id}-${index.toString()}`))))] })] })), socialPosition === "bottom" && (_jsxs(_Fragment, { children: [showSeparator && (_jsx(FieldSeparator, { children: localization.auth.or })), !!socialProviders?.length && (_jsx(ProviderButtons, { socialLayout: socialLayout }))] }))] }), _jsx(Card.Footer, { className: "flex-col gap-3", children: _jsxs(Description, { className: "text-sm", children: [localization.auth.alreadyHaveAnAccount, " ", _jsx(Link, { href: `${basePaths.auth}/${viewPaths.auth.signIn}`, className: "text-accent no-underline hover:underline decoration-accent-hover", children: localization.auth.signIn })] }) })] }));
210
98
  }
211
- //#endregion
212
- export { E as SignUp };
@@ -1,4 +1,4 @@
1
- import { CardProps } from '@heroui/react';
1
+ import { type CardProps } from "@heroui/react";
2
2
  export type AppearanceProps = {
3
3
  className?: string;
4
4
  variant?: CardProps["variant"];
@@ -1,72 +1,24 @@
1
- import { themePlugin as e } from "../../../lib/auth/theme-plugin.js";
2
- import { ThemePreviewDark as t, ThemePreviewLight as n, ThemePreviewSystem as r, useAuthPlugin as i } from "@better-auth-ui/react";
3
- import { Display as a, Moon as o, Sun as s } from "@gravity-ui/icons";
4
- import { Card as c, Label as l, Radio as u, RadioGroup as d, cn as f, useIsHydrated as p } from "@heroui/react";
5
- import { jsx as m, jsxs as h } from "react/jsx-runtime";
6
- //#region src/components/auth/theme/appearance.tsx
7
- function g({ className: g, variant: _, ...v }) {
8
- let { useTheme: y, localization: b } = i(e), { theme: x, setTheme: S, themes: C = [] } = y(), w = p();
9
- return /* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("h2", {
10
- className: f("text-sm font-semibold mb-3"),
11
- children: b.appearance
12
- }), /* @__PURE__ */ m(c, {
13
- className: f("p-4 gap-4", g),
14
- variant: _,
15
- ...v,
16
- children: /* @__PURE__ */ h(c.Content, { children: [/* @__PURE__ */ m(l, { children: b.theme }), /* @__PURE__ */ m(d, {
17
- variant: _ === "transparent" ? "secondary" : "primary",
18
- value: w ? x : "",
19
- onChange: S,
20
- isDisabled: !w || !x,
21
- children: /* @__PURE__ */ h("div", {
22
- className: "grid gap-3 grid-cols-2 sm:grid-cols-3",
23
- children: [
24
- C.includes("system") && /* @__PURE__ */ m(u, {
25
- value: "system",
26
- className: f("mt-0 px-4 pb-4 pt-3 rounded-xl", "border border-transparent data-[selected=true]:border-accent data-[selected=true]:bg-accent/10", "data-[focus-visible=true]:border-accent data-[focus-visible=true]:bg-accent/10", _ === "transparent" ? "bg-surface" : "bg-surface-secondary"),
27
- children: /* @__PURE__ */ h(u.Content, {
28
- className: "gap-2",
29
- children: [/* @__PURE__ */ h("div", {
30
- className: "flex gap-2 justify-between",
31
- children: [/* @__PURE__ */ h(l, {
32
- className: "flex gap-2 items-center",
33
- children: [/* @__PURE__ */ m(a, { className: "text-muted" }), b.system]
34
- }), /* @__PURE__ */ m(u.Control, { children: /* @__PURE__ */ m(u.Indicator, {}) })]
35
- }), /* @__PURE__ */ m(r, { className: "w-full" })]
36
- })
37
- }),
38
- C.includes("light") && /* @__PURE__ */ m(u, {
39
- value: "light",
40
- className: f("mt-0 px-4 pb-4 pt-3 rounded-xl", "border border-transparent data-[selected=true]:border-accent data-[selected=true]:bg-accent/10", "data-[focus-visible=true]:border-accent data-[focus-visible=true]:bg-accent/10", _ === "transparent" ? "bg-surface" : "bg-surface-secondary"),
41
- children: /* @__PURE__ */ h(u.Content, {
42
- className: "gap-2",
43
- children: [/* @__PURE__ */ h("div", {
44
- className: "flex gap-2 justify-between",
45
- children: [/* @__PURE__ */ h(l, {
46
- className: "flex gap-2 items-center",
47
- children: [/* @__PURE__ */ m(s, { className: "text-muted" }), b.light]
48
- }), /* @__PURE__ */ m(u.Control, { children: /* @__PURE__ */ m(u.Indicator, {}) })]
49
- }), /* @__PURE__ */ m(n, { className: "w-full" })]
50
- })
51
- }),
52
- C.includes("dark") && /* @__PURE__ */ m(u, {
53
- value: "dark",
54
- className: f("mt-0 px-4 pb-4 pt-3 rounded-xl", "border border-transparent data-[selected=true]:border-accent data-[selected=true]:bg-accent/10", "data-[focus-visible=true]:border-accent data-[focus-visible=true]:bg-accent/10", _ === "transparent" ? "bg-surface" : "bg-surface-secondary"),
55
- children: /* @__PURE__ */ h(u.Content, {
56
- className: "gap-2",
57
- children: [/* @__PURE__ */ h("div", {
58
- className: "flex gap-2 justify-between",
59
- children: [/* @__PURE__ */ h(l, {
60
- className: "flex gap-2 items-center",
61
- children: [/* @__PURE__ */ m(o, { className: "text-muted" }), b.dark]
62
- }), /* @__PURE__ */ m(u.Control, { children: /* @__PURE__ */ m(u.Indicator, {}) })]
63
- }), /* @__PURE__ */ m(t, { className: "w-full" })]
64
- })
65
- })
66
- ]
67
- })
68
- })] })
69
- })] });
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ThemePreviewDark, ThemePreviewLight, ThemePreviewSystem, useAuthPlugin } from "@better-auth-ui/react";
3
+ import { Display, Moon, Sun } from "@gravity-ui/icons";
4
+ import { Card, cn, Label, Radio, RadioGroup, useIsHydrated } from "@heroui/react";
5
+ import { themePlugin } from "../../../lib/auth/theme-plugin";
6
+ /**
7
+ * Renders a theme selector card with visual theme previews.
8
+ *
9
+ * Displays a card containing radio buttons for selecting between system, light,
10
+ * and dark themes. Each option shows a visual preview of the theme. Theme options
11
+ * are conditionally shown based on the `themes` array provided via the theme plugin.
12
+ */
13
+ export function Appearance({ className, variant, ...props }) {
14
+ const { useTheme, localization } = useAuthPlugin(themePlugin);
15
+ const { theme, setTheme, themes = [] } = useTheme();
16
+ const hydrated = useIsHydrated();
17
+ return (_jsxs("div", { children: [_jsx("h2", { className: cn("text-sm font-semibold mb-3"), children: localization.appearance }), _jsx(Card, { className: cn("p-4 gap-4", className), variant: variant, ...props, children: _jsxs(Card.Content, { children: [_jsx(Label, { children: localization.theme }), _jsx(RadioGroup, { variant: variant === "transparent" ? "secondary" : "primary", value: hydrated ? theme : "", onChange: setTheme, isDisabled: !hydrated || !theme, children: _jsxs("div", { className: "grid gap-3 grid-cols-2 sm:grid-cols-3", children: [themes.includes("system") && (_jsx(Radio, { value: "system", className: cn("mt-0 px-4 pb-4 pt-3 rounded-xl", "border border-transparent data-[selected=true]:border-accent data-[selected=true]:bg-accent/10", "data-[focus-visible=true]:border-accent data-[focus-visible=true]:bg-accent/10", variant === "transparent"
18
+ ? "bg-surface"
19
+ : "bg-surface-secondary"), children: _jsxs(Radio.Content, { className: "gap-2", children: [_jsxs("div", { className: "flex gap-2 justify-between", children: [_jsxs(Label, { className: "flex gap-2 items-center", children: [_jsx(Display, { className: "text-muted" }), localization.system] }), _jsx(Radio.Control, { children: _jsx(Radio.Indicator, {}) })] }), _jsx(ThemePreviewSystem, { className: "w-full" })] }) })), themes.includes("light") && (_jsx(Radio, { value: "light", className: cn("mt-0 px-4 pb-4 pt-3 rounded-xl", "border border-transparent data-[selected=true]:border-accent data-[selected=true]:bg-accent/10", "data-[focus-visible=true]:border-accent data-[focus-visible=true]:bg-accent/10", variant === "transparent"
20
+ ? "bg-surface"
21
+ : "bg-surface-secondary"), children: _jsxs(Radio.Content, { className: "gap-2", children: [_jsxs("div", { className: "flex gap-2 justify-between", children: [_jsxs(Label, { className: "flex gap-2 items-center", children: [_jsx(Sun, { className: "text-muted" }), localization.light] }), _jsx(Radio.Control, { children: _jsx(Radio.Indicator, {}) })] }), _jsx(ThemePreviewLight, { className: "w-full" })] }) })), themes.includes("dark") && (_jsx(Radio, { value: "dark", className: cn("mt-0 px-4 pb-4 pt-3 rounded-xl", "border border-transparent data-[selected=true]:border-accent data-[selected=true]:bg-accent/10", "data-[focus-visible=true]:border-accent data-[focus-visible=true]:bg-accent/10", variant === "transparent"
22
+ ? "bg-surface"
23
+ : "bg-surface-secondary"), children: _jsxs(Radio.Content, { className: "gap-2", children: [_jsxs("div", { className: "flex gap-2 justify-between", children: [_jsxs(Label, { className: "flex gap-2 items-center", children: [_jsx(Moon, { className: "text-muted" }), localization.dark] }), _jsx(Radio.Control, { children: _jsx(Radio.Indicator, {}) })] }), _jsx(ThemePreviewDark, { className: "w-full" })] }) }))] }) })] }) })] }));
70
24
  }
71
- //#endregion
72
- export { g as Appearance };
@@ -1,62 +1,57 @@
1
- import { themePlugin as e } from "../../../lib/auth/theme-plugin.js";
2
- import { useAuthPlugin as t } from "@better-auth-ui/react";
3
- import { Display as n, Moon as r, Palette as i, Sun as a } from "@gravity-ui/icons";
4
- import { Dropdown as o, Label as s, Tabs as c } from "@heroui/react";
5
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
6
- //#region src/components/auth/theme/theme-toggle-item.tsx
7
- var d = "[role=\"tab\"][aria-selected=\"true\"]";
8
- function f() {
9
- let { useTheme: f, localization: p } = t(e), { theme: m, setTheme: h, themes: g = [] } = f();
10
- return /* @__PURE__ */ u(o.Item, {
11
- className: "py-1 pe-2",
12
- onFocus: (e) => {
13
- e.target === e.currentTarget && e.currentTarget.querySelector(d)?.focus({ preventScroll: !0 });
14
- },
15
- shouldCloseOnSelect: !1,
16
- children: [
17
- /* @__PURE__ */ l(i, { className: "text-muted" }),
18
- /* @__PURE__ */ l(s, { children: p.theme }),
19
- /* @__PURE__ */ l(c, {
20
- className: "ml-auto",
21
- selectedKey: m,
22
- onSelectionChange: (e) => h(e),
23
- children: /* @__PURE__ */ l(c.ListContainer, {
24
- onKeyDown: (e) => {
25
- if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
26
- let t = e.target;
27
- if (t.getAttribute("role") !== "tab") return;
28
- let n = t.closest("[role=\"menuitem\"]"), r = n?.closest("[role=\"menu\"]");
29
- if (!n || !r) return;
30
- let i = Array.from(r.querySelectorAll("[role=\"menuitem\"]:not([data-disabled])")), a = i.indexOf(n);
31
- if (a === -1) return;
32
- let o = i[e.key === "ArrowDown" ? a + 1 : a - 1];
33
- o && (e.preventDefault(), o.focus());
34
- },
35
- children: /* @__PURE__ */ u(c.List, {
36
- "aria-label": p.theme,
37
- className: "*:h-5 *:w-5 *:p-0",
38
- children: [
39
- g.includes("system") && /* @__PURE__ */ u(c.Tab, {
40
- id: "system",
41
- "aria-label": p.system,
42
- children: [/* @__PURE__ */ l(n, { className: "size-3" }), /* @__PURE__ */ l(c.Indicator, {})]
43
- }),
44
- g.includes("light") && /* @__PURE__ */ u(c.Tab, {
45
- id: "light",
46
- "aria-label": p.light,
47
- children: [/* @__PURE__ */ l(a, { className: "size-3" }), /* @__PURE__ */ l(c.Indicator, {})]
48
- }),
49
- g.includes("dark") && /* @__PURE__ */ u(c.Tab, {
50
- id: "dark",
51
- "aria-label": p.dark,
52
- children: [/* @__PURE__ */ l(r, { className: "size-3" }), /* @__PURE__ */ l(c.Indicator, {})]
53
- })
54
- ]
55
- })
56
- })
57
- })
58
- ]
59
- });
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useAuthPlugin } from "@better-auth-ui/react";
3
+ import { Display, Moon, Palette, Sun } from "@gravity-ui/icons";
4
+ import { Dropdown, Label, Tabs } from "@heroui/react";
5
+ import { themePlugin } from "../../../lib/auth/theme-plugin";
6
+ const ACTIVE_TAB_SELECTOR = '[role="tab"][aria-selected="true"]';
7
+ /**
8
+ * Theme toggle dropdown item used inside `UserButton`. Callers are responsible
9
+ * for ensuring theming is configured before rendering this component.
10
+ */
11
+ export function ThemeToggleItem() {
12
+ const { useTheme, localization } = useAuthPlugin(themePlugin);
13
+ const { theme, setTheme, themes = [] } = useTheme();
14
+ // The Tabs aren't part of the menu's keyboard-navigation list, so arrow-key
15
+ // nav can't reach them on its own. When the wrapper menu item receives focus
16
+ // we delegate focus to the active Tab so the user can switch themes with the
17
+ // Left/Right arrows. React's synthetic `onFocus` bubbles (it's wired to
18
+ // `focusin`), so we must guard against child-originated events: without the
19
+ // `target === currentTarget` check, an arrow-key focus move between tabs
20
+ // bubbles up here and the still-stale `aria-selected="true"` lookup yanks
21
+ // focus back to the previously selected tab.
22
+ const focusActiveTab = (event) => {
23
+ if (event.target !== event.currentTarget)
24
+ return;
25
+ const activeTab = event.currentTarget.querySelector(ACTIVE_TAB_SELECTOR);
26
+ activeTab?.focus({ preventScroll: true });
27
+ };
28
+ // Up/Down on a Tab escapes back to the previous/next sibling menu item so
29
+ // users can keep navigating the menu with the arrow keys after they've
30
+ // entered the Tabs.
31
+ const handleTabsKeyDown = (event) => {
32
+ if (event.key !== "ArrowUp" && event.key !== "ArrowDown")
33
+ return;
34
+ const target = event.target;
35
+ if (target.getAttribute("role") !== "tab")
36
+ return;
37
+ const wrapper = target.closest('[role="menuitem"]');
38
+ const menu = wrapper?.closest('[role="menu"]');
39
+ if (!wrapper || !menu)
40
+ return;
41
+ const items = Array.from(menu.querySelectorAll('[role="menuitem"]:not([data-disabled])'));
42
+ const currentIndex = items.indexOf(wrapper);
43
+ if (currentIndex === -1)
44
+ return;
45
+ const nextIndex = event.key === "ArrowDown" ? currentIndex + 1 : currentIndex - 1;
46
+ const next = items[nextIndex];
47
+ if (!next)
48
+ return;
49
+ event.preventDefault();
50
+ next.focus();
51
+ };
52
+ return (_jsxs(Dropdown.Item, { className: "py-1 pe-2", onFocus: focusActiveTab,
53
+ // Without `shouldCloseOnSelect={false}` the menu auto-closes after the
54
+ // user changes themes, because clicking on a Tab bubbles up as a
55
+ // menu-item activation.
56
+ shouldCloseOnSelect: false, children: [_jsx(Palette, { className: "text-muted" }), _jsx(Label, { children: localization.theme }), _jsx(Tabs, { className: "ml-auto", selectedKey: theme, onSelectionChange: (key) => setTheme(key), children: _jsx(Tabs.ListContainer, { onKeyDown: handleTabsKeyDown, children: _jsxs(Tabs.List, { "aria-label": localization.theme, className: "*:h-5 *:w-5 *:p-0", children: [themes.includes("system") && (_jsxs(Tabs.Tab, { id: "system", "aria-label": localization.system, children: [_jsx(Display, { className: "size-3" }), _jsx(Tabs.Indicator, {})] })), themes.includes("light") && (_jsxs(Tabs.Tab, { id: "light", "aria-label": localization.light, children: [_jsx(Sun, { className: "size-3" }), _jsx(Tabs.Indicator, {})] })), themes.includes("dark") && (_jsxs(Tabs.Tab, { id: "dark", "aria-label": localization.dark, children: [_jsx(Moon, { className: "size-3" }), _jsx(Tabs.Indicator, {})] }))] }) }) })] }));
60
57
  }
61
- //#endregion
62
- export { f as ThemeToggleItem };
@@ -1,12 +1,12 @@
1
- import { AvatarProps } from '@heroui/react';
2
- import { User } from 'better-auth';
3
- import { ReactNode } from 'react';
1
+ import { type AvatarProps } from "@heroui/react";
2
+ import type { User } from "better-auth";
3
+ import type { ReactNode } from "react";
4
4
  export type UserAvatarProps = {
5
5
  className?: string;
6
6
  fallback?: ReactNode;
7
7
  isPending?: boolean;
8
8
  /** @remarks `User` */
9
- user?: User & {
9
+ user?: Partial<User> & {
10
10
  username?: string | null;
11
11
  displayUsername?: string | null;
12
12
  };