@alepha/ui 0.25.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 (136) hide show
  1. package/README.md +12 -0
  2. package/components.json +20 -0
  3. package/package.json +85 -0
  4. package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
  5. package/src/components/admin/admin-audits.tsx +247 -0
  6. package/src/components/admin/admin-files.tsx +346 -0
  7. package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
  8. package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
  9. package/src/components/admin/admin-jobs.tsx +294 -0
  10. package/src/components/admin/admin-keys.tsx +162 -0
  11. package/src/components/admin/admin-notifications.tsx +130 -0
  12. package/src/components/admin/admin-page.tsx +24 -0
  13. package/src/components/admin/admin-parameters.tsx +864 -0
  14. package/src/components/admin/admin-payments.tsx +93 -0
  15. package/src/components/admin/admin-sessions.tsx +174 -0
  16. package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
  17. package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
  18. package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
  19. package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
  20. package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
  21. package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
  22. package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
  23. package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
  24. package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
  25. package/src/components/admin/admin-user-detail.tsx +606 -0
  26. package/src/components/admin/admin-users-roles-picker.tsx +126 -0
  27. package/src/components/admin/admin-users-status-filter.tsx +51 -0
  28. package/src/components/admin/admin-users.tsx +518 -0
  29. package/src/components/admin/diff-lines.spec.ts +58 -0
  30. package/src/components/admin/diff-lines.ts +58 -0
  31. package/src/components/admin/parameter-diff-dialog.tsx +119 -0
  32. package/src/components/admin/parameter-history-item.tsx +252 -0
  33. package/src/components/admin/parameter-json-dialog.tsx +93 -0
  34. package/src/components/admin/parameter-save-dialog.tsx +126 -0
  35. package/src/components/admin/use-confirmed-action.tsx +93 -0
  36. package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
  37. package/src/components/alepha-table/alepha-table.tsx +1158 -0
  38. package/src/components/alepha-table/use-table-selection.ts +95 -0
  39. package/src/components/app-shell/app-shell.tsx +568 -0
  40. package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
  41. package/src/components/auth/auth-login.tsx +382 -0
  42. package/src/components/auth/auth-register.tsx +786 -0
  43. package/src/components/auth/auth-reset-password.tsx +349 -0
  44. package/src/components/auth/auth-router.tsx +126 -0
  45. package/src/components/auth/auth-verify-email.tsx +179 -0
  46. package/src/components/auto-form/auto-form.tsx +867 -0
  47. package/src/components/brand-icon/brand-icon.tsx +104 -0
  48. package/src/components/button-dark/button-dark.tsx +78 -0
  49. package/src/components/button-language/button-language.tsx +98 -0
  50. package/src/components/button-theme/button-theme.tsx +148 -0
  51. package/src/components/button-user/button-user.tsx +214 -0
  52. package/src/components/captcha/turnstile-widget.tsx +157 -0
  53. package/src/components/control/control.tsx +735 -0
  54. package/src/components/control-array/control-array.tsx +700 -0
  55. package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
  56. package/src/components/control-base/field-i18n.ts +60 -0
  57. package/src/components/control-base/form-field.tsx +275 -0
  58. package/src/components/control-base/grid.tsx +59 -0
  59. package/src/components/control-base/icon-hint.tsx +64 -0
  60. package/src/components/control-date/control-date.tsx +190 -0
  61. package/src/components/control-number/control-number.tsx +136 -0
  62. package/src/components/control-object/control-object.tsx +200 -0
  63. package/src/components/control-select/control-select.tsx +774 -0
  64. package/src/components/control-upload/control-upload.tsx +475 -0
  65. package/src/components/file-image/file-image.tsx +52 -0
  66. package/src/components/language-toggle/language-toggle.tsx +66 -0
  67. package/src/components/markdown-view/markdown-view.css +114 -0
  68. package/src/components/markdown-view/markdown-view.tsx +92 -0
  69. package/src/components/nav-shell/nav-page.tsx +56 -0
  70. package/src/components/nav-shell/nav-shell.tsx +72 -0
  71. package/src/components/nav-shell/nav-tree-util.ts +62 -0
  72. package/src/components/nav-shell/spotlight.tsx +163 -0
  73. package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
  74. package/src/components/nav-shell/use-nav-entries.ts +101 -0
  75. package/src/components/nav-shell/use-nav-tree.ts +61 -0
  76. package/src/components/ui/accordion.tsx +77 -0
  77. package/src/components/ui/alert-dialog.tsx +186 -0
  78. package/src/components/ui/alert.tsx +75 -0
  79. package/src/components/ui/aspect-ratio.tsx +22 -0
  80. package/src/components/ui/avatar.tsx +106 -0
  81. package/src/components/ui/badge.tsx +51 -0
  82. package/src/components/ui/breadcrumb.tsx +121 -0
  83. package/src/components/ui/button-group.tsx +86 -0
  84. package/src/components/ui/button.tsx +83 -0
  85. package/src/components/ui/calendar.tsx +235 -0
  86. package/src/components/ui/card.tsx +102 -0
  87. package/src/components/ui/carousel.tsx +241 -0
  88. package/src/components/ui/chart.tsx +370 -0
  89. package/src/components/ui/checkbox.tsx +27 -0
  90. package/src/components/ui/collapsible.tsx +19 -0
  91. package/src/components/ui/combobox.tsx +298 -0
  92. package/src/components/ui/command.tsx +196 -0
  93. package/src/components/ui/context-menu.tsx +271 -0
  94. package/src/components/ui/dialog.tsx +153 -0
  95. package/src/components/ui/direction.tsx +4 -0
  96. package/src/components/ui/drawer.tsx +130 -0
  97. package/src/components/ui/dropdown-menu.tsx +269 -0
  98. package/src/components/ui/empty.tsx +100 -0
  99. package/src/components/ui/hover-card.tsx +50 -0
  100. package/src/components/ui/input-group.tsx +157 -0
  101. package/src/components/ui/input-otp.tsx +83 -0
  102. package/src/components/ui/input.tsx +19 -0
  103. package/src/components/ui/item.tsx +200 -0
  104. package/src/components/ui/kbd.tsx +26 -0
  105. package/src/components/ui/label.tsx +19 -0
  106. package/src/components/ui/menubar.tsx +283 -0
  107. package/src/components/ui/navigation-menu.tsx +170 -0
  108. package/src/components/ui/pagination.tsx +133 -0
  109. package/src/components/ui/popover.tsx +87 -0
  110. package/src/components/ui/progress.tsx +82 -0
  111. package/src/components/ui/radio-group.tsx +35 -0
  112. package/src/components/ui/resizable.tsx +49 -0
  113. package/src/components/ui/scroll-area.tsx +51 -0
  114. package/src/components/ui/segmented.tsx +232 -0
  115. package/src/components/ui/select.tsx +201 -0
  116. package/src/components/ui/separator.tsx +22 -0
  117. package/src/components/ui/sheet.tsx +133 -0
  118. package/src/components/ui/sidebar.tsx +723 -0
  119. package/src/components/ui/skeleton.tsx +13 -0
  120. package/src/components/ui/slider.tsx +51 -0
  121. package/src/components/ui/sonner.tsx +46 -0
  122. package/src/components/ui/spinner.tsx +15 -0
  123. package/src/components/ui/switch.tsx +29 -0
  124. package/src/components/ui/table.tsx +115 -0
  125. package/src/components/ui/tabs.tsx +79 -0
  126. package/src/components/ui/textarea.tsx +17 -0
  127. package/src/components/ui/toggle-group.tsx +86 -0
  128. package/src/components/ui/toggle.tsx +44 -0
  129. package/src/components/ui/tooltip.tsx +63 -0
  130. package/src/components/use-dialog/use-dialog.tsx +244 -0
  131. package/src/components/use-toast/use-toast.tsx +89 -0
  132. package/src/hooks/use-mobile.ts +21 -0
  133. package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
  134. package/src/lib/i18n-fr.ts +500 -0
  135. package/src/lib/utils.ts +6 -0
  136. package/src/styles.css +129 -0
@@ -0,0 +1,104 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { cn } from "@alepha/ui/lib/utils";
6
+ import type { SVGProps } from "react";
7
+
8
+ export interface BrandIconProps extends SVGProps<SVGSVGElement> {
9
+ /**
10
+ * Auth provider key (e.g. `"google"`, `"apple"`, `"github"`). Known brands
11
+ * render their logo; anything else falls back to a generic globe so new
12
+ * providers still show something sensible.
13
+ */
14
+ provider: string;
15
+ }
16
+
17
+ /**
18
+ * Theme-friendly auth-provider logo. GitHub and Apple are monochrome marks
19
+ * drawn with `fill="currentColor"`, so they inherit the surrounding text
20
+ * color and read on both light and dark surfaces. Google uses its official
21
+ * multicolor mark. Unknown providers fall back to a `currentColor` globe.
22
+ */
23
+ export function BrandIcon(props: BrandIconProps) {
24
+ const { provider, className, ...rest } = props;
25
+ const cls = cn("size-4 shrink-0", className);
26
+
27
+ switch (provider) {
28
+ case "google":
29
+ return (
30
+ <svg
31
+ viewBox="0 0 24 24"
32
+ className={cls}
33
+ role="img"
34
+ aria-label="Google"
35
+ {...rest}
36
+ >
37
+ <path
38
+ fill="#4285F4"
39
+ d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
40
+ />
41
+ <path
42
+ fill="#34A853"
43
+ d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
44
+ />
45
+ <path
46
+ fill="#FBBC05"
47
+ d="M5.84 14.1c-.22-.66-.35-1.36-.35-2.1s.13-1.44.35-2.1V7.06H2.18A11 11 0 0 0 1 12c0 1.77.43 3.45 1.18 4.94l3.66-2.84z"
48
+ />
49
+ <path
50
+ fill="#EA4335"
51
+ d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.06l3.66 2.84C6.71 7.3 9.14 5.38 12 5.38z"
52
+ />
53
+ </svg>
54
+ );
55
+
56
+ case "apple":
57
+ return (
58
+ <svg
59
+ viewBox="0 0 24 24"
60
+ className={cls}
61
+ fill="currentColor"
62
+ role="img"
63
+ aria-label="Apple"
64
+ {...rest}
65
+ >
66
+ <path d="M17.05 20.28c-.98.95-2.05.8-3.08.35-1.09-.46-2.09-.48-3.24 0-1.44.62-2.2.44-3.06-.35C2.79 15.25 3.51 7.59 9.05 7.31c1.35.07 2.29.74 3.08.8 1.18-.24 2.31-.93 3.57-.84 1.51.12 2.65.72 3.4 1.8-3.12 1.87-2.38 5.98.48 7.13-.57 1.5-1.31 2.99-2.51 4.09l-.02-.01M12.03 7.25c-.15-2.23 1.66-4.07 3.74-4.25.29 2.58-2.34 4.5-3.74 4.25z" />
67
+ </svg>
68
+ );
69
+
70
+ case "github":
71
+ return (
72
+ <svg
73
+ viewBox="0 0 24 24"
74
+ className={cls}
75
+ fill="currentColor"
76
+ role="img"
77
+ aria-label="GitHub"
78
+ {...rest}
79
+ >
80
+ <path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23a11.5 11.5 0 0 1 3-.405c1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" />
81
+ </svg>
82
+ );
83
+
84
+ default:
85
+ return (
86
+ <svg
87
+ viewBox="0 0 24 24"
88
+ className={cls}
89
+ fill="none"
90
+ stroke="currentColor"
91
+ strokeWidth={2}
92
+ strokeLinecap="round"
93
+ strokeLinejoin="round"
94
+ role="img"
95
+ aria-label={provider}
96
+ {...rest}
97
+ >
98
+ <circle cx="12" cy="12" r="10" />
99
+ <path d="M2 12h20" />
100
+ <path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z" />
101
+ </svg>
102
+ );
103
+ }
104
+ }
@@ -0,0 +1,78 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Button } from "@alepha/ui/components/ui/button";
6
+ import {
7
+ Tooltip,
8
+ TooltipContent,
9
+ TooltipTrigger,
10
+ } from "@alepha/ui/components/ui/tooltip";
11
+ import { useColorMode } from "alepha/react/ui";
12
+ import { Monitor, Moon, Sun } from "lucide-react";
13
+ import type { ReactNode } from "react";
14
+
15
+ export interface ButtonDarkProps {
16
+ /**
17
+ * Optional aria-label override. Defaults to `"Toggle color mode"`.
18
+ */
19
+ label?: string;
20
+ /**
21
+ * When `true`, the button cycles through three states `light → dark →
22
+ * system`. By default the button toggles strictly between `light` and
23
+ * `dark` using the resolved mode as the starting point.
24
+ */
25
+ withSystem?: boolean;
26
+ /**
27
+ * Visual variant. Defaults to `"ghost"` (minimal). Pass `"outline"` for a
28
+ * bordered toolbar look.
29
+ */
30
+ variant?: "ghost" | "outline";
31
+ }
32
+
33
+ const ICON: Record<"light" | "dark" | "system", ReactNode> = {
34
+ light: <Sun className="size-4" />,
35
+ dark: <Moon className="size-4" />,
36
+ system: <Monitor className="size-4" />,
37
+ };
38
+
39
+ const NEXT: Record<"light" | "dark" | "system", "light" | "dark" | "system"> = {
40
+ light: "dark",
41
+ dark: "system",
42
+ system: "light",
43
+ };
44
+
45
+ /**
46
+ * Color-mode toggle. Default is a two-state Sun ↔ Moon flip; opt into the
47
+ * three-state `light → dark → system` cycle with `withSystem`.
48
+ * Reads/writes the persisted UI cookie via `useColorMode()`.
49
+ */
50
+ export function ButtonDark(props: ButtonDarkProps) {
51
+ const { mode, resolved, setMode } = useColorMode();
52
+ const onClick = () => {
53
+ if (props.withSystem) {
54
+ setMode(NEXT[mode]);
55
+ } else {
56
+ setMode(resolved === "dark" ? "light" : "dark");
57
+ }
58
+ };
59
+ const iconKey = props.withSystem ? mode : resolved;
60
+ const label = props.label ?? "Toggle color mode";
61
+ return (
62
+ <Tooltip>
63
+ <TooltipTrigger
64
+ render={
65
+ <Button
66
+ variant={props.variant ?? "ghost"}
67
+ size="icon"
68
+ aria-label={label}
69
+ onClick={onClick}
70
+ />
71
+ }
72
+ >
73
+ {ICON[iconKey]}
74
+ </TooltipTrigger>
75
+ <TooltipContent>{label}</TooltipContent>
76
+ </Tooltip>
77
+ );
78
+ }
@@ -0,0 +1,98 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Button } from "@alepha/ui/components/ui/button";
6
+ import {
7
+ DropdownMenu,
8
+ DropdownMenuCheckboxItem,
9
+ DropdownMenuContent,
10
+ DropdownMenuTrigger,
11
+ } from "@alepha/ui/components/ui/dropdown-menu";
12
+ import {
13
+ Tooltip,
14
+ TooltipContent,
15
+ TooltipTrigger,
16
+ } from "@alepha/ui/components/ui/tooltip";
17
+ import { useI18n } from "alepha/react/i18n";
18
+ import { Languages } from "lucide-react";
19
+
20
+ export interface ButtonLanguageProps {
21
+ /**
22
+ * Optional aria-label override. Defaults to `"Switch language"`.
23
+ */
24
+ label?: string;
25
+ /**
26
+ * Visual variant. Defaults to `"ghost"` (minimal). Pass `"outline"` for a
27
+ * bordered toolbar look.
28
+ */
29
+ variant?: "ghost" | "outline";
30
+ }
31
+
32
+ /**
33
+ * Dropdown listing every language registered via `$dictionary`. Switches the
34
+ * active locale via `useI18n().setLang(code)`.
35
+ *
36
+ * Labels come from translation keys `language.<code>` (e.g. `language.en`,
37
+ * `language.fr`). If the key is missing, the raw code is shown — so adding a
38
+ * new language to the picker is a one-line `tr` entry per dictionary.
39
+ *
40
+ * Renders nothing when only one language is registered.
41
+ */
42
+ export function ButtonLanguage(props: ButtonLanguageProps) {
43
+ const i18n = useI18n();
44
+ const languages = i18n.languages;
45
+
46
+ if (languages.length <= 1) {
47
+ return null;
48
+ }
49
+
50
+ const label = props.label ?? "Switch language";
51
+ return (
52
+ <DropdownMenu>
53
+ <Tooltip>
54
+ <TooltipTrigger
55
+ render={
56
+ <DropdownMenuTrigger
57
+ render={
58
+ <Button
59
+ variant={props.variant ?? "ghost"}
60
+ size="icon"
61
+ aria-label={label}
62
+ />
63
+ }
64
+ />
65
+ }
66
+ >
67
+ <Languages className="size-4" />
68
+ </TooltipTrigger>
69
+ <TooltipContent>{label}</TooltipContent>
70
+ </Tooltip>
71
+ <DropdownMenuContent align="end">
72
+ {languages.map((code) => {
73
+ const translated = i18n.tr(`language.${code}` as never);
74
+ const label = translated === `language.${code}` ? code : translated;
75
+ return (
76
+ <DropdownMenuCheckboxItem
77
+ key={code}
78
+ checked={i18n.lang === code}
79
+ /*
80
+ * Checkbox items keep the menu open by default, which is right when
81
+ * you are ticking several things and wrong here: a language is a
82
+ * single choice, and the menu stayed hanging over the page after
83
+ * you made it. Closing on click also means the ticked state is
84
+ * something you see on reopening rather than a leftover panel.
85
+ */
86
+ closeOnClick
87
+ onCheckedChange={() => {
88
+ void i18n.setLang(code);
89
+ }}
90
+ >
91
+ {label}
92
+ </DropdownMenuCheckboxItem>
93
+ );
94
+ })}
95
+ </DropdownMenuContent>
96
+ </DropdownMenu>
97
+ );
98
+ }
@@ -0,0 +1,148 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Button } from "@alepha/ui/components/ui/button";
6
+ import {
7
+ DropdownMenu,
8
+ DropdownMenuContent,
9
+ DropdownMenuGroup,
10
+ DropdownMenuLabel,
11
+ DropdownMenuSeparator,
12
+ DropdownMenuTrigger,
13
+ } from "@alepha/ui/components/ui/dropdown-menu";
14
+ import {
15
+ Tooltip,
16
+ TooltipContent,
17
+ TooltipTrigger,
18
+ } from "@alepha/ui/components/ui/tooltip";
19
+ import { cn } from "@alepha/ui/lib/utils";
20
+ import { useStore } from "alepha/react";
21
+ import { uiThemeListAtom, useTheme } from "alepha/react/ui";
22
+ import { Check, Palette } from "lucide-react";
23
+ import { useEffect } from "react";
24
+
25
+ const FONT_LINK_ID = "alepha-theme-fonts";
26
+
27
+ export interface ButtonThemeProps {
28
+ /**
29
+ * Optional aria-label override. Defaults to `"Pick theme"`.
30
+ */
31
+ label?: string;
32
+ /**
33
+ * Optional dropdown header. Defaults to `"Themes"`.
34
+ */
35
+ heading?: string;
36
+ /**
37
+ * Visual variant. Defaults to `"ghost"` (minimal). Pass `"outline"` for a
38
+ * bordered toolbar look.
39
+ */
40
+ variant?: "ghost" | "outline";
41
+ }
42
+
43
+ /**
44
+ * Theme picker reading the available list from `uiThemeListAtom` and the
45
+ * selected id from `useTheme()`. Apps register their themes once at boot:
46
+ *
47
+ * ```ts
48
+ * alepha.store.set(uiThemeListAtom, [
49
+ * { id: "default", label: "Default" },
50
+ * { id: "claude", label: "Claude", swatch: [...], fontHref: "https://..." },
51
+ * ]);
52
+ * ```
53
+ *
54
+ * Selecting a theme with a `fontHref` lazily injects a single `<link>` into
55
+ * `<head>` (id `alepha-theme-fonts`); switching themes swaps it. No effect
56
+ * when the list has 0 or 1 entries.
57
+ */
58
+ export function ButtonTheme(props: ButtonThemeProps) {
59
+ const { theme, setTheme } = useTheme();
60
+ const [list] = useStore(uiThemeListAtom);
61
+ const themes = list ?? [];
62
+
63
+ useEffect(() => {
64
+ if (typeof document === "undefined") return;
65
+ const def = themes.find((t) => t.id === theme) ?? themes[0];
66
+ const existing = document.getElementById(FONT_LINK_ID);
67
+ if (!def?.fontHref) {
68
+ existing?.remove();
69
+ return;
70
+ }
71
+ if (existing && existing.getAttribute("href") === def.fontHref) {
72
+ return;
73
+ }
74
+ existing?.remove();
75
+ const link = document.createElement("link");
76
+ link.id = FONT_LINK_ID;
77
+ link.rel = "stylesheet";
78
+ link.href = def.fontHref;
79
+ document.head.appendChild(link);
80
+ }, [theme, themes]);
81
+
82
+ if (themes.length <= 1) {
83
+ return null;
84
+ }
85
+
86
+ const label = props.label ?? "Pick theme";
87
+ return (
88
+ <DropdownMenu>
89
+ <Tooltip>
90
+ <TooltipTrigger
91
+ render={
92
+ <DropdownMenuTrigger
93
+ render={
94
+ <Button
95
+ variant={props.variant ?? "ghost"}
96
+ size="icon"
97
+ aria-label={label}
98
+ />
99
+ }
100
+ />
101
+ }
102
+ >
103
+ <Palette className="size-4" />
104
+ </TooltipTrigger>
105
+ <TooltipContent>{label}</TooltipContent>
106
+ </Tooltip>
107
+ <DropdownMenuContent align="end" className="w-56">
108
+ <DropdownMenuGroup>
109
+ <DropdownMenuLabel>{props.heading ?? "Themes"}</DropdownMenuLabel>
110
+ <DropdownMenuSeparator />
111
+ {themes.map((t) => (
112
+ <button
113
+ key={t.id}
114
+ type="button"
115
+ onClick={() => setTheme(t.id)}
116
+ className={cn(
117
+ "hover:bg-accent flex w-full items-center gap-2.5 rounded-sm px-2 py-1.5 text-sm",
118
+ theme === t.id && "bg-accent",
119
+ )}
120
+ >
121
+ {t.swatch && <ThemeSwatch colors={t.swatch} />}
122
+ <span className="flex-1 text-left">{t.label}</span>
123
+ {theme === t.id && <Check className="size-3.5" />}
124
+ </button>
125
+ ))}
126
+ </DropdownMenuGroup>
127
+ </DropdownMenuContent>
128
+ </DropdownMenu>
129
+ );
130
+ }
131
+
132
+ interface ThemeSwatchProps {
133
+ colors: string[];
134
+ }
135
+
136
+ const ThemeSwatch = (props: ThemeSwatchProps) => {
137
+ return (
138
+ <div className="border-border grid size-6 shrink-0 grid-cols-2 grid-rows-2 gap-px overflow-hidden rounded-sm border bg-white p-px">
139
+ {props.colors.slice(0, 4).map((c, i) => (
140
+ <span
141
+ key={i}
142
+ className="block rounded-[1px]"
143
+ style={{ background: c }}
144
+ />
145
+ ))}
146
+ </div>
147
+ );
148
+ };
@@ -0,0 +1,214 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Button } from "@alepha/ui/components/ui/button";
6
+ import {
7
+ DropdownMenu,
8
+ DropdownMenuContent,
9
+ DropdownMenuItem,
10
+ DropdownMenuSeparator,
11
+ DropdownMenuTrigger,
12
+ } from "@alepha/ui/components/ui/dropdown-menu";
13
+ import {
14
+ Tooltip,
15
+ TooltipContent,
16
+ TooltipTrigger,
17
+ } from "@alepha/ui/components/ui/tooltip";
18
+ import { useAuth } from "alepha/react/auth";
19
+ import { LogIn, LogOut, Shield, User } from "lucide-react";
20
+ import type { ReactNode } from "react";
21
+
22
+ export interface ButtonUserProps {
23
+ /**
24
+ * Custom menu items rendered between the email header and the logout
25
+ * footer. When omitted, a default menu is rendered: email + admin (when
26
+ * permitted) + logout. When provided, the consumer is responsible for the
27
+ * full layout — use `ButtonUser.Email`, `ButtonUser.AdminMenuItem`,
28
+ * `ButtonUser.LogoutMenuItem` as building blocks.
29
+ */
30
+ children?: ReactNode;
31
+ /**
32
+ * Called when the user clicks the sign-in icon (logged-out state). When
33
+ * absent, the icon button is disabled.
34
+ */
35
+ onSignIn?: () => void;
36
+ /**
37
+ * Called when the user clicks the default "Admin Panel" menu item. Has no
38
+ * effect when `children` are provided. When absent, the admin item is
39
+ * hidden even if the user has the permission.
40
+ */
41
+ onAdminClick?: () => void;
42
+ /**
43
+ * Aria-label and tooltip text for the logged-out (sign-in) state.
44
+ * Defaults to `"Sign in"`.
45
+ */
46
+ signInLabel?: string;
47
+ /**
48
+ * Aria-label and tooltip text for the logged-in (account menu) state.
49
+ * Defaults to `"Account menu"`.
50
+ */
51
+ menuLabel?: string;
52
+ /**
53
+ * Visual variant. Defaults to `"ghost"` (minimal). Pass `"outline"` for a
54
+ * bordered toolbar look.
55
+ */
56
+ variant?: "ghost" | "outline";
57
+ }
58
+
59
+ /**
60
+ * Account button: shows a sign-in icon when logged out, a user icon with a
61
+ * dropdown menu when logged in. Reads auth state via `useAuth()`.
62
+ *
63
+ * @example
64
+ * // Default menu
65
+ * <ButtonUser onSignIn={() => router.push("login")} onAdminClick={() => router.push("admin")} />
66
+ *
67
+ * @example
68
+ * // Custom menu
69
+ * <ButtonUser onSignIn={() => router.push("login")}>
70
+ * <ButtonUser.Email />
71
+ * <ButtonUser.AdminMenuItem onClick={() => router.push("admin")} />
72
+ * <DropdownMenuItem onClick={() => router.push("me")}>Profile</DropdownMenuItem>
73
+ * <DropdownMenuSeparator />
74
+ * <ButtonUser.LogoutMenuItem />
75
+ * </ButtonUser>
76
+ */
77
+ export function ButtonUser(props: ButtonUserProps) {
78
+ const auth = useAuth();
79
+
80
+ if (!auth.user) {
81
+ const signInLabel = props.signInLabel ?? "Sign in";
82
+ return (
83
+ <Tooltip>
84
+ <TooltipTrigger
85
+ render={
86
+ <Button
87
+ variant={props.variant ?? "ghost"}
88
+ size="icon"
89
+ aria-label={signInLabel}
90
+ disabled={!props.onSignIn}
91
+ onClick={props.onSignIn}
92
+ />
93
+ }
94
+ >
95
+ <LogIn className="size-4" />
96
+ </TooltipTrigger>
97
+ <TooltipContent>{signInLabel}</TooltipContent>
98
+ </Tooltip>
99
+ );
100
+ }
101
+
102
+ const menuLabel = props.menuLabel ?? "Account menu";
103
+ return (
104
+ <DropdownMenu>
105
+ <Tooltip>
106
+ <TooltipTrigger
107
+ render={
108
+ <DropdownMenuTrigger
109
+ render={
110
+ <Button
111
+ variant={props.variant ?? "ghost"}
112
+ size="icon"
113
+ aria-label={menuLabel}
114
+ />
115
+ }
116
+ />
117
+ }
118
+ >
119
+ <User className="size-4" />
120
+ </TooltipTrigger>
121
+ <TooltipContent>{menuLabel}</TooltipContent>
122
+ </Tooltip>
123
+ <DropdownMenuContent align="end" className="w-56">
124
+ {props.children ?? <DefaultMenu onAdminClick={props.onAdminClick} />}
125
+ </DropdownMenuContent>
126
+ </DropdownMenu>
127
+ );
128
+ }
129
+
130
+ interface DefaultMenuProps {
131
+ onAdminClick?: () => void;
132
+ }
133
+
134
+ const DefaultMenu = (props: DefaultMenuProps) => {
135
+ return (
136
+ <>
137
+ <Email />
138
+ {props.onAdminClick && <AdminMenuItem onClick={props.onAdminClick} />}
139
+ <DropdownMenuSeparator />
140
+ <LogoutMenuItem />
141
+ </>
142
+ );
143
+ };
144
+
145
+ export interface ButtonUserEmailProps {
146
+ /**
147
+ * Optional fallback when the user has no email. Defaults to username, then id.
148
+ */
149
+ fallback?: string;
150
+ }
151
+
152
+ const Email = (props: ButtonUserEmailProps) => {
153
+ const auth = useAuth();
154
+ const user = auth.user as
155
+ | { email?: string; username?: string; id?: string }
156
+ | undefined;
157
+ if (!user) return null;
158
+ const text = user.email ?? user.username ?? props.fallback ?? user.id ?? null;
159
+ if (!text) return null;
160
+ return (
161
+ <div className="text-muted-foreground truncate px-2 py-1.5 text-xs">
162
+ {text}
163
+ </div>
164
+ );
165
+ };
166
+
167
+ export interface ButtonUserAdminMenuItemProps {
168
+ /**
169
+ * Called when the item is clicked.
170
+ */
171
+ onClick: () => void;
172
+ /**
173
+ * Item label. Defaults to `"Admin Panel"`.
174
+ */
175
+ label?: string;
176
+ /**
177
+ * Permission name checked via `useAuth().has(...)`. Defaults to
178
+ * `"admin:ui"`. The item is hidden when the check returns false.
179
+ */
180
+ permission?: string;
181
+ }
182
+
183
+ const AdminMenuItem = (props: ButtonUserAdminMenuItemProps) => {
184
+ const auth = useAuth();
185
+ const permission = props.permission ?? "admin:ui";
186
+ if (!auth.has(permission)) return null;
187
+ return (
188
+ <DropdownMenuItem onClick={props.onClick}>
189
+ <Shield className="size-4" />
190
+ {props.label ?? "Admin Panel"}
191
+ </DropdownMenuItem>
192
+ );
193
+ };
194
+
195
+ export interface ButtonUserLogoutMenuItemProps {
196
+ /**
197
+ * Item label. Defaults to `"Logout"`.
198
+ */
199
+ label?: string;
200
+ }
201
+
202
+ const LogoutMenuItem = (props: ButtonUserLogoutMenuItemProps) => {
203
+ const auth = useAuth();
204
+ return (
205
+ <DropdownMenuItem onClick={() => auth.logout()}>
206
+ <LogOut className="size-4" />
207
+ {props.label ?? "Logout"}
208
+ </DropdownMenuItem>
209
+ );
210
+ };
211
+
212
+ ButtonUser.Email = Email;
213
+ ButtonUser.AdminMenuItem = AdminMenuItem;
214
+ ButtonUser.LogoutMenuItem = LogoutMenuItem;