@portnet/ui 2.0.0 → 2.0.2
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/components/table/PuiTable.js +146 -16
- package/package.json +1 -1
|
@@ -7,6 +7,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
value: true
|
|
8
8
|
});
|
|
9
9
|
exports.default = void 0;
|
|
10
|
+
require("core-js/modules/es.array.includes.js");
|
|
11
|
+
require("core-js/modules/es.array.sort.js");
|
|
12
|
+
require("core-js/modules/es.string.includes.js");
|
|
10
13
|
require("core-js/modules/esnext.iterator.constructor.js");
|
|
11
14
|
require("core-js/modules/esnext.iterator.map.js");
|
|
12
15
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
@@ -24,7 +27,7 @@ var _PuiTableAction = _interopRequireDefault(require("./PuiTableAction"));
|
|
|
24
27
|
var _ActionPopover = _interopRequireDefault(require("./ActionPopover"));
|
|
25
28
|
var _system = require("@mui/system");
|
|
26
29
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
-
const _excluded = ["id", "className", "sx", "elevate", "rows", "rowCount", "columns", "paginationMode", "page", "pageSize", "checkboxSelection", "loading", "stripped", "actions", "oneActionOnly", "onSelect", "onPageChange", "onPageSizeChange", "rowDetailPanel"];
|
|
30
|
+
const _excluded = ["id", "className", "sx", "elevate", "rows", "rowCount", "columns", "paginationMode", "page", "pageSize", "checkboxSelection", "loading", "stripped", "actions", "oneActionOnly", "onSelect", "onPageChange", "onPageSizeChange", "rowDetailPanel", "stickyColumns"];
|
|
28
31
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
29
32
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
30
33
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -101,6 +104,27 @@ const StyledMuiTable = (0, _styles.styled)(/*#__PURE__*/React.forwardRef((props,
|
|
|
101
104
|
},
|
|
102
105
|
"&:last-of-type .MuiDataGrid-columnSeparator": {
|
|
103
106
|
display: "none"
|
|
107
|
+
},
|
|
108
|
+
// Colonne sticky - styles améliorés
|
|
109
|
+
"&.sticky-column": {
|
|
110
|
+
position: "sticky",
|
|
111
|
+
zIndex: 3,
|
|
112
|
+
// Valeur supérieure pour s'assurer qu'elle reste au-dessus lors du défilement
|
|
113
|
+
"&.sticky-column-left": {
|
|
114
|
+
left: 0
|
|
115
|
+
},
|
|
116
|
+
"&.sticky-column-right": {
|
|
117
|
+
right: 0
|
|
118
|
+
},
|
|
119
|
+
// S'assurer que le contenu est visible
|
|
120
|
+
"& .MuiDataGrid-columnHeaderTitleContainer": {
|
|
121
|
+
visibility: "visible",
|
|
122
|
+
overflow: "visible"
|
|
123
|
+
},
|
|
124
|
+
"& .MuiDataGrid-columnHeaderTitle": {
|
|
125
|
+
visibility: "visible",
|
|
126
|
+
overflow: "visible"
|
|
127
|
+
}
|
|
104
128
|
}
|
|
105
129
|
},
|
|
106
130
|
"& .MuiDataGrid-columnSeparator": {
|
|
@@ -123,6 +147,17 @@ const StyledMuiTable = (0, _styles.styled)(/*#__PURE__*/React.forwardRef((props,
|
|
|
123
147
|
},
|
|
124
148
|
"&:focus-within": {
|
|
125
149
|
outline: "none"
|
|
150
|
+
},
|
|
151
|
+
// Cellules sticky - styles améliorés
|
|
152
|
+
"&.sticky-column": {
|
|
153
|
+
position: "sticky",
|
|
154
|
+
zIndex: 2,
|
|
155
|
+
"&.sticky-column-left": {
|
|
156
|
+
left: 0
|
|
157
|
+
},
|
|
158
|
+
"&.sticky-column-right": {
|
|
159
|
+
right: 0
|
|
160
|
+
}
|
|
126
161
|
}
|
|
127
162
|
},
|
|
128
163
|
"& .MuiDataGrid-row": {
|
|
@@ -278,6 +313,14 @@ const autosizeOptions = {
|
|
|
278
313
|
includeHeaders: true,
|
|
279
314
|
includeOutliers: true
|
|
280
315
|
};
|
|
316
|
+
|
|
317
|
+
// Ordre de priorité pour les colonnes sticky: -1 = début (à gauche), 0 = ne pas figer, 1 = fin (à droite)
|
|
318
|
+
const calculateStickyOrder = (field, stickyColumns) => {
|
|
319
|
+
if (!stickyColumns.includes(field)) return 0;
|
|
320
|
+
const idx = stickyColumns.indexOf(field);
|
|
321
|
+
if (idx === -1) return 0;
|
|
322
|
+
return idx;
|
|
323
|
+
};
|
|
281
324
|
const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
282
325
|
let {
|
|
283
326
|
id,
|
|
@@ -298,12 +341,72 @@ const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
|
298
341
|
onSelect,
|
|
299
342
|
onPageChange,
|
|
300
343
|
onPageSizeChange,
|
|
301
|
-
rowDetailPanel
|
|
344
|
+
rowDetailPanel,
|
|
345
|
+
stickyColumns = []
|
|
302
346
|
} = _ref3,
|
|
303
347
|
rest = _objectWithoutProperties(_ref3, _excluded);
|
|
304
348
|
const [appColumns, setAppColumns] = React.useState(columns);
|
|
349
|
+
|
|
350
|
+
// Calcule les positions sticky pour les colonnes figées - logique améliorée
|
|
351
|
+
const calculateStickyPositions = columns => {
|
|
352
|
+
let leftOffset = 0;
|
|
353
|
+
|
|
354
|
+
// Trier les colonnes sticky par ordre d'apparition dans le tableau stickyColumns
|
|
355
|
+
const sortedColumns = [...columns].sort((a, b) => {
|
|
356
|
+
const aOrder = calculateStickyOrder(a.field, stickyColumns);
|
|
357
|
+
const bOrder = calculateStickyOrder(b.field, stickyColumns);
|
|
358
|
+
if (aOrder === 0 && bOrder === 0) return 0;
|
|
359
|
+
if (aOrder === 0) return 1;
|
|
360
|
+
if (bOrder === 0) return -1;
|
|
361
|
+
return aOrder - bOrder;
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// Pour chaque colonne, calculer sa position sticky si nécessaire
|
|
365
|
+
return sortedColumns.map(column => {
|
|
366
|
+
// Si la colonne n'est pas figée, retournez-la telle quelle
|
|
367
|
+
if (!stickyColumns.includes(column.field)) {
|
|
368
|
+
return column;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Toutes les colonnes sticky sont alignées à gauche pour plus de clarté
|
|
372
|
+
const headerClassName = "".concat(column.headerClassName || '', " sticky-column sticky-column-left");
|
|
373
|
+
const cellClassName = "".concat(column.cellClassName || '', " sticky-column sticky-column-left");
|
|
374
|
+
|
|
375
|
+
// Définir le style pour positionner la colonne
|
|
376
|
+
const headerStyle = _objectSpread(_objectSpread({}, column.headerStyle || {}), {}, {
|
|
377
|
+
left: "".concat(leftOffset, "px"),
|
|
378
|
+
// Assurer que le fond correspond à celui de la ligne
|
|
379
|
+
backgroundColor: 'inherit',
|
|
380
|
+
// Appliquer un léger effet d'ombre pour indiquer la position sticky
|
|
381
|
+
boxShadow: '2px 0 4px -2px rgba(0, 0, 0, 0.15)'
|
|
382
|
+
});
|
|
383
|
+
const cellStyle = _objectSpread(_objectSpread({}, column.cellStyle || {}), {}, {
|
|
384
|
+
left: "".concat(leftOffset, "px"),
|
|
385
|
+
// Assurer que le fond correspond à celui de la ligne
|
|
386
|
+
backgroundColor: 'inherit',
|
|
387
|
+
// Appliquer un léger effet d'ombre pour indiquer la position sticky
|
|
388
|
+
boxShadow: '2px 0 4px -2px rgba(0, 0, 0, 0.15)'
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// Mettre à jour l'offset pour la prochaine colonne figée
|
|
392
|
+
leftOffset += column.width || 100;
|
|
393
|
+
return _objectSpread(_objectSpread({}, column), {}, {
|
|
394
|
+
headerClassName,
|
|
395
|
+
cellClassName,
|
|
396
|
+
headerStyle,
|
|
397
|
+
cellStyle
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
};
|
|
305
401
|
React.useEffect(() => {
|
|
306
|
-
|
|
402
|
+
// Assurez-vous que les colonnes d'action sont ajoutées après le calcul des positions sticky
|
|
403
|
+
let columnsToProcess = columns;
|
|
404
|
+
|
|
405
|
+
// Appliquer les positions sticky
|
|
406
|
+
const columnsWithSticky = stickyColumns.length > 0 ? calculateStickyPositions(columnsToProcess) : columnsToProcess;
|
|
407
|
+
|
|
408
|
+
// Ajouter la colonne d'actions après avoir calculé les positions sticky
|
|
409
|
+
const finalColumns = Boolean(actions.length) ? [...columnsWithSticky, {
|
|
307
410
|
field: "action",
|
|
308
411
|
headerName: "Actions",
|
|
309
412
|
sortable: false,
|
|
@@ -317,23 +420,18 @@ const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
|
317
420
|
sx: {
|
|
318
421
|
display: 'flex',
|
|
319
422
|
gap: '8px',
|
|
320
|
-
// Adjust the space between icons as needed
|
|
321
423
|
flexWrap: 'wrap',
|
|
322
|
-
// Keep icons on the same line; remove if you want them to wrap
|
|
323
424
|
justifyContent: 'center',
|
|
324
|
-
// Center the icons horizontally
|
|
325
425
|
alignItems: 'center',
|
|
326
|
-
|
|
327
|
-
minWidth: 0 // Prevent the flex container from stretching past its content width
|
|
426
|
+
minWidth: 0
|
|
328
427
|
},
|
|
329
428
|
children: actions.map((action, index) => /*#__PURE__*/React.cloneElement(action, {
|
|
330
429
|
row,
|
|
331
430
|
key: index,
|
|
332
431
|
sx: _objectSpread(_objectSpread({}, action.props.sx), {}, {
|
|
333
432
|
marginRight: 0,
|
|
334
|
-
// Remove any outer margins
|
|
335
433
|
'&:last-child': {
|
|
336
|
-
marginRight: 0
|
|
434
|
+
marginRight: 0
|
|
337
435
|
}
|
|
338
436
|
})
|
|
339
437
|
}))
|
|
@@ -341,8 +439,8 @@ const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
|
341
439
|
},
|
|
342
440
|
cellClassName: "tableAction",
|
|
343
441
|
headerClassName: "tableActionColumn"
|
|
344
|
-
}] :
|
|
345
|
-
setAppColumns(
|
|
442
|
+
}] : columnsWithSticky;
|
|
443
|
+
setAppColumns(finalColumns.map(column => {
|
|
346
444
|
const renderCell = Boolean(column.renderCell) ? column.renderCell : Boolean(column.valueGetter) ? columnData => /*#__PURE__*/(0, _jsxRuntime.jsx)(_PuiTooltip.default, {
|
|
347
445
|
title: Boolean(column.titleGetter) ? column.titleGetter(columnData.row) : String(column.valueGetter(columnData)),
|
|
348
446
|
children: column.valueGetter(columnData)
|
|
@@ -360,7 +458,7 @@ const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
|
360
458
|
});
|
|
361
459
|
}));
|
|
362
460
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
363
|
-
}, [actions, columns]);
|
|
461
|
+
}, [actions, columns, stickyColumns]);
|
|
364
462
|
const renderRowDetailPanel = params => {
|
|
365
463
|
const {
|
|
366
464
|
data
|
|
@@ -372,7 +470,8 @@ const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
|
372
470
|
};
|
|
373
471
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
374
472
|
style: {
|
|
375
|
-
width: '100%'
|
|
473
|
+
width: '100%',
|
|
474
|
+
position: 'relative'
|
|
376
475
|
},
|
|
377
476
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledMuiTable, _objectSpread({
|
|
378
477
|
ref: ref,
|
|
@@ -386,6 +485,35 @@ const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
|
|
|
386
485
|
sx: {
|
|
387
486
|
["& .".concat(_xDataGrid.gridClasses.cell)]: {
|
|
388
487
|
py: 0.5
|
|
488
|
+
},
|
|
489
|
+
// Assurer la cohérence visuelle pour les cellules sticky
|
|
490
|
+
["& .".concat(_xDataGrid.gridClasses.cell, ".sticky-column")]: {
|
|
491
|
+
backgroundColor: 'inherit !important'
|
|
492
|
+
},
|
|
493
|
+
["& .".concat(_xDataGrid.gridClasses.columnHeader, ".sticky-column")]: {
|
|
494
|
+
backgroundColor: 'inherit !important'
|
|
495
|
+
},
|
|
496
|
+
// S'assurer que les titres des colonnes sont visibles
|
|
497
|
+
["& .".concat(_xDataGrid.gridClasses.columnHeaderTitle)]: {
|
|
498
|
+
overflow: 'visible',
|
|
499
|
+
whiteSpace: 'normal'
|
|
500
|
+
},
|
|
501
|
+
// Ajuster les styles pour éviter le défilement horizontal
|
|
502
|
+
'& .MuiDataGrid-main': {
|
|
503
|
+
width: '100%',
|
|
504
|
+
overflow: 'visible'
|
|
505
|
+
},
|
|
506
|
+
'& .MuiDataGrid-virtualScroller': {
|
|
507
|
+
overflow: 'visible'
|
|
508
|
+
},
|
|
509
|
+
'& .MuiDataGrid-virtualScrollerRenderZone': {
|
|
510
|
+
width: '100%'
|
|
511
|
+
},
|
|
512
|
+
'& .MuiDataGrid-virtualScrollerContent': {
|
|
513
|
+
width: '100% !important' // Empêcher le contenu de dépasser la largeur
|
|
514
|
+
},
|
|
515
|
+
'& .MuiDataGrid-row': {
|
|
516
|
+
width: '100% !important'
|
|
389
517
|
}
|
|
390
518
|
},
|
|
391
519
|
autoHeight: true,
|
|
@@ -436,7 +564,8 @@ PuiTable.propTypes = {
|
|
|
436
564
|
onPageChange: _propTypes.default.func,
|
|
437
565
|
onPageSizeChange: _propTypes.default.func,
|
|
438
566
|
onSelectionModelChange: _propTypes.default.func,
|
|
439
|
-
rowDetailPanel: _propTypes.default.element
|
|
567
|
+
rowDetailPanel: _propTypes.default.element,
|
|
568
|
+
stickyColumns: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
440
569
|
};
|
|
441
570
|
PuiTable.defaultProps = {
|
|
442
571
|
oneActionOnly: false,
|
|
@@ -444,6 +573,7 @@ PuiTable.defaultProps = {
|
|
|
444
573
|
pageSize: 5,
|
|
445
574
|
paginationMode: "client",
|
|
446
575
|
stripped: false,
|
|
447
|
-
actions: []
|
|
576
|
+
actions: [],
|
|
577
|
+
stickyColumns: []
|
|
448
578
|
};
|
|
449
579
|
var _default = exports.default = PuiTable;
|