@alepha/ui 0.25.0 → 0.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/package.json +4 -5
  2. package/src/components/account/__tests__/account-router.spec.ts +201 -0
  3. package/src/components/account/account-connections.tsx +103 -0
  4. package/src/components/account/account-delete-dialog.tsx +184 -0
  5. package/src/components/account/account-header.tsx +57 -0
  6. package/src/components/account/account-keys.tsx +221 -0
  7. package/src/components/account/account-layout.tsx +63 -0
  8. package/src/components/account/account-password-dialog.tsx +152 -0
  9. package/src/components/account/account-profile.tsx +229 -0
  10. package/src/components/account/account-router-options.tsx +74 -0
  11. package/src/components/account/account-router-page.tsx +69 -0
  12. package/src/components/account/account-router.tsx +214 -0
  13. package/src/components/account/account-security.tsx +150 -0
  14. package/src/components/account/account-sessions.tsx +140 -0
  15. package/src/components/admin/__tests__/admin-keys-token-dialog.browser.spec.tsx +62 -0
  16. package/src/components/admin/__tests__/admin-layout.browser.spec.tsx +82 -0
  17. package/src/components/admin/__tests__/admin-router-page.spec.ts +54 -0
  18. package/src/components/admin/__tests__/admin-router.spec.ts +208 -0
  19. package/src/components/admin/__tests__/admin-user-cell.browser.spec.tsx +99 -0
  20. package/src/components/admin/__tests__/admin-user-detail.spec.ts +29 -0
  21. package/src/components/admin/admin-analytics-query-panel.tsx +149 -0
  22. package/src/components/admin/admin-analytics-results.tsx +95 -0
  23. package/src/components/admin/admin-analytics.tsx +104 -0
  24. package/src/components/admin/admin-audits.tsx +12 -15
  25. package/src/components/admin/admin-files.tsx +10 -18
  26. package/src/components/admin/admin-jobs-executions-panel.tsx +2 -1
  27. package/src/components/admin/admin-jobs.tsx +3 -1
  28. package/src/components/admin/admin-keys-token-dialog.tsx +123 -0
  29. package/src/components/admin/admin-keys.tsx +54 -3
  30. package/src/components/admin/admin-layout.tsx +107 -0
  31. package/src/components/admin/admin-payments.tsx +4 -5
  32. package/src/components/admin/admin-router-options.tsx +130 -0
  33. package/src/components/admin/admin-router-page.tsx +74 -0
  34. package/src/components/admin/admin-router.tsx +379 -0
  35. package/src/components/admin/admin-sessions.tsx +2 -16
  36. package/src/components/admin/admin-user-cell.tsx +70 -0
  37. package/src/components/admin/admin-user-detail-overview-tab.tsx +28 -0
  38. package/src/components/admin/admin-user-detail-profile-policy.spec.ts +146 -0
  39. package/src/components/admin/admin-user-detail-profile-policy.ts +147 -0
  40. package/src/components/admin/admin-user-detail-security-tab.tsx +1 -1
  41. package/src/components/admin/admin-user-detail.tsx +76 -32
  42. package/src/components/admin/admin-users-status-filter.tsx +2 -0
  43. package/src/components/admin/admin-workflows-execution-sheet.tsx +277 -0
  44. package/src/components/admin/admin-workflows-executions-panel.tsx +170 -0
  45. package/src/components/admin/admin-workflows-status-badge.tsx +40 -0
  46. package/src/components/admin/admin-workflows.tsx +207 -0
  47. package/src/components/alepha-table/alepha-table.tsx +73 -17
  48. package/src/components/app-actions/__tests__/app-actions.browser.spec.tsx +79 -0
  49. package/src/components/app-actions/app-actions.tsx +113 -0
  50. package/src/components/app-shell/app-shell.tsx +122 -0
  51. package/src/components/auth/auth-reset-password.tsx +81 -8
  52. package/src/components/button-user/button-user.tsx +58 -1
  53. package/src/components/control/control.tsx +14 -71
  54. package/src/components/control-password/control-password.tsx +87 -0
  55. package/src/components/control-select/__tests__/control-select-clear-label.browser.spec.tsx +101 -0
  56. package/src/components/control-select/__tests__/control-select-deselect.browser.spec.tsx +126 -0
  57. package/src/components/control-select/__tests__/control-select-searchable.browser.spec.tsx +142 -0
  58. package/src/components/control-select/control-select.tsx +133 -111
  59. package/src/components/control-upload/control-upload.tsx +27 -1
  60. package/src/components/markdown-view/markdown-view.tsx +6 -0
  61. package/src/components/nav-shell/nav-page.tsx +3 -3
  62. package/src/components/settings/__tests__/settings-nav.browser.spec.tsx +123 -0
  63. package/src/components/settings/__tests__/settings-section.browser.spec.tsx +130 -0
  64. package/src/components/settings/settings-danger-section.tsx +59 -0
  65. package/src/components/settings/settings-layout.tsx +56 -0
  66. package/src/components/settings/settings-nav.tsx +131 -0
  67. package/src/components/settings/settings-row.tsx +81 -0
  68. package/src/components/settings/settings-section.tsx +64 -0
  69. package/src/components/ui/alert-dialog.tsx +1 -1
  70. package/src/components/ui/avatar.tsx +2 -0
  71. package/src/components/ui/breadcrumb.tsx +1 -1
  72. package/src/components/ui/calendar.tsx +11 -6
  73. package/src/components/ui/card.tsx +5 -5
  74. package/src/components/ui/carousel.tsx +4 -4
  75. package/src/components/ui/chart.tsx +2 -0
  76. package/src/components/ui/collapsible.tsx +2 -0
  77. package/src/components/ui/combobox.tsx +3 -1
  78. package/src/components/ui/context-menu.tsx +3 -3
  79. package/src/components/ui/dialog.tsx +6 -1
  80. package/src/components/ui/direction.tsx +2 -0
  81. package/src/components/ui/drawer.tsx +134 -37
  82. package/src/components/ui/dropdown-menu.tsx +13 -3
  83. package/src/components/ui/empty.tsx +4 -1
  84. package/src/components/ui/input-otp.tsx +2 -0
  85. package/src/components/ui/menubar.tsx +2 -2
  86. package/src/components/ui/pagination.tsx +2 -2
  87. package/src/components/ui/popover.tsx +2 -0
  88. package/src/components/ui/radio-group.tsx +2 -0
  89. package/src/components/ui/scroll-area.tsx +2 -0
  90. package/src/components/ui/select.tsx +1 -1
  91. package/src/components/ui/separator.tsx +2 -0
  92. package/src/components/ui/sheet.tsx +4 -1
  93. package/src/components/ui/sidebar.tsx +1 -1
  94. package/src/components/ui/spinner.tsx +1 -0
  95. package/src/components/ui/switch.tsx +2 -0
  96. package/src/components/ui/tabs.tsx +2 -0
  97. package/src/components/ui/toggle-group.tsx +2 -0
  98. package/src/components/ui/tooltip.tsx +2 -0
  99. package/src/lib/__tests__/rehype-safe-img.spec.ts +121 -0
  100. package/src/lib/i18n-fr.ts +68 -0
  101. package/src/lib/rehype-safe-img.ts +150 -0
  102. package/src/lib/resize-image.ts +135 -0
  103. package/src/styles.css +126 -1
  104. /package/src/components/{admin/admin-user-detail-provider-labels.ts → auth/provider-labels.ts} +0 -0
@@ -0,0 +1,113 @@
1
+ import { ButtonDark } from "@alepha/ui/components/button-dark/button-dark";
2
+ import { ButtonLanguage } from "@alepha/ui/components/button-language/button-language";
3
+ import { ButtonTheme } from "@alepha/ui/components/button-theme/button-theme";
4
+ import { ButtonUser } from "@alepha/ui/components/button-user/button-user";
5
+ import { DropdownMenuSeparator } from "@alepha/ui/components/ui/dropdown-menu";
6
+ import { cn } from "@alepha/ui/lib/utils";
7
+ import { useRouter } from "alepha/react/router";
8
+ import type { ReactNode } from "react";
9
+
10
+ export interface AppActionsProps {
11
+ /**
12
+ * Extra menu items appended to the account dropdown, below the built-ins
13
+ * and above Logout. For an application-specific destination — "My orders",
14
+ * "Billing" — that belongs with the account rather than in the page chrome.
15
+ */
16
+ children?: ReactNode;
17
+
18
+ /**
19
+ * Rendered to the left of the cluster: a search trigger, a create button,
20
+ * anything the surface wants adjacent to these controls.
21
+ */
22
+ before?: ReactNode;
23
+
24
+ /**
25
+ * Route name pushed by the "Admin Panel" item. The item is hidden anyway
26
+ * unless the viewer holds `admin:ui`.
27
+ *
28
+ * @default "admin"
29
+ */
30
+ adminRouteName?: string;
31
+
32
+ /**
33
+ * Route name pushed by the signed-out state's sign-in button.
34
+ *
35
+ * @default "login"
36
+ */
37
+ loginRouteName?: string;
38
+
39
+ /**
40
+ * Labels, for an application that localises its chrome. Omitted entries
41
+ * fall back to each button's own English default.
42
+ */
43
+ labels?: {
44
+ language?: string;
45
+ signIn?: string;
46
+ admin?: string;
47
+ account?: string;
48
+ logout?: string;
49
+ };
50
+
51
+ className?: string;
52
+ }
53
+
54
+ /**
55
+ * The ambient controls every signed-in surface carries: language, theme,
56
+ * dark mode, account.
57
+ *
58
+ * ### Why this is one component rather than four imports
59
+ *
60
+ * It was four imports, in three places — `AdminLayout`, `AccountLayout` and
61
+ * `apps/lore`'s own header — and they had already drifted: admin rendered no
62
+ * theme switcher, and Lore's account menu pushed a route that no longer
63
+ * existed. A cluster that every shell rebuilds by hand is a cluster where
64
+ * each copy is one refactor away from being subtly wrong.
65
+ *
66
+ * ### Each button decides whether it has anything to offer
67
+ *
68
+ * There is no "show the language switcher?" prop, and there should not be:
69
+ * `ButtonLanguage` and `ButtonTheme` already return `null` at one or fewer
70
+ * options, reading the real registry rather than a flag a caller has to keep
71
+ * in sync. So an application with a single locale and a single theme renders
72
+ * exactly two controls here, and gains the others the day it registers a
73
+ * second — with no change at any call site.
74
+ *
75
+ * `ButtonUser` likewise renders a sign-in button when signed out and the
76
+ * account menu when signed in, and `ButtonUser.AccountMenuItem` hides itself
77
+ * when no `account` route is mounted.
78
+ *
79
+ * ### What it deliberately does not include
80
+ *
81
+ * Search. `AdminLayout` keeps its ⌘K trigger outside this cluster because the
82
+ * Spotlight open-state is local to that layout, so a shared component could
83
+ * never own it — and Lore's own search is a field-sized element that reads as
84
+ * a different kind of control next to four icons. Pass it via `before` when a
85
+ * surface wants it adjacent.
86
+ */
87
+ export const AppActions = (props: AppActionsProps) => {
88
+ const router = useRouter<any>();
89
+
90
+ return (
91
+ <div className={cn("flex items-center gap-1", props.className)}>
92
+ {props.before}
93
+ <ButtonLanguage variant="ghost" label={props.labels?.language} />
94
+ <ButtonTheme variant="ghost" />
95
+ <ButtonDark variant="ghost" />
96
+ <ButtonUser
97
+ variant="ghost"
98
+ signInLabel={props.labels?.signIn}
99
+ onSignIn={() => router.push(props.loginRouteName ?? "login")}
100
+ >
101
+ <ButtonUser.Email />
102
+ <ButtonUser.AdminMenuItem
103
+ label={props.labels?.admin}
104
+ onClick={() => router.push(props.adminRouteName ?? "admin")}
105
+ />
106
+ <ButtonUser.AccountMenuItem label={props.labels?.account} />
107
+ {props.children}
108
+ <DropdownMenuSeparator />
109
+ <ButtonUser.LogoutMenuItem label={props.labels?.logout} />
110
+ </ButtonUser>
111
+ </div>
112
+ );
113
+ };
@@ -15,6 +15,17 @@ import {
15
15
  BreadcrumbSeparator,
16
16
  } from "@alepha/ui/components/ui/breadcrumb";
17
17
  import { Button } from "@alepha/ui/components/ui/button";
18
+ import {
19
+ DropdownMenu,
20
+ DropdownMenuContent,
21
+ DropdownMenuGroup,
22
+ DropdownMenuItem,
23
+ DropdownMenuLabel,
24
+ DropdownMenuSub,
25
+ DropdownMenuSubContent,
26
+ DropdownMenuSubTrigger,
27
+ DropdownMenuTrigger,
28
+ } from "@alepha/ui/components/ui/dropdown-menu";
18
29
  import {
19
30
  HoverCard,
20
31
  HoverCardContent,
@@ -221,6 +232,7 @@ function renderNavIcon(icon: NavItem["icon"], className: string): ReactNode {
221
232
 
222
233
  function SidebarNavItem(props: { item: NavItem }) {
223
234
  const { item } = props;
235
+ const { state, isMobile } = useSidebar();
224
236
  const children = item.children;
225
237
  const isGroup = !!children && children.length > 0;
226
238
  const hasActive = isGroup && hasActiveDescendant(item);
@@ -302,6 +314,55 @@ function SidebarNavItem(props: { item: NavItem }) {
302
314
  );
303
315
  }
304
316
 
317
+ // Collapsed to icons, the expanded branch below is a dead button: it still
318
+ // flips `open`, but what `open` reveals is a `SidebarMenuSub`, which carries
319
+ // `group-data-[collapsible=icon]:hidden`. The group has no `href` either, so
320
+ // there is no fallback — every child is simply unreachable. A dropdown is the
321
+ // standard answer, and it belongs here rather than in any one app because
322
+ // this hits EVERY `NavItem` with children.
323
+ //
324
+ // Mobile is excluded: it uses the sheet, not icon mode, so the sub renders
325
+ // normally there.
326
+ if (isGroup && state === "collapsed" && !isMobile) {
327
+ return (
328
+ <SidebarMenuItem>
329
+ <DropdownMenu>
330
+ <DropdownMenuTrigger
331
+ render={
332
+ // No `tooltip` here on purpose. `SidebarMenuButton` turns itself
333
+ // into a `TooltipTrigger` when given one, and layering the
334
+ // dropdown trigger on top makes hover and click fight over the
335
+ // same element. The menu names itself with a label instead.
336
+ //
337
+ // `hasActive` joins `item.active` so the trigger still reads as
338
+ // current when a descendant is — collapsed, it is the only clue
339
+ // which group holds the open page.
340
+ <SidebarMenuButton isActive={item.active || hasActive} />
341
+ }
342
+ >
343
+ {renderNavIcon(item.icon, "size-4")}
344
+ <span className="flex-1 text-left">{item.label}</span>
345
+ <ChevronRight className="size-4" />
346
+ </DropdownMenuTrigger>
347
+ <DropdownMenuContent side="right" align="start" className="min-w-48">
348
+ {/*
349
+ The group wrapper is required, not cosmetic: `DropdownMenuLabel`
350
+ is Base UI's `Menu.GroupLabel`, which reads `MenuGroupContext` and
351
+ THROWS outside a `Menu.Group`. Nothing types this — the label
352
+ compiles fine, and the whole app-shell crashes at the first click
353
+ on the trigger, because the throw happens when the menu opens
354
+ rather than when it mounts.
355
+ */}
356
+ <DropdownMenuGroup>
357
+ <DropdownMenuLabel>{item.label}</DropdownMenuLabel>
358
+ <NavDropdownItems items={children} />
359
+ </DropdownMenuGroup>
360
+ </DropdownMenuContent>
361
+ </DropdownMenu>
362
+ </SidebarMenuItem>
363
+ );
364
+ }
365
+
305
366
  return (
306
367
  <SidebarMenuItem>
307
368
  <SidebarMenuButton
@@ -338,6 +399,67 @@ function SidebarNavItem(props: { item: NavItem }) {
338
399
  );
339
400
  }
340
401
 
402
+ /**
403
+ * The children of a collapsed nav group, as dropdown entries.
404
+ *
405
+ * Recurses through nested groups via `DropdownMenuSub` — `SidebarNavItem`
406
+ * recurses into itself for depth-2 groups in the expanded tree, and without the
407
+ * matching recursion here a nested group would be dead again one level down,
408
+ * which is the very bug this branch exists to fix.
409
+ *
410
+ * Badges are carried inline. `SidebarMenuBadge` is
411
+ * `group-data-[collapsible=icon]:hidden`, so a collapsed sidebar drops every
412
+ * count — and the count is usually why you opened the group.
413
+ */
414
+ function NavDropdownItems(props: { items: NavItem[] }) {
415
+ return (
416
+ <>
417
+ {props.items.map((child, ci) => {
418
+ const badge = child.badge != null && child.badge !== false && (
419
+ <span className="text-muted-foreground ml-auto pl-2 text-xs tabular-nums">
420
+ {child.badge}
421
+ </span>
422
+ );
423
+
424
+ if (child.children && child.children.length > 0) {
425
+ return (
426
+ <DropdownMenuSub key={child.href ?? ci}>
427
+ <DropdownMenuSubTrigger>
428
+ {renderNavIcon(child.icon, "size-4")}
429
+ <span>{child.label}</span>
430
+ </DropdownMenuSubTrigger>
431
+ <DropdownMenuSubContent>
432
+ <NavDropdownItems items={child.children} />
433
+ </DropdownMenuSubContent>
434
+ </DropdownMenuSub>
435
+ );
436
+ }
437
+
438
+ if (child.disabled) {
439
+ return (
440
+ <DropdownMenuItem key={child.href ?? ci} disabled>
441
+ {renderNavIcon(child.icon, "size-4")}
442
+ <span>{child.label}</span>
443
+ <Lock className="ml-auto size-3.5 opacity-70" />
444
+ </DropdownMenuItem>
445
+ );
446
+ }
447
+
448
+ return (
449
+ <DropdownMenuItem
450
+ key={child.href ?? ci}
451
+ render={<Link href={child.href ?? "#"} />}
452
+ >
453
+ {renderNavIcon(child.icon, "size-4")}
454
+ <span>{child.label}</span>
455
+ {badge}
456
+ </DropdownMenuItem>
457
+ );
458
+ })}
459
+ </>
460
+ );
461
+ }
462
+
341
463
  export interface NavGroup {
342
464
  label?: string;
343
465
  items: NavItem[];
@@ -2,6 +2,10 @@ import * as React from "react";
2
2
 
3
3
  void React;
4
4
 
5
+ import {
6
+ TurnstileWidget,
7
+ type TurnstileWidgetHandle,
8
+ } from "@alepha/ui/components/captcha/turnstile-widget";
5
9
  import { Control } from "@alepha/ui/components/control/control";
6
10
  import { iconFor } from "@alepha/ui/components/control-base/icon-hint";
7
11
  import { Alert, AlertDescription } from "@alepha/ui/components/ui/alert";
@@ -25,7 +29,7 @@ import { useForm, useFormState } from "alepha/react/form";
25
29
  import { useI18n } from "alepha/react/i18n";
26
30
  import { useRouter } from "alepha/react/router";
27
31
  import { AlertCircle, CheckCircle2, Info } from "lucide-react";
28
- import { type ReactNode, useState } from "react";
32
+ import { type ReactNode, useEffect, useRef, useState } from "react";
29
33
 
30
34
  export interface AuthResetPasswordProps {
31
35
  /**
@@ -78,15 +82,56 @@ export function AuthResetPassword(props: AuthResetPasswordProps) {
78
82
  const linkQ = [realmBit, redirectBit].filter(Boolean).join("&");
79
83
  const realmQuery = linkQ ? `?${linkQ}` : "";
80
84
 
85
+ /**
86
+ * Captcha, mirroring the registration screen.
87
+ *
88
+ * `createPasswordResetIntent` rejects a request with no token whenever the
89
+ * realm sets `captchaRequired` — it sends mail in our name, so it is gated
90
+ * exactly like registration. Without a widget here the screen could not
91
+ * satisfy that gate at all and every reset answered 400.
92
+ */
93
+ const captchaSiteKey = props.realmConfig.captchaSiteKey;
94
+ const [captchaToken, setCaptchaToken] = useState<string | undefined>();
95
+ const captchaRef = useRef<TurnstileWidgetHandle | null>(null);
96
+ /*
97
+ * `useForm` memoizes its handler at form-create time, so the handler closes
98
+ * over the *initial* `captchaToken` — `undefined` — and would post that
99
+ * forever. Mirror the live value into a ref the handler reads at submit
100
+ * time. Same reason, same fix as `auth-register.tsx`.
101
+ */
102
+ const captchaTokenRef = useRef<string | undefined>(undefined);
103
+ useEffect(() => {
104
+ captchaTokenRef.current = captchaToken;
105
+ }, [captchaToken]);
106
+
107
+ /**
108
+ * Turnstile tokens are single-use, and both the first send and every resend
109
+ * hit the same gated endpoint. Drop the spent token and re-arm the widget
110
+ * so the next request carries a fresh one rather than a replay the server
111
+ * will refuse.
112
+ */
113
+ const consumeCaptcha = () => {
114
+ if (!captchaSiteKey) return;
115
+ setCaptchaToken(undefined);
116
+ captchaRef.current?.reset();
117
+ };
118
+
81
119
  const emailForm = useForm({
82
120
  schema: resetPasswordRequestSchema,
83
121
  handler: async (data) => {
84
122
  setError(null);
85
- const intent = await userCtrl.createPasswordResetIntent({
86
- query: { userRealmName: props.realmConfig.realmName },
87
- body: { email: data.email },
88
- });
89
- setState({ step: "code", intent, email: data.email });
123
+ try {
124
+ const intent = await userCtrl.createPasswordResetIntent({
125
+ query: { userRealmName: props.realmConfig.realmName },
126
+ body: {
127
+ email: data.email,
128
+ captchaToken: captchaSiteKey ? captchaTokenRef.current : undefined,
129
+ },
130
+ });
131
+ setState({ step: "code", intent, email: data.email });
132
+ } finally {
133
+ consumeCaptcha();
134
+ }
90
135
  },
91
136
  });
92
137
 
@@ -140,7 +185,10 @@ export function AuthResetPassword(props: AuthResetPasswordProps) {
140
185
  try {
141
186
  const intent = await userCtrl.createPasswordResetIntent({
142
187
  query: { userRealmName: props.realmConfig.realmName },
143
- body: { email: state.email },
188
+ body: {
189
+ email: state.email,
190
+ captchaToken: captchaSiteKey ? captchaTokenRef.current : undefined,
191
+ },
144
192
  });
145
193
  setState((s) => ({ ...s, intent }));
146
194
  } catch (e) {
@@ -153,6 +201,7 @@ export function AuthResetPassword(props: AuthResetPasswordProps) {
153
201
  );
154
202
  } finally {
155
203
  setSubmitting(false);
204
+ consumeCaptcha();
156
205
  }
157
206
  };
158
207
 
@@ -213,7 +262,19 @@ export function AuthResetPassword(props: AuthResetPasswordProps) {
213
262
  input={emailForm.input.email}
214
263
  icon={iconFor("email")}
215
264
  />
216
- <Button type="submit" loading={emailSubmitting}>
265
+ {captchaSiteKey && (
266
+ <TurnstileWidget
267
+ ref={captchaRef}
268
+ siteKey={captchaSiteKey}
269
+ onToken={setCaptchaToken}
270
+ className="flex justify-center"
271
+ />
272
+ )}
273
+ <Button
274
+ type="submit"
275
+ loading={emailSubmitting}
276
+ disabled={!!captchaSiteKey && !captchaToken}
277
+ >
217
278
  {tr("auth.reset.sendCode", {
218
279
  default: "Send verification code",
219
280
  })}
@@ -258,10 +319,22 @@ export function AuthResetPassword(props: AuthResetPasswordProps) {
258
319
  <Button onClick={handleCodeSubmit} disabled={code.length !== 6}>
259
320
  {tr("auth.reset.continue", { default: "Continue" })}
260
321
  </Button>
322
+ {/* Resend calls the same gated endpoint as the first send,
323
+ and the token that got us here is already spent — so this
324
+ step needs its own challenge rather than reusing one. */}
325
+ {captchaSiteKey && (
326
+ <TurnstileWidget
327
+ ref={captchaRef}
328
+ siteKey={captchaSiteKey}
329
+ onToken={setCaptchaToken}
330
+ className="flex justify-center"
331
+ />
332
+ )}
261
333
  <Button
262
334
  variant="ghost"
263
335
  onClick={handleResend}
264
336
  loading={submitting}
337
+ disabled={!!captchaSiteKey && !captchaToken}
265
338
  >
266
339
  {tr("auth.reset.resend", { default: "Resend code" })}
267
340
  </Button>
@@ -16,7 +16,8 @@ import {
16
16
  TooltipTrigger,
17
17
  } from "@alepha/ui/components/ui/tooltip";
18
18
  import { useAuth } from "alepha/react/auth";
19
- import { LogIn, LogOut, Shield, User } from "lucide-react";
19
+ import { useRouter } from "alepha/react/router";
20
+ import { CircleUser, LogIn, LogOut, Shield, User } from "lucide-react";
20
21
  import type { ReactNode } from "react";
21
22
 
22
23
  export interface ButtonUserProps {
@@ -136,6 +137,7 @@ const DefaultMenu = (props: DefaultMenuProps) => {
136
137
  <>
137
138
  <Email />
138
139
  {props.onAdminClick && <AdminMenuItem onClick={props.onAdminClick} />}
140
+ <AccountMenuItem />
139
141
  <DropdownMenuSeparator />
140
142
  <LogoutMenuItem />
141
143
  </>
@@ -192,6 +194,60 @@ const AdminMenuItem = (props: ButtonUserAdminMenuItemProps) => {
192
194
  );
193
195
  };
194
196
 
197
+ export interface ButtonUserAccountMenuItemProps {
198
+ /**
199
+ * Where the item navigates. Defaults to pushing the `account` route, which
200
+ * is what `AccountRouter` registers — leave it alone unless you mounted the
201
+ * account area under a different name.
202
+ */
203
+ onClick?: () => void;
204
+
205
+ /**
206
+ * Item label. Defaults to `"User Account"`.
207
+ */
208
+ label?: string;
209
+ }
210
+
211
+ /**
212
+ * Link to the signed-in user's own account area.
213
+ *
214
+ * ⚠️ **It owns its destination, unlike {@link ButtonUser.AdminMenuItem}.**
215
+ * That asymmetry is deliberate. Every caller that hard-coded this navigation
216
+ * got it wrong the moment the account area moved — `router.push("me")` kept
217
+ * compiling after the `me` route ceased to exist, because `router.push` falls
218
+ * back to a plain `string` overload, and threw only when someone clicked it.
219
+ * Defaulting to the route `AccountRouter` actually registers removes the whole
220
+ * class of bug; `onClick` stays available for an application that mounted the
221
+ * area itself under another name.
222
+ *
223
+ * **It hides itself when no `account` route is registered**, so an application
224
+ * that never mounts `AccountRouter` gets no dead entry — the same "is the
225
+ * module actually there" question the router's own `can` gates answer, asked
226
+ * the only way a menu item can ask it.
227
+ */
228
+ const AccountMenuItem = (props: ButtonUserAccountMenuItemProps) => {
229
+ const auth = useAuth();
230
+ const router = useRouter<any>();
231
+
232
+ if (!auth.user) {
233
+ return null;
234
+ }
235
+ // No account area mounted → no entry, rather than one that throws on click.
236
+ if (
237
+ !props.onClick &&
238
+ !router.pages?.some((page: any) => page.name === "account")
239
+ ) {
240
+ return null;
241
+ }
242
+
243
+ return (
244
+ <DropdownMenuItem onClick={props.onClick ?? (() => router.push("account"))}>
245
+ <CircleUser className="size-4" />
246
+ {props.label ?? "User Account"}
247
+ </DropdownMenuItem>
248
+ );
249
+ };
250
+
195
251
  export interface ButtonUserLogoutMenuItemProps {
196
252
  /**
197
253
  * Item label. Defaults to `"Logout"`.
@@ -211,4 +267,5 @@ const LogoutMenuItem = (props: ButtonUserLogoutMenuItemProps) => {
211
267
 
212
268
  ButtonUser.Email = Email;
213
269
  ButtonUser.AdminMenuItem = AdminMenuItem;
270
+ ButtonUser.AccountMenuItem = AccountMenuItem;
214
271
  ButtonUser.LogoutMenuItem = LogoutMenuItem;
@@ -18,6 +18,7 @@ import {
18
18
  import { ControlDate } from "@alepha/ui/components/control-date/control-date";
19
19
  import { ControlNumber } from "@alepha/ui/components/control-number/control-number";
20
20
  import { ControlObject } from "@alepha/ui/components/control-object/control-object";
21
+ import { ControlPassword } from "@alepha/ui/components/control-password/control-password";
21
22
  import {
22
23
  ControlSelect,
23
24
  type SelectOption,
@@ -26,7 +27,6 @@ import {
26
27
  ControlUpload,
27
28
  type ControlUploadProps,
28
29
  } from "@alepha/ui/components/control-upload/control-upload";
29
- import { Button } from "@alepha/ui/components/ui/button";
30
30
  import { Input } from "@alepha/ui/components/ui/input";
31
31
  import { Switch } from "@alepha/ui/components/ui/switch";
32
32
  import { Textarea } from "@alepha/ui/components/ui/textarea";
@@ -39,7 +39,7 @@ import {
39
39
  useFormState,
40
40
  } from "alepha/react/form";
41
41
  import { resolveSchemaControl, type SchemaControl } from "alepha/react/ui";
42
- import { Check, Eye, EyeOff, X } from "lucide-react";
42
+ import { Check, X } from "lucide-react";
43
43
  import {
44
44
  type ComponentType,
45
45
  type HTMLAttributes,
@@ -102,9 +102,14 @@ export interface ControlProps {
102
102
  */
103
103
  select?: boolean;
104
104
  /**
105
- * Force a combobox (searchable select).
105
+ * Force a combobox (searchable select). Alias for `searchable: true`.
106
106
  */
107
107
  combobox?: boolean;
108
+ /**
109
+ * Force the select's search input on or off. Defaults to "auto" — on above
110
+ * ~20 options, off below.
111
+ */
112
+ searchable?: boolean;
108
113
  /**
109
114
  * Force a `<Segmented>` control (one option visible at a time).
110
115
  */
@@ -222,7 +227,10 @@ export interface ControlProps {
222
227
  */
223
228
  upload?:
224
229
  | boolean
225
- | Pick<ControlUploadProps, "multi" | "accept" | "maxSize" | "bucket">;
230
+ | Pick<
231
+ ControlUploadProps,
232
+ "multi" | "accept" | "maxSize" | "bucket" | "image"
233
+ >;
226
234
  }
227
235
 
228
236
  /**
@@ -376,6 +384,7 @@ export function Control(props: ControlProps) {
376
384
  description={merged.description ?? props.description}
377
385
  segmented={merged.segmented}
378
386
  combobox={merged.combobox}
387
+ searchable={merged.searchable}
379
388
  items={items as never}
380
389
  icon={resolveIcon(merged.icon)}
381
390
  disabled={merged.disabled}
@@ -505,7 +514,7 @@ export function Control(props: ControlProps) {
505
514
  if (isPassword) {
506
515
  return wrapWithSlots(
507
516
  merged,
508
- <PasswordControl
517
+ <ControlPassword
509
518
  id={meta.id}
510
519
  name={props.input.props.name}
511
520
  label={merged.label ?? meta.label}
@@ -667,69 +676,3 @@ const wrapWithSlots = (
667
676
  </div>
668
677
  );
669
678
  };
670
-
671
- interface PasswordControlProps {
672
- id?: string;
673
- name?: string;
674
- label?: string;
675
- description?: string;
676
- error?: string;
677
- required?: boolean;
678
- disabled?: boolean;
679
- autoComplete?: string;
680
- autoFocus?: boolean;
681
- inputProps?: HTMLAttributes<HTMLElement>;
682
- icon?: IconComponent;
683
- value: string;
684
- onChange: (v: string) => void;
685
- }
686
-
687
- function PasswordControl(props: PasswordControlProps) {
688
- const [reveal, setReveal] = useState(false);
689
- const Icon = props.icon;
690
- return (
691
- <FormField
692
- id={props.id}
693
- label={props.label}
694
- description={props.description}
695
- error={props.error}
696
- required={props.required}
697
- >
698
- <div className="relative">
699
- {Icon && (
700
- <Icon className="text-muted-foreground absolute top-1/2 left-3 size-4 -translate-y-1/2 pointer-events-none" />
701
- )}
702
- <Input
703
- {...props.inputProps}
704
- {...formFieldAriaProps({
705
- id: props.id,
706
- error: props.error,
707
- description: props.description,
708
- })}
709
- id={props.id}
710
- name={props.name}
711
- type={reveal ? "text" : "password"}
712
- autoComplete={props.autoComplete ?? "current-password"}
713
- autoFocus={props.autoFocus}
714
- disabled={props.disabled}
715
- value={props.value}
716
- onChange={(e) => props.onChange(e.target.value)}
717
- className={[props.inputProps?.className, Icon ? "pr-9 pl-9" : "pr-9"]
718
- .filter(Boolean)
719
- .join(" ")}
720
- />
721
- <Button
722
- type="button"
723
- variant="ghost"
724
- size="icon"
725
- disabled={props.disabled}
726
- onClick={() => setReveal((r) => !r)}
727
- aria-label={reveal ? "Hide password" : "Show password"}
728
- className="text-muted-foreground hover:text-foreground absolute top-1/2 right-1 size-7 -translate-y-1/2"
729
- >
730
- {reveal ? <EyeOff className="size-4" /> : <Eye className="size-4" />}
731
- </Button>
732
- </div>
733
- </FormField>
734
- );
735
- }