@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.
- package/README.md +12 -0
- package/components.json +20 -0
- package/package.json +85 -0
- package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
- package/src/components/admin/admin-audits.tsx +247 -0
- package/src/components/admin/admin-files.tsx +346 -0
- package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
- package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
- package/src/components/admin/admin-jobs.tsx +294 -0
- package/src/components/admin/admin-keys.tsx +162 -0
- package/src/components/admin/admin-notifications.tsx +130 -0
- package/src/components/admin/admin-page.tsx +24 -0
- package/src/components/admin/admin-parameters.tsx +864 -0
- package/src/components/admin/admin-payments.tsx +93 -0
- package/src/components/admin/admin-sessions.tsx +174 -0
- package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
- package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
- package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
- package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
- package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
- package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
- package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
- package/src/components/admin/admin-user-detail.tsx +606 -0
- package/src/components/admin/admin-users-roles-picker.tsx +126 -0
- package/src/components/admin/admin-users-status-filter.tsx +51 -0
- package/src/components/admin/admin-users.tsx +518 -0
- package/src/components/admin/diff-lines.spec.ts +58 -0
- package/src/components/admin/diff-lines.ts +58 -0
- package/src/components/admin/parameter-diff-dialog.tsx +119 -0
- package/src/components/admin/parameter-history-item.tsx +252 -0
- package/src/components/admin/parameter-json-dialog.tsx +93 -0
- package/src/components/admin/parameter-save-dialog.tsx +126 -0
- package/src/components/admin/use-confirmed-action.tsx +93 -0
- package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
- package/src/components/alepha-table/alepha-table.tsx +1158 -0
- package/src/components/alepha-table/use-table-selection.ts +95 -0
- package/src/components/app-shell/app-shell.tsx +568 -0
- package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
- package/src/components/auth/auth-login.tsx +382 -0
- package/src/components/auth/auth-register.tsx +786 -0
- package/src/components/auth/auth-reset-password.tsx +349 -0
- package/src/components/auth/auth-router.tsx +126 -0
- package/src/components/auth/auth-verify-email.tsx +179 -0
- package/src/components/auto-form/auto-form.tsx +867 -0
- package/src/components/brand-icon/brand-icon.tsx +104 -0
- package/src/components/button-dark/button-dark.tsx +78 -0
- package/src/components/button-language/button-language.tsx +98 -0
- package/src/components/button-theme/button-theme.tsx +148 -0
- package/src/components/button-user/button-user.tsx +214 -0
- package/src/components/captcha/turnstile-widget.tsx +157 -0
- package/src/components/control/control.tsx +735 -0
- package/src/components/control-array/control-array.tsx +700 -0
- package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
- package/src/components/control-base/field-i18n.ts +60 -0
- package/src/components/control-base/form-field.tsx +275 -0
- package/src/components/control-base/grid.tsx +59 -0
- package/src/components/control-base/icon-hint.tsx +64 -0
- package/src/components/control-date/control-date.tsx +190 -0
- package/src/components/control-number/control-number.tsx +136 -0
- package/src/components/control-object/control-object.tsx +200 -0
- package/src/components/control-select/control-select.tsx +774 -0
- package/src/components/control-upload/control-upload.tsx +475 -0
- package/src/components/file-image/file-image.tsx +52 -0
- package/src/components/language-toggle/language-toggle.tsx +66 -0
- package/src/components/markdown-view/markdown-view.css +114 -0
- package/src/components/markdown-view/markdown-view.tsx +92 -0
- package/src/components/nav-shell/nav-page.tsx +56 -0
- package/src/components/nav-shell/nav-shell.tsx +72 -0
- package/src/components/nav-shell/nav-tree-util.ts +62 -0
- package/src/components/nav-shell/spotlight.tsx +163 -0
- package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
- package/src/components/nav-shell/use-nav-entries.ts +101 -0
- package/src/components/nav-shell/use-nav-tree.ts +61 -0
- package/src/components/ui/accordion.tsx +77 -0
- package/src/components/ui/alert-dialog.tsx +186 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +121 -0
- package/src/components/ui/button-group.tsx +86 -0
- package/src/components/ui/button.tsx +83 -0
- package/src/components/ui/calendar.tsx +235 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +241 -0
- package/src/components/ui/chart.tsx +370 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +19 -0
- package/src/components/ui/combobox.tsx +298 -0
- package/src/components/ui/command.tsx +196 -0
- package/src/components/ui/context-menu.tsx +271 -0
- package/src/components/ui/dialog.tsx +153 -0
- package/src/components/ui/direction.tsx +4 -0
- package/src/components/ui/drawer.tsx +130 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +100 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +157 -0
- package/src/components/ui/input-otp.tsx +83 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +200 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/menubar.tsx +283 -0
- package/src/components/ui/navigation-menu.tsx +170 -0
- package/src/components/ui/pagination.tsx +133 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/radio-group.tsx +35 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +51 -0
- package/src/components/ui/segmented.tsx +232 -0
- package/src/components/ui/select.tsx +201 -0
- package/src/components/ui/separator.tsx +22 -0
- package/src/components/ui/sheet.tsx +133 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/sonner.tsx +46 -0
- package/src/components/ui/spinner.tsx +15 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toggle-group.tsx +86 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +63 -0
- package/src/components/use-dialog/use-dialog.tsx +244 -0
- package/src/components/use-toast/use-toast.tsx +89 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
- package/src/lib/i18n-fr.ts +500 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles.css +129 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
AlertDialog,
|
|
7
|
+
AlertDialogAction,
|
|
8
|
+
AlertDialogCancel,
|
|
9
|
+
AlertDialogContent,
|
|
10
|
+
AlertDialogDescription,
|
|
11
|
+
AlertDialogFooter,
|
|
12
|
+
AlertDialogHeader,
|
|
13
|
+
AlertDialogTitle,
|
|
14
|
+
} from "@alepha/ui/components/ui/alert-dialog";
|
|
15
|
+
import { Input } from "@alepha/ui/components/ui/input";
|
|
16
|
+
import { AlephaError } from "alepha";
|
|
17
|
+
import { useI18n } from "alepha/react/i18n";
|
|
18
|
+
import {
|
|
19
|
+
type ChangeEvent,
|
|
20
|
+
createContext,
|
|
21
|
+
type KeyboardEvent,
|
|
22
|
+
type ReactNode,
|
|
23
|
+
useCallback,
|
|
24
|
+
useContext,
|
|
25
|
+
useMemo,
|
|
26
|
+
useRef,
|
|
27
|
+
useState,
|
|
28
|
+
} from "react";
|
|
29
|
+
|
|
30
|
+
export interface ConfirmOptions {
|
|
31
|
+
title: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
confirmLabel?: string;
|
|
34
|
+
cancelLabel?: string;
|
|
35
|
+
/**
|
|
36
|
+
* When `true`, styles the confirm button as destructive.
|
|
37
|
+
*/
|
|
38
|
+
destructive?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface AlertOptions {
|
|
42
|
+
title: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
confirmLabel?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PromptOptions {
|
|
48
|
+
title: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
label?: string;
|
|
51
|
+
defaultValue?: string;
|
|
52
|
+
placeholder?: string;
|
|
53
|
+
confirmLabel?: string;
|
|
54
|
+
cancelLabel?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Optional inline validator. Return `null` for valid, or an error string.
|
|
57
|
+
*/
|
|
58
|
+
validate?: (value: string) => string | null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type Kind = "confirm" | "alert" | "prompt";
|
|
62
|
+
|
|
63
|
+
interface Pending {
|
|
64
|
+
kind: Kind;
|
|
65
|
+
options: ConfirmOptions | AlertOptions | PromptOptions;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface DialogApi {
|
|
69
|
+
confirm: (options: ConfirmOptions) => Promise<boolean>;
|
|
70
|
+
alert: (options: AlertOptions) => Promise<void>;
|
|
71
|
+
prompt: (options: PromptOptions) => Promise<string | null>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const Ctx = createContext<DialogApi | null>(null);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Provides imperative dialog primitives (`confirm`, `alert`, `prompt`)
|
|
78
|
+
* through {@link useDialog}. Mount once near the root:
|
|
79
|
+
* `<DialogProvider>{children}</DialogProvider>`.
|
|
80
|
+
*/
|
|
81
|
+
export function DialogProvider(props: { children: ReactNode }) {
|
|
82
|
+
const { tr } = useI18n();
|
|
83
|
+
const [pending, setPending] = useState<Pending | null>(null);
|
|
84
|
+
const [promptValue, setPromptValue] = useState("");
|
|
85
|
+
const [promptError, setPromptError] = useState<string | null>(null);
|
|
86
|
+
const resolverRef = useRef<((value: unknown) => void) | null>(null);
|
|
87
|
+
|
|
88
|
+
const open = <T,>(kind: Kind, options: Pending["options"]) =>
|
|
89
|
+
new Promise<T>((resolve) => {
|
|
90
|
+
resolverRef.current = resolve as (value: unknown) => void;
|
|
91
|
+
if (kind === "prompt") {
|
|
92
|
+
const o = options as PromptOptions;
|
|
93
|
+
setPromptValue(o.defaultValue ?? "");
|
|
94
|
+
setPromptError(null);
|
|
95
|
+
}
|
|
96
|
+
setPending({ kind, options });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const resolve = (value: unknown) => {
|
|
100
|
+
resolverRef.current?.(value);
|
|
101
|
+
resolverRef.current = null;
|
|
102
|
+
setPending(null);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const confirm = useCallback(
|
|
106
|
+
(options: ConfirmOptions) => open<boolean>("confirm", options),
|
|
107
|
+
[],
|
|
108
|
+
);
|
|
109
|
+
const alert = useCallback(
|
|
110
|
+
(options: AlertOptions) => open<void>("alert", options),
|
|
111
|
+
[],
|
|
112
|
+
);
|
|
113
|
+
const prompt = useCallback(
|
|
114
|
+
(options: PromptOptions) => open<string | null>("prompt", options),
|
|
115
|
+
[],
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const api = useMemo<DialogApi>(
|
|
119
|
+
() => ({ confirm, alert, prompt }),
|
|
120
|
+
[confirm, alert, prompt],
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const opts = pending?.options as Partial<
|
|
124
|
+
ConfirmOptions & AlertOptions & PromptOptions
|
|
125
|
+
>;
|
|
126
|
+
|
|
127
|
+
const handlePromptConfirm = () => {
|
|
128
|
+
const o = pending?.options as PromptOptions;
|
|
129
|
+
if (o?.validate) {
|
|
130
|
+
const err = o.validate(promptValue);
|
|
131
|
+
if (err) {
|
|
132
|
+
setPromptError(err);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
resolve(promptValue);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const cancelValue = pending?.kind === "prompt" ? null : false;
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<Ctx.Provider value={api}>
|
|
143
|
+
{props.children}
|
|
144
|
+
<AlertDialog
|
|
145
|
+
open={!!pending}
|
|
146
|
+
onOpenChange={(o: boolean) => {
|
|
147
|
+
if (!o) resolve(cancelValue);
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<AlertDialogContent>
|
|
151
|
+
<AlertDialogHeader>
|
|
152
|
+
<AlertDialogTitle>{opts?.title ?? ""}</AlertDialogTitle>
|
|
153
|
+
{opts?.description && (
|
|
154
|
+
<AlertDialogDescription>
|
|
155
|
+
{opts.description}
|
|
156
|
+
</AlertDialogDescription>
|
|
157
|
+
)}
|
|
158
|
+
</AlertDialogHeader>
|
|
159
|
+
{pending?.kind === "prompt" && (
|
|
160
|
+
<div className="flex flex-col gap-2">
|
|
161
|
+
{opts?.label && (
|
|
162
|
+
<label
|
|
163
|
+
htmlFor="alepha-dialog-prompt-input"
|
|
164
|
+
className="text-sm font-medium"
|
|
165
|
+
>
|
|
166
|
+
{opts.label}
|
|
167
|
+
</label>
|
|
168
|
+
)}
|
|
169
|
+
<Input
|
|
170
|
+
id="alepha-dialog-prompt-input"
|
|
171
|
+
autoFocus
|
|
172
|
+
value={promptValue}
|
|
173
|
+
placeholder={opts?.placeholder}
|
|
174
|
+
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
175
|
+
setPromptValue(e.target.value);
|
|
176
|
+
if (promptError) setPromptError(null);
|
|
177
|
+
}}
|
|
178
|
+
onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
|
|
179
|
+
if (e.key === "Enter") {
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
handlePromptConfirm();
|
|
182
|
+
}
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
{promptError && (
|
|
186
|
+
<p className="text-destructive text-xs">{promptError}</p>
|
|
187
|
+
)}
|
|
188
|
+
</div>
|
|
189
|
+
)}
|
|
190
|
+
<AlertDialogFooter>
|
|
191
|
+
{pending?.kind !== "alert" && (
|
|
192
|
+
<AlertDialogCancel onClick={() => resolve(cancelValue)}>
|
|
193
|
+
{opts?.cancelLabel ??
|
|
194
|
+
tr("useDialog.cancel", { default: "Cancel" })}
|
|
195
|
+
</AlertDialogCancel>
|
|
196
|
+
)}
|
|
197
|
+
<AlertDialogAction
|
|
198
|
+
onClick={() => {
|
|
199
|
+
if (pending?.kind === "prompt") {
|
|
200
|
+
handlePromptConfirm();
|
|
201
|
+
} else if (pending?.kind === "alert") {
|
|
202
|
+
resolve(undefined);
|
|
203
|
+
} else {
|
|
204
|
+
resolve(true);
|
|
205
|
+
}
|
|
206
|
+
}}
|
|
207
|
+
className={
|
|
208
|
+
(opts as ConfirmOptions)?.destructive
|
|
209
|
+
? "bg-destructive hover:bg-destructive/90 text-destructive-foreground"
|
|
210
|
+
: undefined
|
|
211
|
+
}
|
|
212
|
+
>
|
|
213
|
+
{opts?.confirmLabel ??
|
|
214
|
+
(pending?.kind === "alert"
|
|
215
|
+
? tr("useDialog.ok", { default: "OK" })
|
|
216
|
+
: tr("useDialog.confirm", { default: "Confirm" }))}
|
|
217
|
+
</AlertDialogAction>
|
|
218
|
+
</AlertDialogFooter>
|
|
219
|
+
</AlertDialogContent>
|
|
220
|
+
</AlertDialog>
|
|
221
|
+
</Ctx.Provider>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Imperative dialog API. Returns an object with:
|
|
227
|
+
*
|
|
228
|
+
* - `confirm({ title, description? })` → `Promise<boolean>`
|
|
229
|
+
* - `alert({ title, description? })` → `Promise<void>`
|
|
230
|
+
* - `prompt({ title, label?, defaultValue?, validate? })` → `Promise<string | null>`
|
|
231
|
+
*
|
|
232
|
+
* Requires {@link DialogProvider} mounted in the tree.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* const dialog = useDialog();
|
|
236
|
+
* if (await dialog.confirm({ title: "Delete?", destructive: true })) {
|
|
237
|
+
* await api.delete();
|
|
238
|
+
* }
|
|
239
|
+
*/
|
|
240
|
+
export function useDialog(): DialogApi {
|
|
241
|
+
const ctx = useContext(Ctx);
|
|
242
|
+
if (!ctx) throw new AlephaError("useDialog requires <DialogProvider>");
|
|
243
|
+
return ctx;
|
|
244
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { toast as sonner } from "sonner";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Intent buckets for `Toast.show`. Maps internally to icon + colour
|
|
9
|
+
* variants. Keep the vocabulary stable — call sites name *meaning*,
|
|
10
|
+
* not visual style.
|
|
11
|
+
*/
|
|
12
|
+
export type ToastIntent = "primary" | "success" | "info" | "warning" | "danger";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Cross-intent options. Intentionally a small, framework-defined shape
|
|
16
|
+
* (rather than re-exporting sonner's `ExternalToast`) so the underlying
|
|
17
|
+
* library can be swapped without touching consumer code. Add fields
|
|
18
|
+
* here as consumers genuinely need them.
|
|
19
|
+
*/
|
|
20
|
+
export interface ToastOptions {
|
|
21
|
+
/** Action button shown next to the toast. */
|
|
22
|
+
action?: { label: string; onClick: () => void };
|
|
23
|
+
/** Auto-dismiss delay in ms. */
|
|
24
|
+
duration?: number;
|
|
25
|
+
/** Secondary description line under the main message. */
|
|
26
|
+
description?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Toast API returned by {@link useToast}. Per-intent shortcuts cover
|
|
31
|
+
* the common case (`toast.success(msg)`); `show` is the generic entry
|
|
32
|
+
* for code that picks the intent dynamically.
|
|
33
|
+
*/
|
|
34
|
+
export interface Toast {
|
|
35
|
+
show(message: string, intent?: ToastIntent, options?: ToastOptions): void;
|
|
36
|
+
success(message: string, options?: ToastOptions): void;
|
|
37
|
+
error(message: string, options?: ToastOptions): void;
|
|
38
|
+
warning(message: string, options?: ToastOptions): void;
|
|
39
|
+
info(message: string, options?: ToastOptions): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Imperative toast hook. Requires a `<Toaster />` mounted somewhere in
|
|
44
|
+
* the tree (from `@alepha/ui/components/ui/sonner`).
|
|
45
|
+
*
|
|
46
|
+
* The underlying library (currently sonner) is an implementation
|
|
47
|
+
* detail — never exported from this module. Consumers depend on the
|
|
48
|
+
* `Toast` interface, not on sonner's API. This keeps the door open to
|
|
49
|
+
* swapping libraries or adding cross-cutting behavior (dedup,
|
|
50
|
+
* rate-limit, branded icons) without rippling through call sites.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const toast = useToast();
|
|
54
|
+
* toast.success("Saved");
|
|
55
|
+
* toast.error(err.message, { description: "Please try again" });
|
|
56
|
+
* toast.show(message, intent, { action: { label: "Undo", onClick } });
|
|
57
|
+
*/
|
|
58
|
+
// Bridge our shape to sonner's. ToastOptions is intentionally a
|
|
59
|
+
// strict subset; using sonner's own parameter type derives it without
|
|
60
|
+
// importing the name, so this file's type surface stays sonner-free.
|
|
61
|
+
type SonnerOptions = Parameters<typeof sonner.success>[1];
|
|
62
|
+
const toSonner = (options?: ToastOptions): SonnerOptions =>
|
|
63
|
+
options as SonnerOptions;
|
|
64
|
+
|
|
65
|
+
export function useToast(): Toast {
|
|
66
|
+
return {
|
|
67
|
+
show(message, intent = "primary", options) {
|
|
68
|
+
const opts = toSonner(options);
|
|
69
|
+
if (intent === "success") return sonner.success(message, opts);
|
|
70
|
+
if (intent === "danger") return sonner.error(message, opts);
|
|
71
|
+
if (intent === "warning") return sonner.warning(message, opts);
|
|
72
|
+
if (intent === "info") return sonner.info(message, opts);
|
|
73
|
+
// Neutral "primary" — sonner exposes `.message` for the unflavoured toast.
|
|
74
|
+
sonner.message(message, opts);
|
|
75
|
+
},
|
|
76
|
+
success(message, options) {
|
|
77
|
+
sonner.success(message, toSonner(options));
|
|
78
|
+
},
|
|
79
|
+
error(message, options) {
|
|
80
|
+
sonner.error(message, toSonner(options));
|
|
81
|
+
},
|
|
82
|
+
warning(message, options) {
|
|
83
|
+
sonner.warning(message, toSonner(options));
|
|
84
|
+
},
|
|
85
|
+
info(message, options) {
|
|
86
|
+
sonner.info(message, toSonner(options));
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
const MOBILE_BREAKPOINT = 768;
|
|
4
|
+
|
|
5
|
+
export function useIsMobile() {
|
|
6
|
+
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
|
|
7
|
+
undefined,
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
12
|
+
const onChange = () => {
|
|
13
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
14
|
+
};
|
|
15
|
+
mql.addEventListener("change", onChange);
|
|
16
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
17
|
+
return () => mql.removeEventListener("change", onChange);
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
return !!isMobile;
|
|
21
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { uiFr } from "../i18n-fr.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The French catalogue must cover every `tr()` key in the package, exactly.
|
|
8
|
+
*
|
|
9
|
+
* Without this, the catalogue rots silently and in one direction only: a
|
|
10
|
+
* component gains a key, nobody adds the translation, and the component falls
|
|
11
|
+
* back to its English default — which looks deliberate. That is how the whole
|
|
12
|
+
* back office came to be in English inside a French application in the first
|
|
13
|
+
* place. A default is not a translation, and nothing but a test can tell the
|
|
14
|
+
* difference.
|
|
15
|
+
*
|
|
16
|
+
* The check runs both ways. A missing key is an untranslated string; an extra one
|
|
17
|
+
* is a translation for something no component asks for any more, which is dead
|
|
18
|
+
* weight that makes the real gaps harder to see.
|
|
19
|
+
*/
|
|
20
|
+
const SRC = join(import.meta.dirname, "..", "..");
|
|
21
|
+
|
|
22
|
+
/** Every `tr("some.key"` or `tr(\`some.key\`` in the package sources. */
|
|
23
|
+
const collectKeys = (dir: string, found = new Set<string>()): Set<string> => {
|
|
24
|
+
for (const entry of readdirSync(dir)) {
|
|
25
|
+
const path = join(dir, entry);
|
|
26
|
+
if (statSync(path).isDirectory()) {
|
|
27
|
+
if (entry !== "__tests__") {
|
|
28
|
+
collectKeys(path, found);
|
|
29
|
+
}
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!/\.tsx?$/.test(entry)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const source = readFileSync(path, "utf8");
|
|
36
|
+
for (const match of source.matchAll(
|
|
37
|
+
/\btr\(\s*(?:`([a-zA-Z][\w.]*)`|"([a-zA-Z][\w.]*)")/g,
|
|
38
|
+
)) {
|
|
39
|
+
found.add((match[1] ?? match[2]) as string);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return found;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
describe("uiFr", () => {
|
|
46
|
+
const keys = collectKeys(SRC);
|
|
47
|
+
|
|
48
|
+
it("finds the package's translatable keys at all", () => {
|
|
49
|
+
// Guards the guard: a regex that silently matches nothing would make every
|
|
50
|
+
// assertion below pass for the wrong reason.
|
|
51
|
+
expect(keys.size).toBeGreaterThan(300);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("translates every key the components ask for", () => {
|
|
55
|
+
const missing = [...keys].filter((key) => !uiFr[key]).sort();
|
|
56
|
+
expect(missing).toEqual([]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("carries no translation for a key nothing uses", () => {
|
|
60
|
+
const extra = Object.keys(uiFr)
|
|
61
|
+
.filter((key) => !keys.has(key))
|
|
62
|
+
.sort();
|
|
63
|
+
expect(extra).toEqual([]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("leaves no value empty", () => {
|
|
67
|
+
const blank = Object.entries(uiFr)
|
|
68
|
+
.filter(([, value]) => value.trim() === "")
|
|
69
|
+
.map(([key]) => key);
|
|
70
|
+
expect(blank).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
});
|