create-modoock-app 1.0.1 → 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.
Files changed (75) hide show
  1. package/README.md +68 -237
  2. package/dist/cli.js +112 -43
  3. package/package.json +22 -22
  4. package/template/.cursor/hooks/gate-ui-pack.mjs +108 -0
  5. package/template/.cursor/hooks.json +18 -0
  6. package/template/.cursor/rules/honey.mdc +11 -3
  7. package/template/AGENTS.md +13 -12
  8. package/template/README.md +225 -175
  9. package/template/app/(local)/components/page.tsx +3 -3
  10. package/template/app/(local)/design-system/page.tsx +2 -2
  11. package/template/components/layout/app-layout.tsx +16 -5
  12. package/template/components/layout/header.tsx +19 -1
  13. package/template/components/layout/side-nav.tsx +103 -30
  14. package/template/postcss.config.mjs +7 -7
  15. package/template/public/identity/full_logo_black.svg +26 -26
  16. package/template/public/identity/full_logo_color.svg +37 -37
  17. package/template/public/identity/full_logo_white.svg +33 -33
  18. package/template/public/identity/logo_icon_black.svg +5 -5
  19. package/template/public/identity/logo_icon_color.svg +12 -12
  20. package/template/public/identity/logo_icon_white.svg +12 -12
  21. package/template/components/ui/action-stack.tsx +0 -42
  22. package/template/components/ui/badge.tsx +0 -43
  23. package/template/components/ui/button.tsx +0 -104
  24. package/template/components/ui/icon.tsx +0 -78
  25. package/template/components/ui/index.ts +0 -28
  26. package/template/components/ui/input.tsx +0 -376
  27. package/template/components/ui/loader.tsx +0 -78
  28. package/template/components/ui/metric-bar.tsx +0 -49
  29. package/template/components/ui/modal.tsx +0 -177
  30. package/template/components/ui/select.tsx +0 -458
  31. package/template/components/ui/stepper.tsx +0 -96
  32. package/template/components/ui/tab.tsx +0 -85
  33. package/template/components/ui/user-table.tsx +0 -806
  34. package/template/knowledge-base/design-system/components/action-stack.mdc +0 -17
  35. package/template/knowledge-base/design-system/components/badges.mdc +0 -16
  36. package/template/knowledge-base/design-system/components/buttons.mdc +0 -21
  37. package/template/knowledge-base/design-system/components/detail-header.mdc +0 -17
  38. package/template/knowledge-base/design-system/components/dropdowns.mdc +0 -12
  39. package/template/knowledge-base/design-system/components/info-list.mdc +0 -17
  40. package/template/knowledge-base/design-system/components/inputs.mdc +0 -23
  41. package/template/knowledge-base/design-system/components/menu.mdc +0 -20
  42. package/template/knowledge-base/design-system/components/modals.mdc +0 -24
  43. package/template/knowledge-base/design-system/components/selects.mdc +0 -39
  44. package/template/knowledge-base/design-system/components/stepper.mdc +0 -18
  45. package/template/knowledge-base/design-system/components/tables.mdc +0 -59
  46. package/template/knowledge-base/design-system/components/tabs.mdc +0 -17
  47. package/template/knowledge-base/design-system/components.mdc +0 -91
  48. package/template/knowledge-base/design-system/tokens.mdc +0 -24
  49. package/template/knowledge-base/examples/bad/README.md +0 -8
  50. package/template/knowledge-base/examples/good/README.md +0 -13
  51. package/template/knowledge-base/metadata/catalog.yaml +0 -245
  52. package/template/knowledge-base/patterns/components/reuse-existing.mdc +0 -26
  53. package/template/knowledge-base/patterns/data-fetching/local-data.mdc +0 -20
  54. package/template/knowledge-base/patterns/layouts/app-shell.mdc +0 -20
  55. package/template/knowledge-base/patterns/pages/data-table-page.mdc +0 -31
  56. package/template/knowledge-base/patterns/pages/workflow-page.mdc +0 -27
  57. package/template/knowledge-base/rules/accessibility/responsive.mdc +0 -31
  58. package/template/knowledge-base/rules/architecture/layout.mdc +0 -52
  59. package/template/knowledge-base/rules/architecture/single-screen.mdc +0 -62
  60. package/template/knowledge-base/rules/code-quality/jsx.mdc +0 -19
  61. package/template/knowledge-base/rules/global/naming.mdc +0 -12
  62. package/template/knowledge-base/rules/global/technology.mdc +0 -19
  63. package/template/knowledge-base/rules/global/ui-copy.mdc +0 -20
  64. package/template/knowledge-base/rules/performance/client.mdc +0 -20
  65. package/template/knowledge-base/rules/ui/information-density.mdc +0 -36
  66. package/template/knowledge-base/rules/ui/interaction.mdc +0 -47
  67. package/template/knowledge-base/rules/ui/simple-ui.mdc +0 -58
  68. package/template/knowledge-base/validation/accessibility.mdc +0 -13
  69. package/template/knowledge-base/validation/architecture.mdc +0 -10
  70. package/template/knowledge-base/validation/ast-grep/do-what-brooooooklyn-said.yml +0 -15
  71. package/template/knowledge-base/validation/ast-grep/no-nested-links.yml +0 -12
  72. package/template/knowledge-base/validation/ast-grep/rewrite-svg-attribute.yml +0 -19
  73. package/template/knowledge-base/validation/code-quality.mdc +0 -18
  74. package/template/knowledge-base/validation/performance.mdc +0 -11
  75. package/template/knowledge-base/validation/ui.mdc +0 -26
@@ -1,806 +0,0 @@
1
- "use client";
2
-
3
- import { useState } from "react";
4
- import type { ReactNode } from "react";
5
- import Icon, { type IconName } from "./icon";
6
- import ClickableButton from "./button";
7
-
8
-
9
- export interface Column<T> {
10
- key: keyof T;
11
- label: string;
12
- sortable?: boolean;
13
- render?: (row: T) => ReactNode;
14
- className?: string;
15
- sortFn?: (a: T, b: T) => number;
16
- }
17
-
18
- /** Action entry displayed inside the card action menus (mobile card view). */
19
- export interface CardAction {
20
- label: string;
21
- icon?: IconName;
22
- /** Destructive action styling. */
23
- danger?: boolean;
24
- /** Pre-rendered node used as the whole menu item. Used when an action is
25
- * derived from the table itself (e.g. the action column cell); it replaces
26
- * `label`/`icon` and keeps its own interactivity. */
27
- content?: ReactNode;
28
- onSelect: () => void;
29
- }
30
-
31
-
32
- export interface UserTableCardActions<T> {
33
- /** Actions globales du dropdown « Actions » — jamais recopiées sur une carte. */
34
- table?: CardAction[];
35
-
36
- selectAll?: CardAction;
37
- /** Actions personnelles de la ligne. Plusieurs → dropdown ; une seule → affichage direct. */
38
- row?: (row: T) => CardAction[];
39
- }
40
-
41
- export interface UserTableProps<T> {
42
- columns: Column<T>[];
43
- data: T[];
44
- rowsPerPage?: number;
45
- emptyMessage?: ReactNode;
46
- getRowKey?: (row: T, index: number) => React.Key;
47
-
48
- cardVisiblePairs?: number;
49
- /** Déclare des actions — voir `UserTableCardActions`.
50
- * `table` : dropdowns globaux « Actions » (pas recopiés sur chaque carte).
51
- * `row` : actions personnelles. Une seule s’affiche telle quelle ; plusieurs
52
- * vont dans un dropdown (colonne tableau et menu 3 points de la carte).
53
- * Sans `row`, la dernière colonne sans libellé est réutilisée. */
54
- cardActions?: UserTableCardActions<T>;
55
-
56
- selectedKeys?: Set<React.Key> | null;
57
- onToggleSelect?: ((rowKey: React.Key) => void) | null;
58
- className?: string;
59
- /** When true, the table is transposed: the first column shows row labels and
60
- * each subsequent column represents one item from `data`. The first column
61
- * header uses `transposeLabel` (or the first column's label), and each
62
- * remaining column header is rendered via `transposeHeader` if provided. */
63
- transpose?: boolean;
64
- /** Label for the first column (row headers) when `transpose` is true. */
65
- transposeLabel?: string;
66
- /** Renders the header for each data column when `transpose` is true. */
67
- transposeHeader?: (item: T) => React.ReactNode;
68
- }
69
-
70
- type SortDirection = "asc" | "desc";
71
-
72
- function defaultCompare<T>(a: T, b: T, key: keyof T): number {
73
- const aValue = a[key];
74
- const bValue = b[key];
75
-
76
- if (typeof aValue === "number" && typeof bValue === "number") {
77
- return aValue - bValue;
78
- }
79
-
80
- const aString = aValue == null ? "" : String(aValue);
81
- const bString = bValue == null ? "" : String(bValue);
82
-
83
- return aString.localeCompare(bString, undefined, {
84
- numeric: true,
85
- sensitivity: "base",
86
- });
87
- }
88
-
89
- interface CardActionsMenuProps {
90
- /** Global table actions (group "Tableau"). */
91
- tableActions: CardAction[];
92
- /** Row-specific actions (group "Cette ligne"). */
93
- rowActions: CardAction[];
94
- open: boolean;
95
- onToggle: () => void;
96
- onClose: () => void;
97
- /** Icon-only 3-dot trigger (card header) or labeled trigger (toolbars). */
98
- trigger: "kebab" | "labeled";
99
- /** Panel placement: below the trigger (default) or above it (bottom toolbar). */
100
- direction?: "down" | "up";
101
- }
102
-
103
-
104
- function CardActionsMenu({
105
- tableActions,
106
- rowActions,
107
- open,
108
- onToggle,
109
- onClose,
110
- trigger,
111
- direction = "down",
112
- }: CardActionsMenuProps) {
113
- const hasGroups = tableActions.length > 0 && rowActions.length > 0;
114
-
115
- const renderGroup = (actions: CardAction[]) =>
116
- actions.map((action, index) =>
117
- action.content ? (
118
- // Action dérivée d'une colonne du tableau : le nœud rendu (ex. bouton
119
- // « Voir ») est l'élément interactif ; le clic ferme le menu (bulle).
120
- <div
121
- key={action.label || `derived-${index}`}
122
- onClick={onClose}
123
- className="rounded-small focus-within:ring-primary"
124
- >
125
- {action.content}
126
- </div>
127
- ) : (
128
- <button
129
- key={action.label}
130
- type="button"
131
- role="menuitem"
132
- onClick={() => {
133
- onClose();
134
- action.onSelect();
135
- }}
136
- className={`flex items-center gap-inline whitespace-nowrap rounded-small px-component py-control text-left text-body-medium transition-colors hover:bg-surface-muted focus-visible:ring-primary ${
137
- action.danger ? "text-danger" : "text-foreground"
138
- }`}
139
- >
140
- {action.icon && (
141
- <Icon
142
- name={action.icon}
143
- size="small"
144
- variant={action.danger ? "danger" : "muted"}
145
- aria-hidden="true"
146
- />
147
- )}
148
- {action.label}
149
- </button>
150
- ),
151
- );
152
-
153
- return (
154
- <div className="relative">
155
- {trigger === "kebab" ? (
156
- <ClickableButton
157
- type="button"
158
- variant="ghost"
159
- size="icon"
160
- aria-label="Plus d'actions"
161
- aria-haspopup="menu"
162
- aria-expanded={open}
163
- onClick={onToggle}
164
- className="text-muted-foreground hover:text-primary focus-visible:ring-primary"
165
- >
166
- <Icon name="EllipsisVertical" aria-hidden="true" />
167
- </ClickableButton>
168
- ) : (
169
- <ClickableButton
170
- type="button"
171
- variant="secondary"
172
- size="sm"
173
- aria-haspopup="menu"
174
- aria-expanded={open}
175
- onClick={onToggle}
176
- leftIcon={<Icon name="EllipsisVertical" size="small" />}
177
- >
178
- Actions
179
- <Icon
180
- name="ChevronDown"
181
- size="small"
182
- className={`transition-transform ${open ? "rotate-180" : ""}`}
183
- />
184
- </ClickableButton>
185
- )}
186
- {open && (
187
- <>
188
- {/* Backdrop : ferme le menu au tap extérieur. */}
189
- <button
190
- type="button"
191
- aria-label="Fermer le menu"
192
- tabIndex={-1}
193
- onClick={onClose}
194
- className="fixed inset-0 z-40 cursor-default"
195
- />
196
- <div
197
- role="menu"
198
- className={`absolute right-0 z-50 flex min-w-40 max-w-[16rem] flex-col rounded-medium border border-border bg-surface shadow-lg ${
199
- direction === "up" ? "bottom-full mb-micro" : "top-full mt-micro"
200
- }`}
201
- >
202
- {hasGroups && (
203
- <p className="px-component pt-micro text-label text-muted-foreground">
204
- Tableau
205
- </p>
206
- )}
207
- {renderGroup(tableActions)}
208
- {hasGroups && <div className="mx-component my-micro h-px bg-border" />}
209
- {hasGroups && (
210
- <p className="px-component pt-micro text-label text-muted-foreground">
211
- Cette ligne
212
- </p>
213
- )}
214
- {renderGroup(rowActions)}
215
- </div>
216
- </>
217
- )}
218
- </div>
219
- );
220
- }
221
-
222
- function TableActionsBar({
223
- selectAllAction,
224
- allSelected,
225
- tableActions,
226
- open,
227
- direction = "down",
228
- onToggle,
229
- onClose,
230
- }: {
231
- selectAllAction?: CardAction;
232
- allSelected: boolean;
233
- tableActions: CardAction[];
234
- open: boolean;
235
- direction?: "down" | "up";
236
- onToggle: () => void;
237
- onClose: () => void;
238
- }) {
239
- return (
240
- <div className="flex items-center justify-end gap-inline">
241
- {selectAllAction ? (
242
- <ClickableButton
243
- type="button"
244
- variant="secondary"
245
- size="sm"
246
- aria-pressed={allSelected}
247
- onClick={selectAllAction.onSelect}
248
- leftIcon={
249
- selectAllAction.icon ? (
250
- <Icon
251
- name={selectAllAction.icon}
252
- size="small"
253
- variant={allSelected ? "primary" : "muted"}
254
- aria-hidden="true"
255
- />
256
- ) : undefined
257
- }
258
- >
259
- {selectAllAction.label}
260
- </ClickableButton>
261
- ) : null}
262
- {tableActions.length > 0 ? (
263
- <CardActionsMenu
264
- trigger="labeled"
265
- direction={direction}
266
- tableActions={tableActions}
267
- rowActions={[]}
268
- open={open}
269
- onToggle={onToggle}
270
- onClose={onClose}
271
- />
272
- ) : null}
273
- </div>
274
- );
275
- }
276
-
277
- export default function UserTable<T extends object>({
278
- columns,
279
- data,
280
- rowsPerPage = 8,
281
- emptyMessage = "Aucune donnée trouvée.",
282
- getRowKey = (_row, index) => index,
283
- cardVisiblePairs = 6,
284
- cardActions,
285
- selectedKeys = null,
286
- onToggleSelect = null,
287
- className,
288
- transpose = false,
289
- transposeLabel,
290
- transposeHeader,
291
- }: UserTableProps<T>) {
292
- const [sortKey, setSortKey] = useState<string | null>(null);
293
- const [sortDirection, setSortDirection] = useState<SortDirection>("asc");
294
- const [currentPage, setCurrentPage] = useState(1);
295
- // Vue carte (sous `md`) : clés des lignes dont la carte est dépliée
296
- // (toutes les paires label/valeur révélées par la bascule « Voir tout »).
297
- const [expandedCards, setExpandedCards] = useState<Set<React.Key>>(new Set());
298
- // Menus d'actions des cartes enrichies : un seul menu ouvert à la fois
299
- // (règle knowledge-base/design-system/components/dropdowns.mdc).
300
- const [openMenu, setOpenMenu] = useState<string | null>(null);
301
-
302
- const sortedData = [...data].sort((a, b) => {
303
- if (!sortKey) return 0;
304
-
305
- const column = columns.find((c) => String(c.key) === sortKey);
306
- if (!column) return 0;
307
-
308
- const comparison = column.sortFn
309
- ? column.sortFn(a, b)
310
- : defaultCompare(a, b, column.key);
311
-
312
- return sortDirection === "asc" ? comparison : -comparison;
313
- });
314
-
315
- const totalPages = Math.max(1, Math.ceil(sortedData.length / rowsPerPage));
316
- const safePage = Math.min(currentPage, totalPages);
317
- const startIndex = (safePage - 1) * rowsPerPage;
318
- const visibleData = sortedData.slice(startIndex, startIndex + rowsPerPage);
319
-
320
- const handleSort = (column: Column<T>) => {
321
- const key = String(column.key);
322
- if (key === sortKey) {
323
- setSortDirection((dir) => (dir === "asc" ? "desc" : "asc"));
324
- } else {
325
- setSortKey(key);
326
- setSortDirection("asc");
327
- }
328
- };
329
-
330
- const toggleCard = (rowKey: React.Key) => {
331
- setExpandedCards((previous) => {
332
- const next = new Set(previous);
333
- if (next.has(rowKey)) {
334
- next.delete(rowKey);
335
- } else {
336
- next.add(rowKey);
337
- }
338
- return next;
339
- });
340
- };
341
-
342
- const toggleMenu = (key: string) =>
343
- setOpenMenu((current) => (current === key ? null : key));
344
-
345
- const getCellValue = (row: T, column: Column<T>): ReactNode => {
346
- if (column.render) return column.render(row);
347
- const value = row[column.key];
348
- if (value == null) return "";
349
- if (typeof value === "object") return String(value);
350
- return value as ReactNode;
351
- };
352
-
353
- // Actions de ligne du menu carte : celles déclarées par la page
354
- // (`cardActions.row`) priment ; sinon la cellule de la colonne d'action
355
- // (dernière colonne sans libellé) est réutilisée telle quelle dans le menu,
356
- // pour que chaque tableau expose ses actions sans configuration par page.
357
- const resolveRowActions = (row: T): CardAction[] => {
358
- if (cardActions?.row) return cardActions.row(row);
359
- if (!actionColumn?.render) return [];
360
- const cell = getCellValue(row, actionColumn);
361
- if (cell == null || cell === false || cell === "") return [];
362
- return [{ label: "", content: cell, onSelect: () => {} }];
363
- };
364
-
365
- // Colonnes spéciales utilisées par la vue carte (sous `md`).
366
- const emptyLabelColumns = columns.filter(
367
- (column) => column.label.trim() === "",
368
- );
369
- const titleColumn =
370
- columns.find((column) => column.label.trim() !== "") ?? columns[0];
371
- const headerControlColumn =
372
- emptyLabelColumns.length > 1 ? emptyLabelColumns[0] : undefined;
373
- const actionColumn = emptyLabelColumns[emptyLabelColumns.length - 1] ?? undefined;
374
- const contentColumns = columns.filter(
375
- (column) =>
376
- column !== titleColumn &&
377
- column !== headerControlColumn &&
378
- column !== actionColumn,
379
- );
380
- const rowActionColumn: Column<T> | undefined = cardActions?.row
381
- ? (actionColumn ?? {
382
- key: columns[0]!.key,
383
- label: "",
384
- sortable: false,
385
- className: "w-12 text-right",
386
- })
387
- : actionColumn;
388
- const visibleColumns: Column<T>[] = cardActions?.row
389
- ? [...columns.filter((column) => column !== actionColumn), rowActionColumn!]
390
- : columns;
391
-
392
- // Vue carte (sous `md`) : cartes visuellement séparées, sélection à gauche,
393
- // menu 3 points par carte (actions de ligne uniquement) et dropdowns
394
- // « Actions » globaux au-dessus et en dessous de la liste. Les actions
395
- // `table` ne sont jamais recopiées dans le menu d'une carte.
396
- const tableActions = cardActions?.table ?? [];
397
- const selectAllAction = cardActions?.selectAll;
398
- // État « toutes les lignes sont sélectionnées » : pilote l'état enfoncé
399
- // (aria-pressed) du bouton « tout sélectionner » dédié ; la bascule
400
- // (second clic = désélection) est implémentée par la page dans `onSelect`.
401
- const allSelected =
402
- data.length > 0 &&
403
- data.every((row, index) => selectedKeys?.has(getRowKey(row, index)) ?? false);
404
- // Bouton de sélection automatique sur les cartes dès qu'il y a des actions
405
- // globales (ou un « tout sélectionner » dédié) et que la page fournit le
406
- // toggle de sélection.
407
- const hasSelectionControl =
408
- onToggleSelect !== null &&
409
- (tableActions.length > 0 || selectAllAction !== undefined);
410
- const columnCount = visibleColumns.length + (hasSelectionControl ? 1 : 0);
411
-
412
- const closeMenus = () => setOpenMenu(null);
413
-
414
- const renderPersonalActions = (row: T, rowKey: React.Key) => {
415
- const rowActions = resolveRowActions(row);
416
- if (rowActions.length > 1) {
417
- const menuKey = `row:${String(rowKey)}`;
418
- return (
419
- <div className="flex justify-end">
420
- <CardActionsMenu
421
- trigger="kebab"
422
- tableActions={[]}
423
- rowActions={rowActions}
424
- open={openMenu === menuKey}
425
- onToggle={() => toggleMenu(menuKey)}
426
- onClose={closeMenus}
427
- />
428
- </div>
429
- );
430
- }
431
- const action = rowActions[0];
432
- if (!action) return null;
433
- if (action.content) {
434
- return <div className="flex justify-end">{action.content}</div>;
435
- }
436
- return (
437
- <div className="flex justify-end">
438
- <ClickableButton
439
- type="button"
440
- variant={action.danger ? "danger" : "secondary"}
441
- size="sm"
442
- onClick={action.onSelect}
443
- >
444
- {action.label}
445
- </ClickableButton>
446
- </div>
447
- );
448
- };
449
-
450
- const SortIcon = () => (
451
- <Icon name="ChevronsUpDown" aria-hidden="true" />
452
- );
453
-
454
- const SortableHeader = ({ column }: { column: Column<T> }) => (
455
- <th className="text-left">
456
- <ClickableButton
457
- type="button"
458
- variant="bare"
459
- onClick={() => handleSort(column)}
460
- className="px-component py-control text-muted-foreground transition-colors hover:text-primary focus-visible:ring-primary"
461
- >
462
- <span className="text-label">{column.label}</span>
463
- <SortIcon />
464
- </ClickableButton>
465
- </th>
466
- );
467
-
468
- return (
469
- <div className={`flex flex-col overflow-hidden rounded-large border border-border bg-surface md:h-full ${className ?? ""}`}>
470
- {tableActions.length > 0 || selectAllAction ? (
471
- <div className="hidden shrink-0 border-b border-border px-component py-control md:flex md:justify-end">
472
- <TableActionsBar
473
- selectAllAction={selectAllAction}
474
- allSelected={allSelected}
475
- tableActions={tableActions}
476
- open={openMenu === "actions-desktop"}
477
- onToggle={() => toggleMenu("actions-desktop")}
478
- onClose={closeMenus}
479
- />
480
- </div>
481
- ) : null}
482
- <div className="hidden flex-1 overflow-auto md:flex">
483
- <table className="w-full border-collapse text-body">
484
- {transpose ? (
485
- <>
486
- <thead className="sticky top-0 z-10 bg-surface-muted">
487
- <tr className="border-b border-border">
488
- <th className="px-component py-control text-left text-label text-muted-foreground">
489
- {transposeLabel ?? columns[0]?.label ?? ""}
490
- </th>
491
- {data.map((item, i) => (
492
- <th key={i} className="px-component py-control text-left">
493
- {transposeHeader ? transposeHeader(item) : null}
494
- </th>
495
- ))}
496
- </tr>
497
- </thead>
498
- <tbody>
499
- {data.length === 0 ? (
500
- <tr>
501
- <td colSpan={1} className="px-component py-section text-center text-muted-foreground">
502
- {emptyMessage}
503
- </td>
504
- </tr>
505
- ) : (
506
- columns.slice(1).map((column) => (
507
- <tr key={String(column.key)} className="border-t border-border">
508
- <td className="px-component py-control text-label text-muted-foreground">
509
- {column.label}
510
- </td>
511
- {data.map((item, i) => (
512
- <td
513
- key={i}
514
- className={`px-component py-control ${
515
- column.className ?? "text-body-medium text-foreground"
516
- }`}
517
- >
518
- {getCellValue(item, column)}
519
- </td>
520
- ))}
521
- </tr>
522
- ))
523
- )}
524
- </tbody>
525
- </>
526
- ) : (
527
- <>
528
- <thead className="sticky top-0 z-10 bg-surface-muted">
529
- <tr className="border-b border-border">
530
- {hasSelectionControl ? (
531
- <th className="w-10 px-component py-control">
532
- {selectAllAction ? (
533
- <ClickableButton
534
- type="button"
535
- variant="ghost"
536
- size="icon"
537
- aria-label={selectAllAction.label}
538
- aria-pressed={allSelected}
539
- onClick={selectAllAction.onSelect}
540
- className="text-muted-foreground hover:text-primary focus-visible:ring-primary"
541
- >
542
- <Icon
543
- name={allSelected ? "SquareCheck" : "Square"}
544
- aria-hidden="true"
545
- />
546
- </ClickableButton>
547
- ) : null}
548
- </th>
549
- ) : null}
550
- {visibleColumns.map((column, columnIndex) =>
551
- column.sortable ? (
552
- <SortableHeader
553
- key={`col-${columnIndex}`}
554
- column={column}
555
- />
556
- ) : (
557
- <th
558
- key={`col-${columnIndex}`}
559
- className="px-component py-control text-left text-label text-muted-foreground"
560
- >
561
- {column.label}
562
- </th>
563
- ),
564
- )}
565
- </tr>
566
- </thead>
567
- <tbody>
568
- {visibleData.length === 0 ? (
569
- <tr>
570
- <td
571
- colSpan={columnCount}
572
- className="px-component py-section text-center text-muted-foreground"
573
- >
574
- {emptyMessage}
575
- </td>
576
- </tr>
577
- ) : (
578
- visibleData.map((row, rowIndex) => {
579
- const rowKey = getRowKey(row, startIndex + rowIndex);
580
- const selected = selectedKeys?.has(rowKey) ?? false;
581
- return (
582
- <tr
583
- key={rowKey}
584
- className="border-b border-border transition-colors last:border-b-0 hover:bg-surface-muted"
585
- >
586
- {hasSelectionControl ? (
587
- <td className="px-component py-control">
588
- <ClickableButton
589
- type="button"
590
- variant="ghost"
591
- size="icon"
592
- aria-pressed={selected}
593
- aria-label={
594
- selected
595
- ? "Retirer la sélection"
596
- : "Sélectionner"
597
- }
598
- onClick={() => onToggleSelect?.(rowKey)}
599
- className="text-muted-foreground hover:text-primary focus-visible:ring-primary"
600
- >
601
- <Icon
602
- name={selected ? "SquareCheck" : "Square"}
603
- aria-hidden="true"
604
- />
605
- </ClickableButton>
606
- </td>
607
- ) : null}
608
- {visibleColumns.map((column, columnIndex) => (
609
- <td
610
- key={`col-${columnIndex}`}
611
- className={`px-component py-control ${
612
- column.className ?? "text-body-medium text-foreground"
613
- }`}
614
- >
615
- {cardActions?.row && column === rowActionColumn ? (
616
- renderPersonalActions(row, rowKey)
617
- ) : (
618
- getCellValue(row, column)
619
- )}
620
- </td>
621
- ))}
622
- </tr>
623
- );
624
- })
625
- )}
626
- </tbody>
627
- </>
628
- )}
629
- </table>
630
- </div>
631
-
632
-
633
- <div className="md:hidden">
634
- {visibleData.length === 0 ? (
635
- <div className="px-component py-section text-center text-muted-foreground">
636
- {emptyMessage}
637
- </div>
638
- ) : (
639
- <div className="flex flex-col gap-component p-component">
640
- {tableActions.length > 0 || selectAllAction ? (
641
- <div className="flex justify-end">
642
- <TableActionsBar
643
- selectAllAction={selectAllAction}
644
- allSelected={allSelected}
645
- tableActions={tableActions}
646
- direction="down"
647
- open={openMenu === "actions-top"}
648
- onToggle={() => toggleMenu("actions-top")}
649
- onClose={closeMenus}
650
- />
651
- </div>
652
- ) : null}
653
- {visibleData.map((row, rowIndex) => {
654
- const rowKey = getRowKey(row, startIndex + rowIndex);
655
- const pairLimit = Math.max(1, cardVisiblePairs);
656
- const isExpanded = expandedCards.has(rowKey);
657
- const collapsible = contentColumns.length > pairLimit;
658
- const visiblePairs =
659
- collapsible && !isExpanded
660
- ? contentColumns.slice(0, pairLimit)
661
- : contentColumns;
662
- const rowActions = resolveRowActions(row);
663
- const menuKey = `card:${String(rowKey)}`;
664
-
665
- return (
666
- <article
667
- key={rowKey}
668
- className="flex flex-col overflow-hidden rounded-large border border-border bg-surface"
669
- >
670
- {/* Barre de titre — mêmes couleurs que l'en-tête du tableau. */}
671
- <div className="flex items-center gap-inline bg-surface-muted px-component py-control">
672
- {hasSelectionControl ? (
673
- <button
674
- type="button"
675
- onClick={() => onToggleSelect?.(rowKey)}
676
- aria-pressed={selectedKeys?.has(rowKey) ?? false}
677
- aria-label={
678
- selectedKeys?.has(rowKey)
679
- ? "Retirer la sélection"
680
- : "Sélectionner"
681
- }
682
- className="grid size-8 shrink-0 place-items-center rounded-small text-muted-foreground transition-colors hover:text-primary focus-visible:ring-primary"
683
- >
684
- <Icon
685
- name={selectedKeys?.has(rowKey) ? "SquareCheck" : "Square"}
686
- size="default"
687
- aria-hidden="true"
688
- />
689
- </button>
690
- ) : (
691
- headerControlColumn && (
692
- <div className="shrink-0">{getCellValue(row, headerControlColumn)}</div>
693
- )
694
- )}
695
- <p className="min-w-0 flex-1 text-component-title text-foreground">
696
- {getCellValue(row, titleColumn)}
697
- </p>
698
- {rowActions.length > 0 ? (
699
- <CardActionsMenu
700
- trigger="kebab"
701
- tableActions={[]}
702
- rowActions={rowActions}
703
- open={openMenu === menuKey}
704
- onToggle={() => toggleMenu(menuKey)}
705
- onClose={closeMenus}
706
- />
707
- ) : null}
708
- </div>
709
-
710
- {/* Lignes label/valeur — même style que les lignes du tableau. */}
711
- {visiblePairs.map((column) => (
712
- <div
713
- key={String(column.key)}
714
- className="flex items-center justify-between gap-inline border-t border-border px-component py-control"
715
- >
716
- <span className="shrink-0 text-label text-muted-foreground">
717
- {column.label}
718
- </span>
719
- <span className="min-w-0 text-right text-body-medium text-foreground">
720
- {getCellValue(row, column)}
721
- </span>
722
- </div>
723
- ))}
724
-
725
- {collapsible && (
726
- <div className="border-t border-border px-component py-control">
727
- <ClickableButton
728
- type="button"
729
- variant="bare"
730
- onClick={() => toggleCard(rowKey)}
731
- aria-expanded={isExpanded}
732
- className="flex items-center gap-micro text-small text-primary transition-colors hover:text-primary focus-visible:ring-primary"
733
- >
734
- <Icon
735
- name="ChevronDown"
736
- aria-hidden="true"
737
- className={`transition-transform ${isExpanded ? "rotate-180" : ""}`}
738
- />
739
- {isExpanded
740
- ? "Réduire"
741
- : `Voir tout (+${contentColumns.length - pairLimit})`}
742
- </ClickableButton>
743
- </div>
744
- )}
745
-
746
- {actionColumn && rowActions.length === 0 ? (
747
- <div className="flex justify-end border-t border-border px-component py-control">
748
- {getCellValue(row, actionColumn)}
749
- </div>
750
- ) : null}
751
- </article>
752
- );
753
- })}
754
- {tableActions.length > 0 || selectAllAction ? (
755
- <div className="flex justify-end">
756
- <TableActionsBar
757
- selectAllAction={selectAllAction}
758
- allSelected={allSelected}
759
- tableActions={tableActions}
760
- direction="up"
761
- open={openMenu === "actions-bottom"}
762
- onToggle={() => toggleMenu("actions-bottom")}
763
- onClose={closeMenus}
764
- />
765
- </div>
766
- ) : null}
767
- </div>
768
- )}
769
- </div>
770
-
771
- {totalPages > 1 && (
772
- <div className="flex items-center justify-between border-t border-border bg-surface px-component py-control">
773
- <p className="text-small text-muted-foreground">
774
- {startIndex + 1}–{Math.min(startIndex + rowsPerPage, sortedData.length)} sur{" "}
775
- {sortedData.length}
776
- </p>
777
- <div className="flex items-center gap-inline">
778
- <ClickableButton
779
- type="button"
780
- variant="bare"
781
- onClick={() => setCurrentPage((page) => Math.max(1, page - 1))}
782
- disabled={safePage === 1}
783
- className="rounded-medium border border-border p-inline text-muted-foreground transition-colors hover:text-primary disabled:opacity-50 focus-visible:ring-primary"
784
- aria-label="Page précédente"
785
- >
786
- <Icon name="ChevronLeft" aria-hidden="true" />
787
- </ClickableButton>
788
- <span className="text-small text-muted-foreground">
789
- {safePage} / {totalPages}
790
- </span>
791
- <ClickableButton
792
- type="button"
793
- variant="bare"
794
- onClick={() => setCurrentPage((page) => Math.min(totalPages, page + 1))}
795
- disabled={safePage === totalPages}
796
- className="rounded-medium border border-border p-inline text-muted-foreground transition-colors hover:text-primary disabled:opacity-50 focus-visible:ring-primary"
797
- aria-label="Page suivante"
798
- >
799
- <Icon name="ChevronRight" aria-hidden="true" />
800
- </ClickableButton>
801
- </div>
802
- </div>
803
- )}
804
- </div>
805
- );
806
- }