@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,126 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Control } from "@alepha/ui/components/control/control";
6
+ import { Button } from "@alepha/ui/components/ui/button";
7
+ import {
8
+ Dialog,
9
+ DialogContent,
10
+ DialogDescription,
11
+ DialogFooter,
12
+ DialogHeader,
13
+ DialogTitle,
14
+ } from "@alepha/ui/components/ui/dialog";
15
+ import { z } from "alepha";
16
+ import { useAction } from "alepha/react";
17
+ import { useForm } from "alepha/react/form";
18
+ import { useI18n } from "alepha/react/i18n";
19
+
20
+ export interface ParameterSaveDialogProps {
21
+ open: boolean;
22
+ onOpenChange: (open: boolean) => void;
23
+ /**
24
+ * Tags to pre-fill the input with (e.g. the current version's tags).
25
+ */
26
+ initialTags?: string[];
27
+ /**
28
+ * Persist the new version with the chosen tags and optional activation date.
29
+ * Should resolve once the save completes; the dialog stays open (with a busy
30
+ * button) until it does.
31
+ */
32
+ onConfirm: (meta: {
33
+ tags: string[];
34
+ activationDate?: string;
35
+ }) => void | Promise<void>;
36
+ }
37
+
38
+ /**
39
+ * Confirmation dialog shown when saving a new parameter version. Collects the
40
+ * free-form tags and an optional activation date (leave empty to apply
41
+ * immediately, set a future date to schedule a `next`/`future` version), then
42
+ * triggers the save.
43
+ */
44
+ export const ParameterSaveDialog = (props: ParameterSaveDialogProps) => {
45
+ const { tr } = useI18n();
46
+ const form = useForm(
47
+ {
48
+ schema: z.object({
49
+ tags: z.array(z.string()).optional(),
50
+ activationDate: z.string().meta({ format: "date-time" }).optional(),
51
+ }),
52
+ initialValues: { tags: props.initialTags ?? [] },
53
+ handler: async () => {},
54
+ },
55
+ [props.open],
56
+ );
57
+
58
+ const save = useAction(
59
+ {
60
+ handler: async () => {
61
+ await props.onConfirm({
62
+ tags: form.currentValues.tags ?? [],
63
+ activationDate: form.currentValues.activationDate || undefined,
64
+ });
65
+ props.onOpenChange(false);
66
+ },
67
+ },
68
+ [props.onConfirm, props.onOpenChange, form],
69
+ );
70
+
71
+ return (
72
+ <Dialog open={props.open} onOpenChange={props.onOpenChange}>
73
+ <DialogContent>
74
+ <DialogHeader>
75
+ <DialogTitle>
76
+ {tr("admin.parameters.saveDialogTitle", {
77
+ default: "Save new version",
78
+ })}
79
+ </DialogTitle>
80
+ <DialogDescription>
81
+ {tr("admin.parameters.saveDialogDescription", {
82
+ default:
83
+ "Optionally tag and schedule this version before saving.",
84
+ })}
85
+ </DialogDescription>
86
+ </DialogHeader>
87
+ <Control
88
+ input={form.input.tags}
89
+ combobox
90
+ createNewEntry
91
+ label={tr("admin.parameters.fieldTags", { default: "Tags" })}
92
+ placeholder={tr("admin.parameters.tagsPlaceholder", {
93
+ default: "Add tags…",
94
+ })}
95
+ />
96
+ <Control
97
+ input={form.input.activationDate}
98
+ datetime
99
+ label={tr("admin.parameters.fieldActivationDate", {
100
+ default: "Activate at",
101
+ })}
102
+ description={tr("admin.parameters.activationDateHint", {
103
+ default: "Leave empty to apply immediately.",
104
+ })}
105
+ />
106
+ <DialogFooter>
107
+ <Button
108
+ type="button"
109
+ variant="outline"
110
+ disabled={save.loading}
111
+ onClick={() => props.onOpenChange(false)}
112
+ >
113
+ {tr("admin.parameters.cancel", { default: "Cancel" })}
114
+ </Button>
115
+ <Button
116
+ type="button"
117
+ loading={save.loading}
118
+ onClick={() => save.run()}
119
+ >
120
+ {tr("admin.parameters.save", { default: "Save new version" })}
121
+ </Button>
122
+ </DialogFooter>
123
+ </DialogContent>
124
+ </Dialog>
125
+ );
126
+ };
@@ -0,0 +1,93 @@
1
+ import {
2
+ type ConfirmOptions,
3
+ useDialog,
4
+ } from "@alepha/ui/components/use-dialog/use-dialog";
5
+ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
6
+ import { useAction } from "alepha/react";
7
+ import type { DependencyList } from "react";
8
+
9
+ export interface UseConfirmedActionConfig<TArgs extends unknown[]> {
10
+ /**
11
+ * Confirmation dialog shown before the handler runs. Either static options or
12
+ * a function of the same args passed to `run` (e.g. to interpolate a name /
13
+ * count into the message).
14
+ */
15
+ confirm: ConfirmOptions | ((...args: TArgs) => ConfirmOptions);
16
+ /**
17
+ * The mutation. Runs only if the user confirms. Receives the same args as
18
+ * `run` (e.g. the row + a `refresh` callback from `AlephaTable`'s row/bulk
19
+ * action context). Errors surface via the global action-error toaster.
20
+ */
21
+ handler: (...args: TArgs) => void | Promise<void>;
22
+ /**
23
+ * Optional success toast shown after the handler resolves.
24
+ */
25
+ success?: string | ((...args: TArgs) => string);
26
+ }
27
+
28
+ export interface UseConfirmedActionReturn<TArgs extends unknown[]> {
29
+ run: (...args: TArgs) => Promise<void | undefined>;
30
+ loading: boolean;
31
+ }
32
+
33
+ /**
34
+ * The recurring admin pattern — confirm, then mutate, then toast — in one hook.
35
+ * Wraps {@link useAction} (so failures still emit `react:action:error` for the
36
+ * global toaster) plus `useDialog().confirm` and an optional success toast.
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * const remove = useConfirmedAction<[FileResource, () => void]>(
41
+ * {
42
+ * confirm: (file) => ({
43
+ * title: tr("admin.files.deleteTitle", { default: "Delete file" }),
44
+ * description: tr("admin.files.deleteConfirm", {
45
+ * default: `Delete "${file.name}"?`, args: [file.name],
46
+ * }),
47
+ * destructive: true,
48
+ * }),
49
+ * handler: async (file, refresh) => {
50
+ * await client.deleteFile({ params: { id: file.id } });
51
+ * refresh();
52
+ * },
53
+ * success: tr("admin.files.deleted", { default: "File deleted" }),
54
+ * },
55
+ * [client, tr],
56
+ * );
57
+ * // rowActions: onClick: (_f, { refresh }) => remove.run(file, refresh)
58
+ * ```
59
+ */
60
+ export function useConfirmedAction<TArgs extends unknown[]>(
61
+ config: UseConfirmedActionConfig<TArgs>,
62
+ deps: DependencyList,
63
+ ): UseConfirmedActionReturn<TArgs> {
64
+ const dialog = useDialog();
65
+ const toast = useToast();
66
+
67
+ const action = useAction<TArgs, void>(
68
+ {
69
+ handler: async (...argsWithCtx) => {
70
+ // useAction appends an ActionContext as the last argument — strip it so
71
+ // the caller's `confirm` / `handler` / `success` see only their args.
72
+ const args = argsWithCtx.slice(0, -1) as unknown as TArgs;
73
+ const options =
74
+ typeof config.confirm === "function"
75
+ ? config.confirm(...args)
76
+ : config.confirm;
77
+ const confirmed = await dialog.confirm(options);
78
+ if (!confirmed) return;
79
+ await config.handler(...args);
80
+ if (config.success != null) {
81
+ toast.success(
82
+ typeof config.success === "function"
83
+ ? config.success(...args)
84
+ : config.success,
85
+ );
86
+ }
87
+ },
88
+ },
89
+ deps,
90
+ );
91
+
92
+ return { run: action.run, loading: action.loading };
93
+ }
@@ -0,0 +1,92 @@
1
+ import { act, renderHook } from "@testing-library/react";
2
+ import { describe, expect, it } from "vitest";
3
+ import { useTableSelection } from "../use-table-selection.ts";
4
+
5
+ interface Row {
6
+ id: string;
7
+ name: string;
8
+ }
9
+
10
+ const page1: Row[] = [
11
+ { id: "1", name: "a" },
12
+ { id: "2", name: "b" },
13
+ { id: "3", name: "c" },
14
+ ];
15
+ const page2: Row[] = [
16
+ { id: "4", name: "d" },
17
+ { id: "5", name: "e" },
18
+ { id: "6", name: "f" },
19
+ ];
20
+ const rowKey = (r: Row) => r.id;
21
+
22
+ const setup = (data: Row[] = page1) =>
23
+ renderHook(({ rows }) => useTableSelection(rows, rowKey), {
24
+ initialProps: { rows: data },
25
+ });
26
+
27
+ describe("useTableSelection", () => {
28
+ it("keeps selected items across page changes", () => {
29
+ const { result, rerender } = setup();
30
+ act(() => result.current.toggleRow(page1[0]));
31
+ act(() => result.current.toggleRow(page1[1]));
32
+
33
+ rerender({ rows: page2 });
34
+ act(() => result.current.toggleRow(page2[0]));
35
+
36
+ // The pill count and the items handed to bulk actions must agree:
37
+ // 2 rows from page 1 + 1 row from page 2.
38
+ expect(result.current.selection.size).toBe(3);
39
+ expect(result.current.selectedItems.map(rowKey).sort()).toEqual([
40
+ "1",
41
+ "2",
42
+ "4",
43
+ ]);
44
+ });
45
+
46
+ it("toggleAll selects and deselects the current page only", () => {
47
+ const { result, rerender } = setup();
48
+ act(() => result.current.toggleRow(page1[0]));
49
+
50
+ rerender({ rows: page2 });
51
+ act(() => result.current.toggleAll());
52
+ expect(result.current.selection.size).toBe(4);
53
+
54
+ act(() => result.current.toggleAll());
55
+ expect(result.current.selection.size).toBe(1);
56
+ expect(result.current.selectedItems.map(rowKey)).toEqual(["1"]);
57
+ });
58
+
59
+ it("computes allSelected/someSelected against the current page", () => {
60
+ const { result, rerender } = setup();
61
+ act(() => result.current.toggleAll());
62
+ expect(result.current.allSelected).toBe(true);
63
+ expect(result.current.someSelected).toBe(false);
64
+
65
+ rerender({ rows: page2 });
66
+ expect(result.current.allSelected).toBe(false);
67
+ expect(result.current.someSelected).toBe(false);
68
+
69
+ act(() => result.current.toggleRow(page2[0]));
70
+ expect(result.current.allSelected).toBe(false);
71
+ expect(result.current.someSelected).toBe(true);
72
+ });
73
+
74
+ it("clearSelection empties every page's selection", () => {
75
+ const { result, rerender } = setup();
76
+ act(() => result.current.toggleAll());
77
+ rerender({ rows: page2 });
78
+ act(() => result.current.toggleAll());
79
+ expect(result.current.selection.size).toBe(6);
80
+
81
+ act(() => result.current.clearSelection());
82
+ expect(result.current.selection.size).toBe(0);
83
+ expect(result.current.selectedItems).toEqual([]);
84
+ });
85
+
86
+ it("toggling a selected row removes it", () => {
87
+ const { result } = setup();
88
+ act(() => result.current.toggleRow(page1[0]));
89
+ act(() => result.current.toggleRow(page1[0]));
90
+ expect(result.current.selection.size).toBe(0);
91
+ });
92
+ });