@modoock/components 1.1.0 → 2.1.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 (58) hide show
  1. package/dist/accordion.d.ts +24 -0
  2. package/dist/accordion.d.ts.map +1 -0
  3. package/dist/accordion.js +30 -0
  4. package/dist/agenda.d.ts +93 -0
  5. package/dist/agenda.d.ts.map +1 -0
  6. package/dist/agenda.js +581 -0
  7. package/dist/badge.d.ts +10 -0
  8. package/dist/badge.d.ts.map +1 -0
  9. package/dist/badge.js +14 -0
  10. package/dist/button.d.ts +21 -0
  11. package/dist/button.d.ts.map +1 -0
  12. package/dist/button.js +27 -0
  13. package/dist/date-picker.d.ts +47 -0
  14. package/dist/date-picker.d.ts.map +1 -0
  15. package/dist/date-picker.js +327 -0
  16. package/dist/icon.d.ts +21 -0
  17. package/dist/icon.d.ts.map +1 -0
  18. package/dist/icon.js +24 -0
  19. package/{components/ui/index.ts → dist/index.d.ts} +28 -28
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +14 -0
  22. package/dist/input.d.ts +41 -0
  23. package/dist/input.d.ts.map +1 -0
  24. package/dist/input.js +105 -0
  25. package/dist/loader.d.ts +26 -0
  26. package/dist/loader.d.ts.map +1 -0
  27. package/dist/loader.js +20 -0
  28. package/dist/metric-bar.d.ts +11 -0
  29. package/dist/metric-bar.d.ts.map +1 -0
  30. package/dist/metric-bar.js +19 -0
  31. package/dist/modal.d.ts +19 -0
  32. package/dist/modal.d.ts.map +1 -0
  33. package/dist/modal.js +88 -0
  34. package/dist/select.d.ts +59 -0
  35. package/dist/select.d.ts.map +1 -0
  36. package/dist/select.js +153 -0
  37. package/dist/stepper.d.ts +13 -0
  38. package/dist/stepper.d.ts.map +1 -0
  39. package/dist/stepper.js +38 -0
  40. package/dist/tab.d.ts +34 -0
  41. package/dist/tab.d.ts.map +1 -0
  42. package/dist/tab.js +25 -0
  43. package/dist/table.d.ts +57 -0
  44. package/dist/table.d.ts.map +1 -0
  45. package/dist/table.js +180 -0
  46. package/package.json +26 -2
  47. package/components/ui/accordion.tsx +0 -97
  48. package/components/ui/badge.tsx +0 -43
  49. package/components/ui/button.tsx +0 -104
  50. package/components/ui/icon.tsx +0 -78
  51. package/components/ui/input.tsx +0 -376
  52. package/components/ui/loader.tsx +0 -78
  53. package/components/ui/metric-bar.tsx +0 -49
  54. package/components/ui/modal.tsx +0 -177
  55. package/components/ui/select.tsx +0 -458
  56. package/components/ui/stepper.tsx +0 -96
  57. package/components/ui/tab.tsx +0 -85
  58. package/components/ui/table.tsx +0 -806
package/dist/tab.js ADDED
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import ClickableButton from "./button";
5
+ /**
6
+ * Tabbed pages navigation component.
7
+ * Follows Design System rules:
8
+ * - Tabs are presented on a single row.
9
+ * - Only one tab can be active at a time.
10
+ * - The active tab is clearly distinguished from inactive ones.
11
+ * - Clicking a tab activates it immediately and shows its associated content.
12
+ */
13
+ export default function Tabs({ tabs, defaultValue, onChange, children, panelClassName = "mt-component", }) {
14
+ const [activeTab, setActiveTab] = useState(defaultValue ?? tabs[0]?.value);
15
+ const handleSelect = (value) => {
16
+ setActiveTab(value);
17
+ onChange?.(value);
18
+ };
19
+ return (_jsxs("div", { className: "flex h-full min-h-0 w-full flex-col", children: [_jsx("div", { role: "tablist", className: "inline-flex max-w-full items-center gap-micro overflow-x-auto rounded-large bg-surface-muted p-micro", children: tabs.map((tab) => {
20
+ const isActive = activeTab === tab.value;
21
+ return (_jsx(ClickableButton, { type: "button", variant: "bare", role: "tab", "aria-selected": isActive, "aria-current": isActive ? "page" : undefined, onClick: () => handleSelect(tab.value), className: `whitespace-nowrap rounded-large px-component py-inline text-body-medium focus-visible:ring-primary ${isActive
22
+ ? "bg-surface text-primary shadow-sm"
23
+ : "bg-transparent text-muted-foreground hover:text-foreground"}`, children: tab.label }, tab.value));
24
+ }) }), children && _jsx("div", { className: panelClassName, children: children(activeTab) })] }));
25
+ }
@@ -0,0 +1,57 @@
1
+ import type { ReactNode } from "react";
2
+ import { type IconName } from "./icon";
3
+ export interface Column<T> {
4
+ key: keyof T;
5
+ label: string;
6
+ sortable?: boolean;
7
+ render?: (row: T) => ReactNode;
8
+ className?: string;
9
+ sortFn?: (a: T, b: T) => number;
10
+ }
11
+ /** Action entry displayed inside the card action menus (mobile card view). */
12
+ export interface CardAction {
13
+ label: string;
14
+ icon?: IconName;
15
+ /** Destructive action styling. */
16
+ danger?: boolean;
17
+ /** Pre-rendered node used as the whole menu item. Used when an action is
18
+ * derived from the table itself (e.g. the action column cell); it replaces
19
+ * `label`/`icon` and keeps its own interactivity. */
20
+ content?: ReactNode;
21
+ onSelect: () => void;
22
+ }
23
+ export interface TableCardActions<T> {
24
+ /** Actions globales du dropdown « Actions » — jamais recopiées sur une carte. */
25
+ table?: CardAction[];
26
+ selectAll?: CardAction;
27
+ /** Actions personnelles de la ligne. Plusieurs → dropdown ; une seule → affichage direct. */
28
+ row?: (row: T) => CardAction[];
29
+ }
30
+ export interface TableProps<T> {
31
+ columns: Column<T>[];
32
+ data: T[];
33
+ rowsPerPage?: number;
34
+ emptyMessage?: ReactNode;
35
+ getRowKey?: (row: T, index: number) => React.Key;
36
+ cardVisiblePairs?: number;
37
+ /** Déclare des actions — voir `TableCardActions`.
38
+ * `table` : dropdowns globaux « Actions » (pas recopiés sur chaque carte).
39
+ * `row` : actions personnelles. Une seule s’affiche telle quelle ; plusieurs
40
+ * vont dans un dropdown (colonne tableau et menu 3 points de la carte).
41
+ * Sans `row`, la dernière colonne sans libellé est réutilisée. */
42
+ cardActions?: TableCardActions<T>;
43
+ selectedKeys?: Set<React.Key> | null;
44
+ onToggleSelect?: ((rowKey: React.Key) => void) | null;
45
+ className?: string;
46
+ /** When true, the table is transposed: the first column shows row labels and
47
+ * each subsequent column represents one item from `data`. The first column
48
+ * header uses `transposeLabel` (or the first column's label), and each
49
+ * remaining column header is rendered via `transposeHeader` if provided. */
50
+ transpose?: boolean;
51
+ /** Label for the first column (row headers) when `transpose` is true. */
52
+ transposeLabel?: string;
53
+ /** Renders the header for each data column when `transpose` is true. */
54
+ transposeHeader?: (item: T) => React.ReactNode;
55
+ }
56
+ export default function Table<T extends object>({ columns, data, rowsPerPage, emptyMessage, getRowKey, cardVisiblePairs, cardActions, selectedKeys, onToggleSelect, className, transpose, transposeLabel, transposeHeader, }: TableProps<T>): import("react").JSX.Element;
57
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../components/ui/table.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAI7C,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC;CACjC;AAED,8EAA8E;AAC9E,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,kCAAkC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;0DAEsD;IACtD,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAGD,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,iFAAiF;IACjF,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IAErB,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,6FAA6F;IAC7F,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,UAAU,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACrB,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC;IAEjD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;uEAImE;IACnE,WAAW,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAElC,YAAY,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACrC,cAAc,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;iFAG6E;IAC7E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,yEAAyE;IACzE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;CAChD;AAiND,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,EAC9C,OAAO,EACP,IAAI,EACJ,WAAe,EACf,YAAuC,EACvC,SAAkC,EAClC,gBAAoB,EACpB,WAAW,EACX,YAAmB,EACnB,cAAqB,EACrB,SAAS,EACT,SAAiB,EACjB,cAAc,EACd,eAAe,GAChB,EAAE,UAAU,CAAC,CAAC,CAAC,+BAmgBf"}
package/dist/table.js ADDED
@@ -0,0 +1,180 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import Icon from "./icon";
5
+ import ClickableButton from "./button";
6
+ function defaultCompare(a, b, key) {
7
+ const aValue = a[key];
8
+ const bValue = b[key];
9
+ if (typeof aValue === "number" && typeof bValue === "number") {
10
+ return aValue - bValue;
11
+ }
12
+ const aString = aValue == null ? "" : String(aValue);
13
+ const bString = bValue == null ? "" : String(bValue);
14
+ return aString.localeCompare(bString, undefined, {
15
+ numeric: true,
16
+ sensitivity: "base",
17
+ });
18
+ }
19
+ function CardActionsMenu({ tableActions, rowActions, open, onToggle, onClose, trigger, direction = "down", }) {
20
+ const hasGroups = tableActions.length > 0 && rowActions.length > 0;
21
+ const renderGroup = (actions) => actions.map((action, index) => action.content ? (
22
+ // Action dérivée d'une colonne du tableau : le nœud rendu (ex. bouton
23
+ // « Voir ») est l'élément interactif ; le clic ferme le menu (bulle).
24
+ _jsx("div", { onClick: onClose, className: "rounded-small focus-within:ring-primary", children: action.content }, action.label || `derived-${index}`)) : (_jsxs("button", { type: "button", role: "menuitem", onClick: () => {
25
+ onClose();
26
+ action.onSelect();
27
+ }, 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 ${action.danger ? "text-danger" : "text-foreground"}`, children: [action.icon && (_jsx(Icon, { name: action.icon, size: "small", variant: action.danger ? "danger" : "muted", "aria-hidden": "true" })), action.label] }, action.label)));
28
+ return (_jsxs("div", { className: "relative", children: [trigger === "kebab" ? (_jsx(ClickableButton, { type: "button", variant: "ghost", size: "icon", "aria-label": "Plus d'actions", "aria-haspopup": "menu", "aria-expanded": open, onClick: onToggle, className: "text-muted-foreground hover:text-primary focus-visible:ring-primary", children: _jsx(Icon, { name: "EllipsisVertical", "aria-hidden": "true" }) })) : (_jsxs(ClickableButton, { type: "button", variant: "secondary", size: "sm", "aria-haspopup": "menu", "aria-expanded": open, onClick: onToggle, leftIcon: _jsx(Icon, { name: "EllipsisVertical", size: "small" }), children: ["Actions", _jsx(Icon, { name: "ChevronDown", size: "small", className: `transition-transform ${open ? "rotate-180" : ""}` })] })), open && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", "aria-label": "Fermer le menu", tabIndex: -1, onClick: onClose, className: "fixed inset-0 z-40 cursor-default" }), _jsxs("div", { role: "menu", className: `absolute right-0 z-50 flex min-w-40 max-w-[16rem] flex-col rounded-medium border border-border bg-surface shadow-lg ${direction === "up" ? "bottom-full mb-micro" : "top-full mt-micro"}`, children: [hasGroups && (_jsx("p", { className: "px-component pt-micro text-label text-muted-foreground", children: "Tableau" })), renderGroup(tableActions), hasGroups && _jsx("div", { className: "mx-component my-micro h-px bg-border" }), hasGroups && (_jsx("p", { className: "px-component pt-micro text-label text-muted-foreground", children: "Cette ligne" })), renderGroup(rowActions)] })] }))] }));
29
+ }
30
+ function TableActionsBar({ selectAllAction, allSelected, tableActions, open, direction = "down", onToggle, onClose, }) {
31
+ return (_jsxs("div", { className: "flex items-center justify-end gap-inline", children: [selectAllAction ? (_jsx(ClickableButton, { type: "button", variant: "secondary", size: "sm", "aria-pressed": allSelected, onClick: selectAllAction.onSelect, leftIcon: selectAllAction.icon ? (_jsx(Icon, { name: selectAllAction.icon, size: "small", variant: allSelected ? "primary" : "muted", "aria-hidden": "true" })) : undefined, children: selectAllAction.label })) : null, tableActions.length > 0 ? (_jsx(CardActionsMenu, { trigger: "labeled", direction: direction, tableActions: tableActions, rowActions: [], open: open, onToggle: onToggle, onClose: onClose })) : null] }));
32
+ }
33
+ export default function Table({ columns, data, rowsPerPage = 8, emptyMessage = "Aucune donnée trouvée.", getRowKey = (_row, index) => index, cardVisiblePairs = 6, cardActions, selectedKeys = null, onToggleSelect = null, className, transpose = false, transposeLabel, transposeHeader, }) {
34
+ const [sortKey, setSortKey] = useState(null);
35
+ const [sortDirection, setSortDirection] = useState("asc");
36
+ const [currentPage, setCurrentPage] = useState(1);
37
+ // Vue carte (sous `md`) : clés des lignes dont la carte est dépliée
38
+ // (toutes les paires label/valeur révélées par la bascule « Voir tout »).
39
+ const [expandedCards, setExpandedCards] = useState(new Set());
40
+ // Menus d'actions des cartes enrichies : un seul menu ouvert à la fois
41
+ // (règle knowledge-base/design-system/components/dropdowns.mdc).
42
+ const [openMenu, setOpenMenu] = useState(null);
43
+ const sortedData = [...data].sort((a, b) => {
44
+ if (!sortKey)
45
+ return 0;
46
+ const column = columns.find((c) => String(c.key) === sortKey);
47
+ if (!column)
48
+ return 0;
49
+ const comparison = column.sortFn
50
+ ? column.sortFn(a, b)
51
+ : defaultCompare(a, b, column.key);
52
+ return sortDirection === "asc" ? comparison : -comparison;
53
+ });
54
+ const totalPages = Math.max(1, Math.ceil(sortedData.length / rowsPerPage));
55
+ const safePage = Math.min(currentPage, totalPages);
56
+ const startIndex = (safePage - 1) * rowsPerPage;
57
+ const visibleData = sortedData.slice(startIndex, startIndex + rowsPerPage);
58
+ const handleSort = (column) => {
59
+ const key = String(column.key);
60
+ if (key === sortKey) {
61
+ setSortDirection((dir) => (dir === "asc" ? "desc" : "asc"));
62
+ }
63
+ else {
64
+ setSortKey(key);
65
+ setSortDirection("asc");
66
+ }
67
+ };
68
+ const toggleCard = (rowKey) => {
69
+ setExpandedCards((previous) => {
70
+ const next = new Set(previous);
71
+ if (next.has(rowKey)) {
72
+ next.delete(rowKey);
73
+ }
74
+ else {
75
+ next.add(rowKey);
76
+ }
77
+ return next;
78
+ });
79
+ };
80
+ const toggleMenu = (key) => setOpenMenu((current) => (current === key ? null : key));
81
+ const getCellValue = (row, column) => {
82
+ if (column.render)
83
+ return column.render(row);
84
+ const value = row[column.key];
85
+ if (value == null)
86
+ return "";
87
+ if (typeof value === "object")
88
+ return String(value);
89
+ return value;
90
+ };
91
+ // Actions de ligne du menu carte : celles déclarées par la page
92
+ // (`cardActions.row`) priment ; sinon la cellule de la colonne d'action
93
+ // (dernière colonne sans libellé) est réutilisée telle quelle dans le menu,
94
+ // pour que chaque tableau expose ses actions sans configuration par page.
95
+ const resolveRowActions = (row) => {
96
+ if (cardActions?.row)
97
+ return cardActions.row(row);
98
+ if (!actionColumn?.render)
99
+ return [];
100
+ const cell = getCellValue(row, actionColumn);
101
+ if (cell == null || cell === false || cell === "")
102
+ return [];
103
+ return [{ label: "", content: cell, onSelect: () => { } }];
104
+ };
105
+ // Colonnes spéciales utilisées par la vue carte (sous `md`).
106
+ const emptyLabelColumns = columns.filter((column) => column.label.trim() === "");
107
+ const titleColumn = columns.find((column) => column.label.trim() !== "") ?? columns[0];
108
+ const headerControlColumn = emptyLabelColumns.length > 1 ? emptyLabelColumns[0] : undefined;
109
+ const actionColumn = emptyLabelColumns[emptyLabelColumns.length - 1] ?? undefined;
110
+ const contentColumns = columns.filter((column) => column !== titleColumn &&
111
+ column !== headerControlColumn &&
112
+ column !== actionColumn);
113
+ const rowActionColumn = cardActions?.row
114
+ ? (actionColumn ?? {
115
+ key: columns[0].key,
116
+ label: "",
117
+ sortable: false,
118
+ className: "w-12 text-right",
119
+ })
120
+ : actionColumn;
121
+ const visibleColumns = cardActions?.row
122
+ ? [...columns.filter((column) => column !== actionColumn), rowActionColumn]
123
+ : columns;
124
+ // Vue carte (sous `md`) : cartes visuellement séparées, sélection à gauche,
125
+ // menu 3 points par carte (actions de ligne uniquement) et dropdowns
126
+ // « Actions » globaux au-dessus et en dessous de la liste. Les actions
127
+ // `table` ne sont jamais recopiées dans le menu d'une carte.
128
+ const tableActions = cardActions?.table ?? [];
129
+ const selectAllAction = cardActions?.selectAll;
130
+ // État « toutes les lignes sont sélectionnées » : pilote l'état enfoncé
131
+ // (aria-pressed) du bouton « tout sélectionner » dédié ; la bascule
132
+ // (second clic = désélection) est implémentée par la page dans `onSelect`.
133
+ const allSelected = data.length > 0 &&
134
+ data.every((row, index) => selectedKeys?.has(getRowKey(row, index)) ?? false);
135
+ // Bouton de sélection automatique sur les cartes dès qu'il y a des actions
136
+ // globales (ou un « tout sélectionner » dédié) et que la page fournit le
137
+ // toggle de sélection.
138
+ const hasSelectionControl = onToggleSelect !== null &&
139
+ (tableActions.length > 0 || selectAllAction !== undefined);
140
+ const columnCount = visibleColumns.length + (hasSelectionControl ? 1 : 0);
141
+ const closeMenus = () => setOpenMenu(null);
142
+ const renderPersonalActions = (row, rowKey) => {
143
+ const rowActions = resolveRowActions(row);
144
+ if (rowActions.length > 1) {
145
+ const menuKey = `row:${String(rowKey)}`;
146
+ return (_jsx("div", { className: "flex justify-end", children: _jsx(CardActionsMenu, { trigger: "kebab", tableActions: [], rowActions: rowActions, open: openMenu === menuKey, onToggle: () => toggleMenu(menuKey), onClose: closeMenus }) }));
147
+ }
148
+ const action = rowActions[0];
149
+ if (!action)
150
+ return null;
151
+ if (action.content) {
152
+ return _jsx("div", { className: "flex justify-end", children: action.content });
153
+ }
154
+ return (_jsx("div", { className: "flex justify-end", children: _jsx(ClickableButton, { type: "button", variant: action.danger ? "danger" : "secondary", size: "sm", onClick: action.onSelect, children: action.label }) }));
155
+ };
156
+ const SortIcon = () => (_jsx(Icon, { name: "ChevronsUpDown", "aria-hidden": "true" }));
157
+ const SortableHeader = ({ column }) => (_jsx("th", { className: "text-left", children: _jsxs(ClickableButton, { type: "button", variant: "bare", onClick: () => handleSort(column), className: "px-component py-control text-muted-foreground transition-colors hover:text-primary focus-visible:ring-primary", children: [_jsx("span", { className: "text-label", children: column.label }), _jsx(SortIcon, {})] }) }));
158
+ return (_jsxs("div", { className: `flex flex-col overflow-hidden rounded-large border border-border bg-surface md:h-full ${className ?? ""}`, children: [tableActions.length > 0 || selectAllAction ? (_jsx("div", { className: "hidden shrink-0 border-b border-border px-component py-control md:flex md:justify-end", children: _jsx(TableActionsBar, { selectAllAction: selectAllAction, allSelected: allSelected, tableActions: tableActions, open: openMenu === "actions-desktop", onToggle: () => toggleMenu("actions-desktop"), onClose: closeMenus }) })) : null, _jsx("div", { className: "hidden min-h-0 flex-1 overflow-auto md:block", children: _jsx("table", { className: "w-full border-collapse text-body", children: transpose ? (_jsxs(_Fragment, { children: [_jsx("thead", { className: "sticky top-0 z-10 bg-surface-muted", children: _jsxs("tr", { className: "border-b border-border", children: [_jsx("th", { className: "px-component py-control text-left text-label text-muted-foreground", children: transposeLabel ?? columns[0]?.label ?? "" }), data.map((item, i) => (_jsx("th", { className: "px-component py-control text-left", children: transposeHeader ? transposeHeader(item) : null }, i)))] }) }), _jsx("tbody", { children: data.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: 1, className: "px-component py-section text-center text-muted-foreground", children: emptyMessage }) })) : (columns.slice(1).map((column) => (_jsxs("tr", { className: "h-12 border-t border-border", children: [_jsx("td", { className: "px-component align-middle text-label text-muted-foreground", children: column.label }), data.map((item, i) => (_jsx("td", { className: `px-component align-middle ${column.className ?? "text-body-medium text-foreground"}`, children: getCellValue(item, column) }, i)))] }, String(column.key))))) })] })) : (_jsxs(_Fragment, { children: [_jsx("thead", { className: "sticky top-0 z-10 bg-surface-muted", children: _jsxs("tr", { className: "border-b border-border", children: [hasSelectionControl ? (_jsx("th", { className: "w-10 px-component py-control", children: selectAllAction ? (_jsx(ClickableButton, { type: "button", variant: "ghost", size: "icon", "aria-label": selectAllAction.label, "aria-pressed": allSelected, onClick: selectAllAction.onSelect, className: "text-muted-foreground hover:text-primary focus-visible:ring-primary", children: _jsx(Icon, { name: allSelected ? "SquareCheck" : "Square", "aria-hidden": "true" }) })) : null })) : null, visibleColumns.map((column, columnIndex) => column.sortable ? (_jsx(SortableHeader, { column: column }, `col-${columnIndex}`)) : (_jsx("th", { className: "px-component py-control text-left text-label text-muted-foreground", children: column.label }, `col-${columnIndex}`)))] }) }), _jsx("tbody", { children: visibleData.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: columnCount, className: "px-component py-section text-center text-muted-foreground", children: emptyMessage }) })) : (visibleData.map((row, rowIndex) => {
159
+ const rowKey = getRowKey(row, startIndex + rowIndex);
160
+ const selected = selectedKeys?.has(rowKey) ?? false;
161
+ return (_jsxs("tr", { className: "h-12 border-b border-border transition-colors last:border-b-0 hover:bg-surface-muted", children: [hasSelectionControl ? (_jsx("td", { className: "px-component align-middle", children: _jsx(ClickableButton, { type: "button", variant: "ghost", size: "icon", "aria-pressed": selected, "aria-label": selected
162
+ ? "Retirer la sélection"
163
+ : "Sélectionner", onClick: () => onToggleSelect?.(rowKey), className: "text-muted-foreground hover:text-primary focus-visible:ring-primary", children: _jsx(Icon, { name: selected ? "SquareCheck" : "Square", "aria-hidden": "true" }) }) })) : null, visibleColumns.map((column, columnIndex) => (_jsx("td", { className: `px-component align-middle ${column.className ?? "text-body-medium text-foreground"}`, children: cardActions?.row && column === rowActionColumn ? (renderPersonalActions(row, rowKey)) : (getCellValue(row, column)) }, `col-${columnIndex}`)))] }, rowKey));
164
+ })) })] })) }) }), _jsx("div", { className: "md:hidden", children: visibleData.length === 0 ? (_jsx("div", { className: "px-component py-section text-center text-muted-foreground", children: emptyMessage })) : (_jsxs("div", { className: "flex flex-col gap-component p-component", children: [tableActions.length > 0 || selectAllAction ? (_jsx("div", { className: "flex justify-end", children: _jsx(TableActionsBar, { selectAllAction: selectAllAction, allSelected: allSelected, tableActions: tableActions, direction: "down", open: openMenu === "actions-top", onToggle: () => toggleMenu("actions-top"), onClose: closeMenus }) })) : null, visibleData.map((row, rowIndex) => {
165
+ const rowKey = getRowKey(row, startIndex + rowIndex);
166
+ const pairLimit = Math.max(1, cardVisiblePairs);
167
+ const isExpanded = expandedCards.has(rowKey);
168
+ const collapsible = contentColumns.length > pairLimit;
169
+ const visiblePairs = collapsible && !isExpanded
170
+ ? contentColumns.slice(0, pairLimit)
171
+ : contentColumns;
172
+ const rowActions = resolveRowActions(row);
173
+ const menuKey = `card:${String(rowKey)}`;
174
+ return (_jsxs("article", { className: "flex flex-col overflow-hidden rounded-large border border-border bg-surface", children: [_jsxs("div", { className: "flex items-center gap-inline bg-surface-muted px-component py-control", children: [hasSelectionControl ? (_jsx("button", { type: "button", onClick: () => onToggleSelect?.(rowKey), "aria-pressed": selectedKeys?.has(rowKey) ?? false, "aria-label": selectedKeys?.has(rowKey)
175
+ ? "Retirer la sélection"
176
+ : "Sélectionner", className: "grid size-8 shrink-0 place-items-center rounded-small text-muted-foreground transition-colors hover:text-primary focus-visible:ring-primary", children: _jsx(Icon, { name: selectedKeys?.has(rowKey) ? "SquareCheck" : "Square", size: "default", "aria-hidden": "true" }) })) : (headerControlColumn && (_jsx("div", { className: "shrink-0", children: getCellValue(row, headerControlColumn) }))), _jsx("p", { className: "min-w-0 flex-1 text-component-title text-foreground", children: getCellValue(row, titleColumn) }), rowActions.length > 0 ? (_jsx(CardActionsMenu, { trigger: "kebab", tableActions: [], rowActions: rowActions, open: openMenu === menuKey, onToggle: () => toggleMenu(menuKey), onClose: closeMenus })) : null] }), visiblePairs.map((column) => (_jsxs("div", { className: "flex items-center justify-between gap-inline border-t border-border px-component py-control", children: [_jsx("span", { className: "shrink-0 text-label text-muted-foreground", children: column.label }), _jsx("span", { className: "min-w-0 text-right text-body-medium text-foreground", children: getCellValue(row, column) })] }, String(column.key)))), collapsible && (_jsx("div", { className: "border-t border-border px-component py-control", children: _jsxs(ClickableButton, { type: "button", variant: "bare", onClick: () => toggleCard(rowKey), "aria-expanded": isExpanded, className: "flex items-center gap-micro text-small text-primary transition-colors hover:text-primary focus-visible:ring-primary", children: [_jsx(Icon, { name: "ChevronDown", "aria-hidden": "true", className: `transition-transform ${isExpanded ? "rotate-180" : ""}` }), isExpanded
177
+ ? "Réduire"
178
+ : `Voir tout (+${contentColumns.length - pairLimit})`] }) })), actionColumn && rowActions.length === 0 ? (_jsx("div", { className: "flex justify-end border-t border-border px-component py-control", children: getCellValue(row, actionColumn) })) : null] }, rowKey));
179
+ }), tableActions.length > 0 || selectAllAction ? (_jsx("div", { className: "flex justify-end", children: _jsx(TableActionsBar, { selectAllAction: selectAllAction, allSelected: allSelected, tableActions: tableActions, direction: "up", open: openMenu === "actions-bottom", onToggle: () => toggleMenu("actions-bottom"), onClose: closeMenus }) })) : null] })) }), totalPages > 1 && (_jsxs("div", { className: "flex items-center justify-between border-t border-border bg-surface px-component py-control", children: [_jsxs("p", { className: "text-small text-muted-foreground", children: [startIndex + 1, "\u2013", Math.min(startIndex + rowsPerPage, sortedData.length), " sur", " ", sortedData.length] }), _jsxs("div", { className: "flex items-center gap-inline", children: [_jsx(ClickableButton, { type: "button", variant: "bare", onClick: () => setCurrentPage((page) => Math.max(1, page - 1)), disabled: safePage === 1, className: "rounded-medium border border-border p-inline text-muted-foreground transition-colors hover:text-primary disabled:opacity-50 focus-visible:ring-primary", "aria-label": "Page pr\u00E9c\u00E9dente", children: _jsx(Icon, { name: "ChevronLeft", "aria-hidden": "true" }) }), _jsxs("span", { className: "text-small text-muted-foreground", children: [safePage, " / ", totalPages] }), _jsx(ClickableButton, { type: "button", variant: "bare", onClick: () => setCurrentPage((page) => Math.min(totalPages, page + 1)), disabled: safePage === totalPages, className: "rounded-medium border border-border p-inline text-muted-foreground transition-colors hover:text-primary disabled:opacity-50 focus-visible:ring-primary", "aria-label": "Page suivante", children: _jsx(Icon, { name: "ChevronRight", "aria-hidden": "true" }) })] })] }))] }));
180
+ }
package/package.json CHANGED
@@ -1,10 +1,34 @@
1
1
  {
2
2
  "name": "@modoock/components",
3
- "version": "1.1.0",
3
+ "version": "2.1.0",
4
4
  "description": "Modoock source components for internal projects.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js"
12
+ }
13
+ },
5
14
  "files": [
6
- "components/ui",
15
+ "dist",
7
16
  "README.md"
8
17
  ],
18
+ "scripts": {
19
+ "build": "tsc"
20
+ },
21
+ "peerDependencies": {
22
+ "react": ">=18",
23
+ "react-dom": ">=18",
24
+ "lucide-react": ">=1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/react": "^19",
28
+ "@types/react-dom": "^19",
29
+ "react": "^19",
30
+ "react-dom": "^19",
31
+ "typescript": "^5"
32
+ },
9
33
  "license": "MIT"
10
34
  }
@@ -1,97 +0,0 @@
1
- "use client";
2
-
3
- import { useState, type ReactNode } from "react";
4
- import ClickableButton from "./button";
5
- import Icon from "./icon";
6
-
7
- export interface AccordionItem {
8
- id: string;
9
- title: string;
10
- content: ReactNode;
11
- /** When true, the item starts open. */
12
- defaultOpen?: boolean;
13
- }
14
-
15
- interface AccordionProps {
16
- items: AccordionItem[];
17
- /**
18
- * When true (default), several panels can stay open.
19
- * When false, opening one panel closes the others.
20
- */
21
- allowMultiple?: boolean;
22
- className?: string;
23
- }
24
-
25
- /**
26
- * Accordion — FAQ-style open/close sections.
27
- * Each item has a clickable header and a collapsible body.
28
- */
29
- export default function Accordion({
30
- items,
31
- allowMultiple = true,
32
- className = "",
33
- }: AccordionProps) {
34
- const [openIds, setOpenIds] = useState<Set<string>>(
35
- () => new Set(items.filter((item) => item.defaultOpen).map((item) => item.id)),
36
- );
37
-
38
- const toggle = (id: string) => {
39
- setOpenIds((previous) => {
40
- const next = new Set(allowMultiple ? previous : []);
41
- if (previous.has(id)) {
42
- next.delete(id);
43
- } else {
44
- next.add(id);
45
- }
46
- return next;
47
- });
48
- };
49
-
50
- return (
51
- <div className={`flex flex-col gap-inline ${className}`}>
52
- {items.map((item) => {
53
- const isOpen = openIds.has(item.id);
54
- const panelId = `accordion-panel-${item.id}`;
55
- const headerId = `accordion-header-${item.id}`;
56
-
57
- return (
58
- <section
59
- key={item.id}
60
- className="overflow-hidden rounded-large border border-border bg-surface"
61
- >
62
- <h3 className="m-0">
63
- <ClickableButton
64
- type="button"
65
- variant="bare"
66
- id={headerId}
67
- aria-expanded={isOpen}
68
- aria-controls={panelId}
69
- onClick={() => toggle(item.id)}
70
- className="flex !h-auto w-full items-center justify-between gap-inline rounded-none px-component py-component text-left text-component-title text-foreground hover:bg-surface-muted focus-visible:ring-primary"
71
- >
72
- <span className="min-w-0 flex-1 truncate">{item.title}</span>
73
- <Icon
74
- name="ChevronDown"
75
- aria-hidden="true"
76
- className={`shrink-0 transition-transform ${
77
- isOpen ? "rotate-180" : ""
78
- }`}
79
- />
80
- </ClickableButton>
81
- </h3>
82
- {isOpen ? (
83
- <div
84
- id={panelId}
85
- role="region"
86
- aria-labelledby={headerId}
87
- className="border-t border-border px-component py-component"
88
- >
89
- {item.content}
90
- </div>
91
- ) : null}
92
- </section>
93
- );
94
- })}
95
- </div>
96
- );
97
- }
@@ -1,43 +0,0 @@
1
- import type { ReactNode } from "react";
2
-
3
- type BadgeVariant =
4
- | "default"
5
- | "primary"
6
- | "secondary"
7
- | "success"
8
- | "warning"
9
- | "danger"
10
- | "info"
11
- | "accent";
12
-
13
- export interface BadgeProps {
14
- children: ReactNode;
15
- variant?: BadgeVariant;
16
- className?: string;
17
- }
18
-
19
- const badgeStyles: Record<BadgeVariant, string> = {
20
- default: "bg-surface-muted text-muted-foreground",
21
- primary: "bg-primary-light text-primary",
22
- secondary: "bg-surface text-foreground border border-border",
23
- success: "bg-success-light text-success-foreground",
24
- warning: "bg-warning-light text-warning-foreground",
25
- danger: "bg-danger-light text-danger-foreground",
26
- info: "bg-info-light text-info-foreground",
27
- accent: "bg-accent-light text-accent",
28
- };
29
-
30
- export default function Badge({
31
- children,
32
- variant = "default",
33
- className = "",
34
- }: BadgeProps) {
35
- return (
36
- <span
37
- className={`inline-flex items-center justify-center rounded-full px-component py-micro text-label whitespace-nowrap ${badgeStyles[variant]} ${className}`}
38
- >
39
- {children}
40
- </span>
41
- );
42
- }
43
-
@@ -1,104 +0,0 @@
1
- import type { ButtonHTMLAttributes, ReactNode } from "react";
2
- import Icon from "./icon";
3
-
4
- export type ButtonVariant =
5
- | "primary"
6
- | "secondary"
7
- | "ghost"
8
- | "bare"
9
- | "success"
10
- | "warning"
11
- | "danger"
12
- | "info"
13
- | "accent";
14
-
15
- export type ButtonSize = "sm" | "md" | "lg" | "icon";
16
-
17
- export interface ClickableButtonProps
18
- extends ButtonHTMLAttributes<HTMLButtonElement> {
19
- children: ReactNode;
20
- variant?: ButtonVariant;
21
- /** Controls the height, padding and radius of the button. */
22
- size?: ButtonSize;
23
- /** Optional leading icon (replaced by a spinner while `loading`). */
24
- leftIcon?: ReactNode;
25
- /** Optional trailing icon. */
26
- rightIcon?: ReactNode;
27
- /** Shows a spinner, disables the button and prevents interactions. */
28
- loading?: boolean;
29
- /** Text displayed while `loading` (defaults to `children`). */
30
- loadingText?: string;
31
- /** Expands the button to fill the available width. */
32
- fullWidth?: boolean;
33
- }
34
-
35
- const BASE_CLASS =
36
- "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-medium text-sm font-medium outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60 [&_svg]:size-[var(--icon-small)] [&_svg]:shrink-0 [&_svg]:text-current";
37
-
38
- const SIZE_CLASS: Record<ButtonSize, string> = {
39
- sm: "h-9 px-3",
40
- md: "h-10 px-4",
41
- lg: "h-11 px-5",
42
- /* Icon-only button: square, no horizontal padding. */
43
- icon: "h-10 w-10 px-0",
44
- };
45
-
46
- const VARIANT_CLASS: Record<ButtonVariant, string> = {
47
- primary:
48
- "bg-primary text-white hover:bg-primary-hover active:bg-primary-active focus-visible:ring-primary",
49
- secondary:
50
- "border border-border bg-surface text-foreground hover:border-primary hover:text-primary focus-visible:ring-primary",
51
- ghost:
52
- "bg-transparent text-muted-foreground hover:text-primary focus-visible:ring-primary",
53
- success:
54
- "bg-success text-white hover:brightness-90 active:brightness-80 focus-visible:ring-success",
55
- warning:
56
- "bg-warning text-white hover:brightness-90 active:brightness-80 focus-visible:ring-warning",
57
- danger:
58
- "bg-danger text-white hover:brightness-90 active:brightness-80 focus-visible:ring-danger",
59
- info: "bg-info text-white hover:brightness-90 active:brightness-80 focus-visible:ring-info",
60
- accent:
61
- "bg-accent text-accent-foreground hover:bg-accent-hover active:brightness-80 focus-visible:ring-accent",
62
- /* No built-in styles: the caller provides everything via className. */
63
- bare: "",
64
- };
65
-
66
- export default function ClickableButton({
67
- children,
68
- variant = "primary",
69
- size = "md",
70
- leftIcon,
71
- rightIcon,
72
- loading = false,
73
- loadingText,
74
- fullWidth = false,
75
- disabled,
76
- className = "",
77
- ...props
78
- }: ClickableButtonProps) {
79
- const isDisabled = disabled || loading;
80
- const resolvedLabel = loading && loadingText ? loadingText : children;
81
-
82
- return (
83
- <button
84
- type="button"
85
- aria-busy={loading || undefined}
86
- disabled={isDisabled}
87
- className={`${BASE_CLASS} ${VARIANT_CLASS[variant]} ${SIZE_CLASS[size]} ${fullWidth ? "w-full" : ""} ${className}`}
88
- {...props}
89
- >
90
- {loading ? (
91
- <Icon
92
- name="LoaderCircle"
93
- size="small"
94
- className="animate-spin"
95
- aria-hidden="true"
96
- />
97
- ) : (
98
- leftIcon
99
- )}
100
- {resolvedLabel}
101
- {!loading && rightIcon}
102
- </button>
103
- );
104
- }
@@ -1,78 +0,0 @@
1
- import type { SVGProps } from "react";
2
- import { icons, type LucideIcon } from "lucide-react";
3
-
4
- /* ------------------------------------------------------------------ */
5
- /* Icon - centralized interface icon */
6
- /* */
7
- /* Single source of truth for icons. Only pick `name`, `variant` and */
8
- /* `size` from the allowed values defined by the Design System. */
9
- /* ------------------------------------------------------------------ */
10
-
11
- /** Available icon sizes from the Iconography section. */
12
- export type IconSize = "small" | "default" | "large" | "display";
13
-
14
- /** Available icon variants, aligned with the Design System colors. */
15
- export type IconVariant =
16
- | "default"
17
- | "muted"
18
- | "primary"
19
- | "success"
20
- | "warning"
21
- | "danger"
22
- | "white";
23
-
24
- /** Every exported Lucide icon name (e.g. "Search", "ArrowRight"). */
25
- export type IconName = keyof typeof icons;
26
-
27
- export interface IconProps extends Omit<SVGProps<SVGSVGElement>, "size"> {
28
- /** The Lucide icon name to render. */
29
- name: IconName;
30
- /** Color variant; defaults to a neutral foreground icon. */
31
- variant?: IconVariant;
32
- /** Size variant following the Iconography tokens. */
33
- size?: IconSize;
34
- /** Overrides the Design System default stroke weight (1.8). */
35
- strokeWidth?: number;
36
- className?: string;
37
- }
38
-
39
- /** Fallback base class: keeps the icon from shrinking inside flex rows. */
40
- const BASE_CLASS = "shrink-0";
41
-
42
- const SIZE_CLASS: Record<IconSize, string> = {
43
- small: "size-[var(--icon-small)]",
44
- default: "size-[var(--icon-default)]",
45
- large: "size-[var(--icon-large)]",
46
- display: "size-[var(--icon-display)]",
47
- };
48
-
49
- const VARIANT_CLASS: Record<IconVariant, string> = {
50
- default: "text-foreground",
51
- muted: "text-muted-foreground",
52
- primary: "text-primary",
53
- success: "text-success",
54
- warning: "text-warning",
55
- danger: "text-danger",
56
- /* White icon intended for colored surfaces (nav items, brand badges). */
57
- white: "text-white",
58
- };
59
-
60
- export default function Icon({
61
- name,
62
- variant = "default",
63
- size = "default",
64
- strokeWidth = 1.8,
65
- className = "",
66
- ...props
67
- }: IconProps) {
68
- const IconComponent: LucideIcon = icons[name];
69
-
70
- return (
71
- <IconComponent
72
- aria-hidden="true"
73
- strokeWidth={strokeWidth}
74
- className={`${BASE_CLASS} ${SIZE_CLASS[size]} ${VARIANT_CLASS[variant]} ${className}`}
75
- {...props}
76
- />
77
- );
78
- }