@modoock/components 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/dist/accordion.d.ts +24 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +30 -0
- package/dist/badge.d.ts +10 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +14 -0
- package/dist/button.d.ts +21 -0
- package/dist/button.d.ts.map +1 -0
- package/dist/button.js +27 -0
- package/dist/icon.d.ts +21 -0
- package/dist/icon.d.ts.map +1 -0
- package/dist/icon.js +24 -0
- package/{components/ui/index.ts → dist/index.d.ts} +24 -28
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/input.d.ts +41 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +105 -0
- package/dist/loader.d.ts +26 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +20 -0
- package/dist/metric-bar.d.ts +11 -0
- package/dist/metric-bar.d.ts.map +1 -0
- package/dist/metric-bar.js +19 -0
- package/dist/modal.d.ts +19 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +88 -0
- package/dist/select.d.ts +59 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +153 -0
- package/dist/stepper.d.ts +13 -0
- package/dist/stepper.d.ts.map +1 -0
- package/dist/stepper.js +38 -0
- package/dist/tab.d.ts +34 -0
- package/dist/tab.d.ts.map +1 -0
- package/dist/tab.js +25 -0
- package/dist/table.d.ts +57 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +180 -0
- package/package.json +27 -3
- package/components/ui/action-stack.tsx +0 -42
- package/components/ui/badge.tsx +0 -43
- package/components/ui/button.tsx +0 -104
- package/components/ui/icon.tsx +0 -78
- package/components/ui/input.tsx +0 -376
- package/components/ui/loader.tsx +0 -78
- package/components/ui/metric-bar.tsx +0 -49
- package/components/ui/modal.tsx +0 -177
- package/components/ui/select.tsx +0 -458
- package/components/ui/stepper.tsx +0 -96
- package/components/ui/tab.tsx +0 -85
- package/components/ui/user-table.tsx +0 -806
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": "
|
|
3
|
+
"version": "2.0.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
|
-
"
|
|
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,42 +0,0 @@
|
|
|
1
|
-
import ClickableButton from "./button";
|
|
2
|
-
import type { ButtonVariant } from "./button";
|
|
3
|
-
|
|
4
|
-
export interface ActionStackItem {
|
|
5
|
-
key: string;
|
|
6
|
-
label: string;
|
|
7
|
-
variant?: ButtonVariant;
|
|
8
|
-
onClick: () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Pile verticale de boutons d'action, avec message si aucune action n'est disponible.
|
|
13
|
-
*/
|
|
14
|
-
export default function ActionStack({
|
|
15
|
-
actions,
|
|
16
|
-
emptyMessage,
|
|
17
|
-
}: {
|
|
18
|
-
actions: ActionStackItem[];
|
|
19
|
-
emptyMessage?: string;
|
|
20
|
-
}) {
|
|
21
|
-
if (actions.length === 0) {
|
|
22
|
-
return emptyMessage ? (
|
|
23
|
-
<p className="text-body text-muted-foreground">{emptyMessage}</p>
|
|
24
|
-
) : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<div className="flex flex-col gap-inline">
|
|
29
|
-
{actions.map((action) => (
|
|
30
|
-
<ClickableButton
|
|
31
|
-
key={action.key}
|
|
32
|
-
type="button"
|
|
33
|
-
variant={action.variant}
|
|
34
|
-
fullWidth
|
|
35
|
-
onClick={action.onClick}
|
|
36
|
-
>
|
|
37
|
-
{action.label}
|
|
38
|
-
</ClickableButton>
|
|
39
|
-
))}
|
|
40
|
-
</div>
|
|
41
|
-
);
|
|
42
|
-
}
|
package/components/ui/badge.tsx
DELETED
|
@@ -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
|
-
|
package/components/ui/button.tsx
DELETED
|
@@ -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
|
-
}
|
package/components/ui/icon.tsx
DELETED
|
@@ -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
|
-
}
|