create-modoock-app 1.0.0 → 2.0.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 +68 -0
- package/dist/cli.js +112 -43
- package/package.json +22 -21
- package/template/.cursor/hooks/gate-ui-pack.mjs +108 -0
- package/template/.cursor/hooks.json +18 -0
- package/template/.cursor/rules/honey.mdc +11 -3
- package/template/AGENTS.md +13 -12
- package/template/README.md +225 -175
- package/template/app/(local)/components/page.tsx +3 -3
- package/template/app/(local)/design-system/page.tsx +2 -2
- package/template/components/layout/app-layout.tsx +16 -5
- package/template/components/layout/header.tsx +19 -1
- package/template/components/layout/side-nav.tsx +103 -30
- package/template/postcss.config.mjs +7 -7
- package/template/public/identity/full_logo_black.svg +26 -26
- package/template/public/identity/full_logo_color.svg +37 -37
- package/template/public/identity/full_logo_white.svg +33 -33
- package/template/public/identity/logo_icon_black.svg +5 -5
- package/template/public/identity/logo_icon_color.svg +12 -12
- package/template/public/identity/logo_icon_white.svg +12 -12
- package/template/components/ui/action-stack.tsx +0 -42
- package/template/components/ui/badge.tsx +0 -43
- package/template/components/ui/button.tsx +0 -104
- package/template/components/ui/icon.tsx +0 -78
- package/template/components/ui/index.ts +0 -28
- package/template/components/ui/input.tsx +0 -376
- package/template/components/ui/loader.tsx +0 -78
- package/template/components/ui/metric-bar.tsx +0 -49
- package/template/components/ui/modal.tsx +0 -177
- package/template/components/ui/select.tsx +0 -458
- package/template/components/ui/stepper.tsx +0 -96
- package/template/components/ui/tab.tsx +0 -85
- package/template/components/ui/user-table.tsx +0 -806
- package/template/knowledge-base/design-system/components/action-stack.mdc +0 -17
- package/template/knowledge-base/design-system/components/badges.mdc +0 -16
- package/template/knowledge-base/design-system/components/buttons.mdc +0 -21
- package/template/knowledge-base/design-system/components/detail-header.mdc +0 -17
- package/template/knowledge-base/design-system/components/dropdowns.mdc +0 -12
- package/template/knowledge-base/design-system/components/info-list.mdc +0 -17
- package/template/knowledge-base/design-system/components/inputs.mdc +0 -23
- package/template/knowledge-base/design-system/components/menu.mdc +0 -20
- package/template/knowledge-base/design-system/components/modals.mdc +0 -24
- package/template/knowledge-base/design-system/components/selects.mdc +0 -39
- package/template/knowledge-base/design-system/components/stepper.mdc +0 -18
- package/template/knowledge-base/design-system/components/tables.mdc +0 -59
- package/template/knowledge-base/design-system/components/tabs.mdc +0 -17
- package/template/knowledge-base/design-system/components.mdc +0 -91
- package/template/knowledge-base/design-system/tokens.mdc +0 -24
- package/template/knowledge-base/examples/bad/README.md +0 -8
- package/template/knowledge-base/examples/good/README.md +0 -13
- package/template/knowledge-base/metadata/catalog.yaml +0 -245
- package/template/knowledge-base/patterns/components/reuse-existing.mdc +0 -26
- package/template/knowledge-base/patterns/data-fetching/local-data.mdc +0 -20
- package/template/knowledge-base/patterns/layouts/app-shell.mdc +0 -20
- package/template/knowledge-base/patterns/pages/data-table-page.mdc +0 -31
- package/template/knowledge-base/patterns/pages/workflow-page.mdc +0 -27
- package/template/knowledge-base/rules/accessibility/responsive.mdc +0 -31
- package/template/knowledge-base/rules/architecture/layout.mdc +0 -52
- package/template/knowledge-base/rules/architecture/single-screen.mdc +0 -62
- package/template/knowledge-base/rules/code-quality/jsx.mdc +0 -19
- package/template/knowledge-base/rules/global/naming.mdc +0 -12
- package/template/knowledge-base/rules/global/technology.mdc +0 -19
- package/template/knowledge-base/rules/global/ui-copy.mdc +0 -20
- package/template/knowledge-base/rules/performance/client.mdc +0 -20
- package/template/knowledge-base/rules/ui/information-density.mdc +0 -36
- package/template/knowledge-base/rules/ui/interaction.mdc +0 -47
- package/template/knowledge-base/rules/ui/simple-ui.mdc +0 -58
- package/template/knowledge-base/validation/accessibility.mdc +0 -13
- package/template/knowledge-base/validation/architecture.mdc +0 -10
- package/template/knowledge-base/validation/ast-grep/do-what-brooooooklyn-said.yml +0 -15
- package/template/knowledge-base/validation/ast-grep/no-nested-links.yml +0 -12
- package/template/knowledge-base/validation/ast-grep/rewrite-svg-attribute.yml +0 -19
- package/template/knowledge-base/validation/code-quality.mdc +0 -18
- package/template/knowledge-base/validation/performance.mdc +0 -11
- package/template/knowledge-base/validation/ui.mdc +0 -26
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
useId,
|
|
5
|
-
useRef,
|
|
6
|
-
useState,
|
|
7
|
-
type ChangeEvent,
|
|
8
|
-
type InputHTMLAttributes,
|
|
9
|
-
type ReactNode,
|
|
10
|
-
type Ref,
|
|
11
|
-
type TextareaHTMLAttributes,
|
|
12
|
-
} from "react";
|
|
13
|
-
import Icon from "./icon";
|
|
14
|
-
|
|
15
|
-
/** Visual validation state of the field. */
|
|
16
|
-
export type InputState = "valid" | "invalid";
|
|
17
|
-
|
|
18
|
-
const LABEL_CLASS =
|
|
19
|
-
"mb-inline flex items-center gap-micro text-label text-muted-foreground";
|
|
20
|
-
|
|
21
|
-
function RequiredMark() {
|
|
22
|
-
return (
|
|
23
|
-
<span aria-hidden="true" className="text-danger">
|
|
24
|
-
*
|
|
25
|
-
</span>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function FieldFeedback({ id, error }: { id: string; error?: string }) {
|
|
30
|
-
if (!error) return null;
|
|
31
|
-
return (
|
|
32
|
-
<p
|
|
33
|
-
id={id}
|
|
34
|
-
className="flex items-start gap-micro text-small text-danger-foreground [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0"
|
|
35
|
-
>
|
|
36
|
-
<Icon name="CircleAlert" variant="danger" aria-hidden="true" />
|
|
37
|
-
<span>{error}</span>
|
|
38
|
-
</p>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
43
|
-
/** Text label shown above the field. */
|
|
44
|
-
label?: string;
|
|
45
|
-
/** Optional leading icon/control inside the field. */
|
|
46
|
-
icon?: ReactNode;
|
|
47
|
-
/** Optional static adornment shown at the right of the field. */
|
|
48
|
-
trailingIcon?: ReactNode;
|
|
49
|
-
/** Visual validation state: tints the border and shows a feedback icon. */
|
|
50
|
-
state?: InputState;
|
|
51
|
-
/** Error message shown below the field (overrides `helper`). */
|
|
52
|
-
error?: string;
|
|
53
|
-
/** Unstyled helper text shown below the field. */
|
|
54
|
-
helper?: string;
|
|
55
|
-
/** Marks the field as required (renders `*` and sets `aria-required`). */
|
|
56
|
-
required?: boolean;
|
|
57
|
-
/** When set, shows a "clear" action as soon as the field has a value. */
|
|
58
|
-
clearable?: boolean;
|
|
59
|
-
/** Shorthand for a password field with a visibility toggle (same as `type="password"`). */
|
|
60
|
-
password?: boolean;
|
|
61
|
-
/** Shows a live character counter (uses `maxLength` when provided). */
|
|
62
|
-
counter?: boolean;
|
|
63
|
-
/** Extra callback fired after the field value is cleared. */
|
|
64
|
-
onClear?: () => void;
|
|
65
|
-
/** React 19 forwarded ref. */
|
|
66
|
-
ref?: Ref<HTMLInputElement>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default function Input({
|
|
70
|
-
label,
|
|
71
|
-
icon,
|
|
72
|
-
trailingIcon,
|
|
73
|
-
state,
|
|
74
|
-
error,
|
|
75
|
-
helper,
|
|
76
|
-
required = false,
|
|
77
|
-
clearable = false,
|
|
78
|
-
password = false,
|
|
79
|
-
counter = false,
|
|
80
|
-
onClear,
|
|
81
|
-
id,
|
|
82
|
-
type,
|
|
83
|
-
disabled,
|
|
84
|
-
maxLength,
|
|
85
|
-
value,
|
|
86
|
-
defaultValue,
|
|
87
|
-
onChange,
|
|
88
|
-
className = "",
|
|
89
|
-
ref,
|
|
90
|
-
...props
|
|
91
|
-
}: InputProps) {
|
|
92
|
-
const generatedId = useId();
|
|
93
|
-
const helperId = useId();
|
|
94
|
-
const errorId = useId();
|
|
95
|
-
const inputId = id ?? generatedId;
|
|
96
|
-
|
|
97
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
98
|
-
const [currentValue, setCurrentValue] = useState<string>(() => {
|
|
99
|
-
if (typeof value === "string") return value;
|
|
100
|
-
if (defaultValue != null) return String(defaultValue);
|
|
101
|
-
return "";
|
|
102
|
-
});
|
|
103
|
-
const [showPassword, setShowPassword] = useState(false);
|
|
104
|
-
|
|
105
|
-
const effectiveValue = typeof value === "string" ? value : currentValue;
|
|
106
|
-
|
|
107
|
-
const isPassword = password || type === "password";
|
|
108
|
-
const resolvedType = isPassword ? (showPassword ? "text" : "password") : type;
|
|
109
|
-
|
|
110
|
-
const hasClear = clearable && effectiveValue.length > 0 && !disabled;
|
|
111
|
-
|
|
112
|
-
/** A semantic feedback icon is shown unless a `trailingIcon` occupies the slot. */
|
|
113
|
-
const feedbackShown = (state !== undefined || Boolean(error)) && !trailingIcon;
|
|
114
|
-
|
|
115
|
-
const rightCount =
|
|
116
|
-
(feedbackShown ? 1 : 0) +
|
|
117
|
-
(trailingIcon ? 1 : 0) +
|
|
118
|
-
(hasClear ? 1 : 0) +
|
|
119
|
-
(isPassword ? 1 : 0);
|
|
120
|
-
|
|
121
|
-
const rightPad =
|
|
122
|
-
rightCount === 0
|
|
123
|
-
? ""
|
|
124
|
-
: rightCount === 1
|
|
125
|
-
? "pr-9"
|
|
126
|
-
: rightCount === 2
|
|
127
|
-
? "pr-[3.75rem]"
|
|
128
|
-
: "pr-[5.25rem]";
|
|
129
|
-
|
|
130
|
-
const describedBy =
|
|
131
|
-
[error ? errorId : helper ? helperId : undefined]
|
|
132
|
-
.filter(Boolean)
|
|
133
|
-
.join(" ") || undefined;
|
|
134
|
-
|
|
135
|
-
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
136
|
-
setCurrentValue(event.target.value);
|
|
137
|
-
onChange?.(event);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const handleClear = () => {
|
|
141
|
-
setCurrentValue("");
|
|
142
|
-
if (inputRef.current) {
|
|
143
|
-
const inputEl = inputRef.current;
|
|
144
|
-
const setter = Object.getOwnPropertyDescriptor(
|
|
145
|
-
window.HTMLInputElement.prototype,
|
|
146
|
-
"value",
|
|
147
|
-
)?.set;
|
|
148
|
-
setter?.call(inputEl, "");
|
|
149
|
-
inputEl.dispatchEvent(new Event("input", { bubbles: true }));
|
|
150
|
-
inputEl.focus();
|
|
151
|
-
}
|
|
152
|
-
onClear?.();
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const setRefs = (el: HTMLInputElement | null) => {
|
|
156
|
-
inputRef.current = el;
|
|
157
|
-
if (typeof ref === "function") ref(el);
|
|
158
|
-
else if (ref) ref.current = el;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const toneClass =
|
|
162
|
-
state === "valid"
|
|
163
|
-
? "border-success hover:border-success focus:border-success"
|
|
164
|
-
: state === "invalid" || error
|
|
165
|
-
? "border-danger hover:border-danger focus:border-danger"
|
|
166
|
-
: "";
|
|
167
|
-
|
|
168
|
-
return (
|
|
169
|
-
<div className="w-full">
|
|
170
|
-
{label && (
|
|
171
|
-
<label htmlFor={inputId} className={LABEL_CLASS}>
|
|
172
|
-
<span className="truncate">{label}</span>
|
|
173
|
-
{required && <RequiredMark />}
|
|
174
|
-
</label>
|
|
175
|
-
)}
|
|
176
|
-
|
|
177
|
-
<div className="relative w-full">
|
|
178
|
-
{icon && (
|
|
179
|
-
<span className="pointer-events-none absolute left-3 top-1/2 flex -translate-y-1/2 items-center text-muted-foreground [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0 [&_svg]:text-current">
|
|
180
|
-
{icon}
|
|
181
|
-
</span>
|
|
182
|
-
)}
|
|
183
|
-
|
|
184
|
-
<input
|
|
185
|
-
ref={setRefs}
|
|
186
|
-
id={inputId}
|
|
187
|
-
type={resolvedType}
|
|
188
|
-
disabled={disabled}
|
|
189
|
-
required={required}
|
|
190
|
-
aria-invalid={state === "invalid" || Boolean(error) || undefined}
|
|
191
|
-
aria-required={required || undefined}
|
|
192
|
-
aria-describedby={describedBy}
|
|
193
|
-
maxLength={maxLength}
|
|
194
|
-
value={value}
|
|
195
|
-
defaultValue={defaultValue}
|
|
196
|
-
onChange={handleChange}
|
|
197
|
-
className={`ds-input ${icon ? "pl-9" : ""} ${rightPad} ${toneClass} ${className}`}
|
|
198
|
-
{...props}
|
|
199
|
-
/>
|
|
200
|
-
|
|
201
|
-
{rightCount > 0 && (
|
|
202
|
-
<span className="absolute right-3 top-1/2 flex -translate-y-1/2 items-center gap-inline">
|
|
203
|
-
{state === "valid" && !trailingIcon && (
|
|
204
|
-
<Icon name="Check" variant="success" aria-hidden="true" />
|
|
205
|
-
)}
|
|
206
|
-
{!trailingIcon && (state === "invalid" || error) && (
|
|
207
|
-
<Icon name="CircleAlert" variant="danger" aria-hidden="true" />
|
|
208
|
-
)}
|
|
209
|
-
|
|
210
|
-
{trailingIcon && (
|
|
211
|
-
<span className="pointer-events-none text-muted-foreground [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0 [&_svg]:text-current">
|
|
212
|
-
{trailingIcon}
|
|
213
|
-
</span>
|
|
214
|
-
)}
|
|
215
|
-
|
|
216
|
-
{hasClear && (
|
|
217
|
-
<button
|
|
218
|
-
type="button"
|
|
219
|
-
onClick={handleClear}
|
|
220
|
-
aria-label="Effacer la valeur"
|
|
221
|
-
className="flex items-center rounded-small text-muted-foreground transition-colors hover:text-foreground [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0 [&_svg]:text-current"
|
|
222
|
-
>
|
|
223
|
-
<Icon name="X" aria-hidden="true" />
|
|
224
|
-
</button>
|
|
225
|
-
)}
|
|
226
|
-
|
|
227
|
-
{isPassword && (
|
|
228
|
-
<button
|
|
229
|
-
type="button"
|
|
230
|
-
onClick={() => setShowPassword((prev) => !prev)}
|
|
231
|
-
aria-label={
|
|
232
|
-
showPassword
|
|
233
|
-
? "Masquer le mot de passe"
|
|
234
|
-
: "Afficher le mot de passe"
|
|
235
|
-
}
|
|
236
|
-
className="flex items-center rounded-small text-muted-foreground transition-colors hover:text-foreground [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0 [&_svg]:text-current"
|
|
237
|
-
>
|
|
238
|
-
{showPassword ? (
|
|
239
|
-
<Icon name="EyeOff" aria-hidden="true" />
|
|
240
|
-
) : (
|
|
241
|
-
<Icon name="Eye" aria-hidden="true" />
|
|
242
|
-
)}
|
|
243
|
-
</button>
|
|
244
|
-
)}
|
|
245
|
-
</span>
|
|
246
|
-
)}
|
|
247
|
-
</div>
|
|
248
|
-
|
|
249
|
-
{(error || helper || counter) && (
|
|
250
|
-
<div className="mt-inline flex items-start justify-between gap-inline">
|
|
251
|
-
<div className="min-w-0">
|
|
252
|
-
{error ? (
|
|
253
|
-
<FieldFeedback id={errorId} error={error} />
|
|
254
|
-
) : helper ? (
|
|
255
|
-
<p id={helperId} className="text-small text-muted-foreground">
|
|
256
|
-
{helper}
|
|
257
|
-
</p>
|
|
258
|
-
) : null}
|
|
259
|
-
</div>
|
|
260
|
-
{counter && (
|
|
261
|
-
<span className="shrink-0 text-small text-muted-foreground">
|
|
262
|
-
{effectiveValue.length}
|
|
263
|
-
{typeof maxLength === "number" ? ` / ${maxLength}` : ""}
|
|
264
|
-
</span>
|
|
265
|
-
)}
|
|
266
|
-
</div>
|
|
267
|
-
)}
|
|
268
|
-
</div>
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
273
|
-
label?: string;
|
|
274
|
-
state?: InputState;
|
|
275
|
-
error?: string;
|
|
276
|
-
helper?: string;
|
|
277
|
-
required?: boolean;
|
|
278
|
-
counter?: boolean;
|
|
279
|
-
ref?: Ref<HTMLTextAreaElement>;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export function Textarea({
|
|
283
|
-
label,
|
|
284
|
-
state,
|
|
285
|
-
error,
|
|
286
|
-
helper,
|
|
287
|
-
required = false,
|
|
288
|
-
counter = false,
|
|
289
|
-
id,
|
|
290
|
-
disabled,
|
|
291
|
-
maxLength,
|
|
292
|
-
value,
|
|
293
|
-
defaultValue,
|
|
294
|
-
onChange,
|
|
295
|
-
className = "",
|
|
296
|
-
ref,
|
|
297
|
-
...props
|
|
298
|
-
}: TextareaProps) {
|
|
299
|
-
const generatedId = useId();
|
|
300
|
-
const helperId = useId();
|
|
301
|
-
const errorId = useId();
|
|
302
|
-
const textareaId = id ?? generatedId;
|
|
303
|
-
|
|
304
|
-
const [currentValue, setCurrentValue] = useState<string>(() => {
|
|
305
|
-
if (typeof value === "string") return value;
|
|
306
|
-
if (defaultValue != null) return String(defaultValue);
|
|
307
|
-
return "";
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
const effectiveValue = typeof value === "string" ? value : currentValue;
|
|
311
|
-
|
|
312
|
-
const describedBy =
|
|
313
|
-
[error ? errorId : helper ? helperId : undefined]
|
|
314
|
-
.filter(Boolean)
|
|
315
|
-
.join(" ") || undefined;
|
|
316
|
-
|
|
317
|
-
const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
|
|
318
|
-
setCurrentValue(event.target.value);
|
|
319
|
-
onChange?.(event);
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
const toneClass =
|
|
323
|
-
state === "valid"
|
|
324
|
-
? "border-success hover:border-success focus:border-success"
|
|
325
|
-
: state === "invalid" || error
|
|
326
|
-
? "border-danger hover:border-danger focus:border-danger"
|
|
327
|
-
: "";
|
|
328
|
-
|
|
329
|
-
return (
|
|
330
|
-
<div className="w-full">
|
|
331
|
-
{label && (
|
|
332
|
-
<label htmlFor={textareaId} className={LABEL_CLASS}>
|
|
333
|
-
<span className="truncate">{label}</span>
|
|
334
|
-
{required && <RequiredMark />}
|
|
335
|
-
</label>
|
|
336
|
-
)}
|
|
337
|
-
|
|
338
|
-
<textarea
|
|
339
|
-
ref={ref}
|
|
340
|
-
id={textareaId}
|
|
341
|
-
rows={4}
|
|
342
|
-
disabled={disabled}
|
|
343
|
-
required={required}
|
|
344
|
-
aria-invalid={state === "invalid" || Boolean(error) || undefined}
|
|
345
|
-
aria-required={required || undefined}
|
|
346
|
-
aria-describedby={describedBy}
|
|
347
|
-
maxLength={maxLength}
|
|
348
|
-
value={value}
|
|
349
|
-
defaultValue={defaultValue}
|
|
350
|
-
onChange={handleChange}
|
|
351
|
-
className={`ds-input resize-y ${toneClass} ${className}`}
|
|
352
|
-
{...props}
|
|
353
|
-
/>
|
|
354
|
-
|
|
355
|
-
{(error || helper || counter) && (
|
|
356
|
-
<div className="mt-inline flex items-start justify-between gap-inline">
|
|
357
|
-
<div className="min-w-0">
|
|
358
|
-
{error ? (
|
|
359
|
-
<FieldFeedback id={errorId} error={error} />
|
|
360
|
-
) : helper ? (
|
|
361
|
-
<p id={helperId} className="text-small text-muted-foreground">
|
|
362
|
-
{helper}
|
|
363
|
-
</p>
|
|
364
|
-
) : null}
|
|
365
|
-
</div>
|
|
366
|
-
{counter && (
|
|
367
|
-
<span className="shrink-0 text-small text-muted-foreground">
|
|
368
|
-
{effectiveValue.length}
|
|
369
|
-
{typeof maxLength === "number" ? ` / ${maxLength}` : ""}
|
|
370
|
-
</span>
|
|
371
|
-
)}
|
|
372
|
-
</div>
|
|
373
|
-
)}
|
|
374
|
-
</div>
|
|
375
|
-
);
|
|
376
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import Icon from "./icon";
|
|
2
|
-
import type { IconSize } from "./icon";
|
|
3
|
-
|
|
4
|
-
export interface LoaderProps {
|
|
5
|
-
/** Message displayed under the spinner (also announced to screen readers). */
|
|
6
|
-
message?: string;
|
|
7
|
-
/** Spinner size token (see Iconography). */
|
|
8
|
-
size?: IconSize;
|
|
9
|
-
/**
|
|
10
|
-
* - "overlay" (default): absolute overlay over the nearest positioned
|
|
11
|
-
* (relative) parent — modal body, card, section…
|
|
12
|
-
* - "inline": centered block in the normal flow — no positioning required.
|
|
13
|
-
*/
|
|
14
|
-
variant?: "overlay" | "inline";
|
|
15
|
-
/** Covers the whole viewport (fixed) — use for full-page data loading. */
|
|
16
|
-
fullScreen?: boolean;
|
|
17
|
-
className?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Chargement réutilisable — même visuel partout (page, modale, section…).
|
|
22
|
-
* - `<Loader fullScreen message="…" />` : couvre tout l'écran (page dont les
|
|
23
|
-
* données sont en cours de chargement) ;
|
|
24
|
-
* - `<Loader message="…" />` : superposition dans le parent positionné
|
|
25
|
-
* (`relative`) — corps de modale, carte, section ;
|
|
26
|
-
* - `<Loader variant="inline" message="…" />` : bloc centré dans le flux.
|
|
27
|
-
*/
|
|
28
|
-
export default function Loader({
|
|
29
|
-
message,
|
|
30
|
-
size = "large",
|
|
31
|
-
variant = "overlay",
|
|
32
|
-
fullScreen = false,
|
|
33
|
-
className = "",
|
|
34
|
-
}: LoaderProps) {
|
|
35
|
-
const content = (
|
|
36
|
-
<div
|
|
37
|
-
role="status"
|
|
38
|
-
aria-live="polite"
|
|
39
|
-
className="flex flex-col items-center gap-inline"
|
|
40
|
-
>
|
|
41
|
-
<Icon
|
|
42
|
-
name="LoaderCircle"
|
|
43
|
-
size={size}
|
|
44
|
-
variant="primary"
|
|
45
|
-
className="animate-spin"
|
|
46
|
-
aria-hidden="true"
|
|
47
|
-
/>
|
|
48
|
-
{message && <p className="text-small text-muted-foreground">{message}</p>}
|
|
49
|
-
<span className="sr-only">{message ?? "Chargement en cours"}</span>
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
if (fullScreen) {
|
|
54
|
-
return (
|
|
55
|
-
<div
|
|
56
|
-
className={`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm ${className}`}
|
|
57
|
-
>
|
|
58
|
-
{content}
|
|
59
|
-
</div>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (variant === "inline") {
|
|
64
|
-
return (
|
|
65
|
-
<div className={`flex justify-center py-component ${className}`}>
|
|
66
|
-
{content}
|
|
67
|
-
</div>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<div
|
|
73
|
-
className={`absolute inset-0 z-30 flex items-center justify-center bg-background/80 backdrop-blur-sm ${className}`}
|
|
74
|
-
>
|
|
75
|
-
{content}
|
|
76
|
-
</div>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
type MetricTone =
|
|
2
|
-
| "default"
|
|
3
|
-
| "primary"
|
|
4
|
-
| "secondary"
|
|
5
|
-
| "success"
|
|
6
|
-
| "warning"
|
|
7
|
-
| "danger"
|
|
8
|
-
| "info"
|
|
9
|
-
| "accent";
|
|
10
|
-
|
|
11
|
-
const TONE_BG: Record<MetricTone, string> = {
|
|
12
|
-
default: "bg-muted",
|
|
13
|
-
primary: "bg-primary",
|
|
14
|
-
secondary: "bg-border-strong",
|
|
15
|
-
success: "bg-success",
|
|
16
|
-
warning: "bg-warning",
|
|
17
|
-
danger: "bg-danger",
|
|
18
|
-
info: "bg-info",
|
|
19
|
-
accent: "bg-accent",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Barre de métrique compacte avec pourcentage.
|
|
24
|
-
* Réutilisée par les tableaux de métriques et fiches détail.
|
|
25
|
-
*/
|
|
26
|
-
export default function MetricBar({
|
|
27
|
-
value,
|
|
28
|
-
tone,
|
|
29
|
-
}: {
|
|
30
|
-
value: number;
|
|
31
|
-
tone: MetricTone;
|
|
32
|
-
}) {
|
|
33
|
-
const width = Math.min(100, Math.max(2, value));
|
|
34
|
-
return (
|
|
35
|
-
<div className="flex items-center gap-inline">
|
|
36
|
-
<div className="h-1.5 w-24 overflow-hidden rounded-full bg-surface-muted">
|
|
37
|
-
<div
|
|
38
|
-
className={`h-full rounded-full ${TONE_BG[tone]}`}
|
|
39
|
-
style={{ width: `${width}%` }}
|
|
40
|
-
/>
|
|
41
|
-
</div>
|
|
42
|
-
<span className="text-small text-muted-foreground">
|
|
43
|
-
{value.toFixed(0)} %
|
|
44
|
-
</span>
|
|
45
|
-
</div>
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { type MetricTone };
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
useEffect,
|
|
5
|
-
useId,
|
|
6
|
-
useRef,
|
|
7
|
-
type KeyboardEvent as ReactKeyboardEvent,
|
|
8
|
-
type ReactNode,
|
|
9
|
-
} from "react";
|
|
10
|
-
import { createPortal } from "react-dom";
|
|
11
|
-
import Icon from "./icon";
|
|
12
|
-
import ClickableButton from "./button";
|
|
13
|
-
|
|
14
|
-
interface ModalProps {
|
|
15
|
-
open: boolean;
|
|
16
|
-
title: string;
|
|
17
|
-
children: ReactNode;
|
|
18
|
-
onClose: () => void;
|
|
19
|
-
footer?: ReactNode;
|
|
20
|
-
primaryAction?: {
|
|
21
|
-
label: string;
|
|
22
|
-
onClick: () => void;
|
|
23
|
-
};
|
|
24
|
-
secondaryAction?: {
|
|
25
|
-
label: string;
|
|
26
|
-
onClick: () => void;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Selector matching every focusable element the dialog can own. */
|
|
31
|
-
const FOCUSABLE_SELECTOR = [
|
|
32
|
-
"a[href]",
|
|
33
|
-
"button:not([disabled])",
|
|
34
|
-
"textarea:not([disabled])",
|
|
35
|
-
"input:not([disabled])",
|
|
36
|
-
"select:not([disabled])",
|
|
37
|
-
'[tabindex]:not([tabindex="-1"])',
|
|
38
|
-
].join(", ");
|
|
39
|
-
|
|
40
|
-
/** Returns the focusable elements owned by a given dialog panel. */
|
|
41
|
-
function getFocusables(panel: HTMLElement | null): HTMLElement[] {
|
|
42
|
-
return panel
|
|
43
|
-
? Array.from(panel.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR))
|
|
44
|
-
: [];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default function Modal({
|
|
48
|
-
open,
|
|
49
|
-
title,
|
|
50
|
-
children,
|
|
51
|
-
onClose,
|
|
52
|
-
footer,
|
|
53
|
-
primaryAction,
|
|
54
|
-
secondaryAction,
|
|
55
|
-
}: ModalProps) {
|
|
56
|
-
// Unique, stable id used to bind the dialog label to its title.
|
|
57
|
-
const titleId = useId();
|
|
58
|
-
const panelRef = useRef<HTMLDivElement>(null);
|
|
59
|
-
// Element that had focus before the modal opened, restored on close.
|
|
60
|
-
const previouslyFocusedRef = useRef<HTMLElement | null>(null);
|
|
61
|
-
|
|
62
|
-
// Lock body scroll while open.
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
if (!open) return;
|
|
65
|
-
const previousOverflow = document.body.style.overflow;
|
|
66
|
-
document.body.style.overflow = "hidden";
|
|
67
|
-
return () => {
|
|
68
|
-
document.body.style.overflow = previousOverflow;
|
|
69
|
-
};
|
|
70
|
-
}, [open]);
|
|
71
|
-
|
|
72
|
-
// Close on Escape.
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
if (!open) return;
|
|
75
|
-
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
|
|
76
|
-
if (event.key === "Escape") onClose();
|
|
77
|
-
};
|
|
78
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
79
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
80
|
-
}, [open, onClose]);
|
|
81
|
-
|
|
82
|
-
// Move focus into the dialog on open and restore it on close.
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (!open) return;
|
|
85
|
-
previouslyFocusedRef.current =
|
|
86
|
-
document.activeElement instanceof HTMLElement
|
|
87
|
-
? document.activeElement
|
|
88
|
-
: null;
|
|
89
|
-
const focusables = getFocusables(panelRef.current);
|
|
90
|
-
(focusables[0] ?? panelRef.current)?.focus();
|
|
91
|
-
return () => {
|
|
92
|
-
previouslyFocusedRef.current?.focus?.();
|
|
93
|
-
previouslyFocusedRef.current = null;
|
|
94
|
-
};
|
|
95
|
-
}, [open]);
|
|
96
|
-
|
|
97
|
-
if (!open) return null;
|
|
98
|
-
|
|
99
|
-
// Keep Tab / Shift+Tab cycling within the dialog panel.
|
|
100
|
-
const handlePanelKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
|
|
101
|
-
if (event.key !== "Tab") return;
|
|
102
|
-
const focusables = getFocusables(panelRef.current);
|
|
103
|
-
if (focusables.length === 0) return;
|
|
104
|
-
|
|
105
|
-
const first = focusables[0];
|
|
106
|
-
const last = focusables[focusables.length - 1];
|
|
107
|
-
const active = document.activeElement;
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
!(event.shiftKey) &&
|
|
111
|
-
(!panelRef.current?.contains(active) || active === last)
|
|
112
|
-
) {
|
|
113
|
-
event.preventDefault();
|
|
114
|
-
first.focus();
|
|
115
|
-
} else if (
|
|
116
|
-
event.shiftKey &&
|
|
117
|
-
(!panelRef.current?.contains(active) || active === first)
|
|
118
|
-
) {
|
|
119
|
-
event.preventDefault();
|
|
120
|
-
last.focus();
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
return createPortal(
|
|
125
|
-
<div
|
|
126
|
-
className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4"
|
|
127
|
-
role="dialog"
|
|
128
|
-
aria-modal="true"
|
|
129
|
-
aria-labelledby={titleId}
|
|
130
|
-
onClick={onClose}
|
|
131
|
-
>
|
|
132
|
-
<div
|
|
133
|
-
ref={panelRef}
|
|
134
|
-
className="flex max-h-[90vh] w-full max-w-[560px] flex-col overflow-hidden rounded-large border border-border bg-surface shadow-lg"
|
|
135
|
-
onClick={(event) => event.stopPropagation()}
|
|
136
|
-
onKeyDown={handlePanelKeyDown}
|
|
137
|
-
>
|
|
138
|
-
<div className="flex shrink-0 items-center justify-between border-b border-border px-component py-control">
|
|
139
|
-
<h2 id={titleId} className="text-component-title text-foreground">
|
|
140
|
-
{title}
|
|
141
|
-
</h2>
|
|
142
|
-
<button
|
|
143
|
-
type="button"
|
|
144
|
-
onClick={onClose}
|
|
145
|
-
className="grid size-8 place-items-center rounded-small text-muted-foreground outline-none hover:bg-surface-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0 [&_svg]:text-current"
|
|
146
|
-
aria-label="Fermer"
|
|
147
|
-
>
|
|
148
|
-
<Icon name="X" aria-hidden="true" />
|
|
149
|
-
</button>
|
|
150
|
-
</div>
|
|
151
|
-
<div className="min-h-0 flex-1 overflow-y-auto overscroll-contain px-component py-control">
|
|
152
|
-
{children}
|
|
153
|
-
</div>
|
|
154
|
-
{(footer || primaryAction || secondaryAction) && (
|
|
155
|
-
<div className="flex shrink-0 items-center justify-end gap-inline border-t border-border px-component py-control">
|
|
156
|
-
{secondaryAction && (
|
|
157
|
-
<ClickableButton
|
|
158
|
-
type="button"
|
|
159
|
-
onClick={secondaryAction.onClick}
|
|
160
|
-
variant="ghost"
|
|
161
|
-
>
|
|
162
|
-
{secondaryAction.label}
|
|
163
|
-
</ClickableButton>
|
|
164
|
-
)}
|
|
165
|
-
{footer && footer}
|
|
166
|
-
{primaryAction && (
|
|
167
|
-
<ClickableButton onClick={primaryAction.onClick}>
|
|
168
|
-
{primaryAction.label}
|
|
169
|
-
</ClickableButton>
|
|
170
|
-
)}
|
|
171
|
-
</div>
|
|
172
|
-
)}
|
|
173
|
-
</div>
|
|
174
|
-
</div>,
|
|
175
|
-
document.body,
|
|
176
|
-
);
|
|
177
|
-
}
|